Skip to content

Commit 487b1dd

Browse files
committed
fix: Scope string literals used in expressions
Closes humbug#557.
1 parent c1e866e commit 487b1dd

File tree

7 files changed

+957
-429
lines changed

7 files changed

+957
-429
lines changed

specs/misc/composer.php

Lines changed: 894 additions & 0 deletions
Large diffs are not rendered by default.

specs/string-literal/expr.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the humbug/php-scoper package.
7+
*
8+
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
9+
* Pádraic Brady <padraic.brady@gmail.com>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
use Humbug\PhpScoper\SpecFramework\Config\Meta;
16+
17+
return [
18+
'meta' => new Meta(
19+
title: 'Scalar literal used in an expression',
20+
),
21+
22+
'String value used in a comparison expression' => <<<'PHP'
23+
<?php
24+
25+
namespace Composer\Package\Loader;
26+
27+
if ($class !== 'Composer\Package\CompletePackage' && $class !== 'Composer\Package\RootPackage') {
28+
trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', E_USER_DEPRECATED);
29+
}
30+
31+
----
32+
<?php
33+
34+
namespace Humbug\Composer\Package\Loader;
35+
36+
if ($class !== 'Humbug\Composer\Package\CompletePackage' && $class !== 'Humbug\Composer\Package\RootPackage') {
37+
trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', \E_USER_DEPRECATED);
38+
}
39+
40+
PHP,
41+
42+
'Non valid class name string value used in a comparison expression' => <<<'PHP'
43+
<?php
44+
45+
namespace Composer\Package\Loader;
46+
47+
if ($class !== '1Composer\Package\CompletePackage' && $class !== '0Composer\Package\RootPackage') {
48+
trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', E_USER_DEPRECATED);
49+
}
50+
51+
----
52+
<?php
53+
54+
namespace Humbug\Composer\Package\Loader;
55+
56+
if ($class !== '1Composer\Package\CompletePackage' && $class !== '0Composer\Package\RootPackage') {
57+
trigger_error('The $class arg is deprecated, please reach out to Composer maintainers ASAP if you still need this.', \E_USER_DEPRECATED);
58+
}
59+
60+
PHP,
61+
];

src/Configuration/ConfigurationFactory.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
namespace Humbug\PhpScoper\Configuration;
1616

17-
use Humbug\PhpScoper\Patcher\ComposerPatcher;
1817
use Humbug\PhpScoper\Patcher\Patcher;
1918
use Humbug\PhpScoper\Patcher\PatcherChain;
2019
use Humbug\PhpScoper\Patcher\SymfonyParentTraitPatcher;
@@ -89,7 +88,6 @@ public function create(?string $path = null, array $paths = []): Configuration
8988

9089
array_unshift($patchers, new SymfonyPatcher());
9190
array_unshift($patchers, new SymfonyParentTraitPatcher());
92-
array_unshift($patchers, new ComposerPatcher());
9391

9492
$symbolsConfiguration = $this->symbolsConfigurationFactory->createSymbolsConfiguration($config);
9593

src/Patcher/ComposerPatcher.php

Lines changed: 0 additions & 66 deletions
This file was deleted.

src/PhpParser/NodeVisitor/StringScalarPrefixer.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use PhpParser\Node\Arg;
2222
use PhpParser\Node\ArrayItem;
2323
use PhpParser\Node\Const_;
24+
use PhpParser\Node\Expr;
2425
use PhpParser\Node\Expr\Array_;
2526
use PhpParser\Node\Expr\Assign;
2627
use PhpParser\Node\Expr\FuncCall;
@@ -174,6 +175,7 @@ private function prefixStringScalar(String_ $string): String_
174175
$parentNode instanceof Assign
175176
|| $parentNode instanceof Param
176177
|| $parentNode instanceof Const_
178+
|| $parentNode instanceof Expr
177179
|| $parentNode instanceof PropertyProperty
178180
|| $parentNode instanceof Return_
179181
)) {

tests/Configuration/ConfigurationFactoryTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
use Fidry\FileSystem\FS;
1818
use Humbug\PhpScoper\Container;
1919
use Humbug\PhpScoper\FileSystemTestCase;
20-
use Humbug\PhpScoper\Patcher\ComposerPatcher;
2120
use Humbug\PhpScoper\Patcher\PatcherChain;
2221
use Humbug\PhpScoper\Patcher\SymfonyParentTraitPatcher;
2322
use Humbug\PhpScoper\Patcher\SymfonyPatcher;
@@ -60,7 +59,6 @@ public function test_it_can_be_created_without_a_file(): void
6059
self::assertSame([], $configuration->getFilesWithContents());
6160
self::assertEquals(
6261
new PatcherChain([
63-
new ComposerPatcher(),
6462
new SymfonyParentTraitPatcher(),
6563
new SymfonyPatcher(),
6664
]),
@@ -141,7 +139,6 @@ public function test_it_can_create_a_complete_configuration(): void
141139
);
142140
self::assertEquals(
143141
new PatcherChain([
144-
new ComposerPatcher(),
145142
new SymfonyParentTraitPatcher(),
146143
new SymfonyPatcher(),
147144
]),

0 commit comments

Comments
 (0)