-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PHPStan parser for different PHP version parsing (#1791)
- Loading branch information
1 parent
dbadefc
commit bc0eac3
Showing
17 changed files
with
257 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# This workflow runs system tests: Use the Rector application from the source | ||
# checkout to process "fixture" projects in e2e/ directory | ||
# to see if those can be processed successfully | ||
name: End to End tests on PHP 7.4 | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: | ||
- main | ||
|
||
env: | ||
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361 | ||
COMPOSER_ROOT_VERSION: "dev-main" | ||
|
||
jobs: | ||
end_to_end: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
directory: | ||
- 'e2e/php74-parse-static' | ||
|
||
name: End to end test - ${{ matrix.directory }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 7.4 | ||
coverage: none | ||
|
||
# run in e2e subdir | ||
- | ||
run: composer install --ansi | ||
working-directory: ${{ matrix.directory }} | ||
|
||
# run e2e test - there should be no reports | ||
- run: vendor/bin/rector --ansi --dry-run | ||
working-directory: ${{ matrix.directory }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# ref https://github.com/rectorphp/rector/issues/6970 | ||
name: Downgrade PHPStan Parser | ||
|
||
on: | ||
pull_request: null | ||
|
||
env: | ||
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361 | ||
COMPOSER_ROOT_VERSION: "dev-main" | ||
|
||
jobs: | ||
downgrade_phpstan_parser: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
# see https://github.com/shivammathur/setup-php | ||
- | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: none | ||
|
||
- uses: "ramsey/composer-install@v1" | ||
|
||
- run: bin/rector p vendor/clue/ndjson-react/src/Decoder.php --config tests/config/downgrade-phpstan-parser.php --dry-run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"require": { | ||
"php": "7.4.*", | ||
"api-platform/core": "^2.6", | ||
"symfony/framework-bundle": "^5.4", | ||
"symfony/http-client": "^5.4" | ||
}, | ||
"require-dev": { | ||
"rector/rector": "dev-main" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
use Rector\Core\Configuration\Option; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$parameters = $containerConfigurator->parameters(); | ||
|
||
$parameters->set(Option::PARALLEL, true); | ||
$parameters->set(Option::PATHS, [ | ||
__DIR__ . '/tests', | ||
]); | ||
|
||
$services = $containerConfigurator->services(); | ||
$services->set(DowngradeJsonDecodeNullAssociativeArgRector::class); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; | ||
use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\Client; | ||
|
||
class ApiTest extends ApiTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
static::createClient(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...2/Rector/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector/Fixture/array_assoc.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector\Fixture; | ||
|
||
final class ArrayAssoc | ||
{ | ||
public function run($data, array $items) | ||
{ | ||
$data = \json_decode($data, $items[0]); | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector\Fixture; | ||
|
||
final class ArrayAssoc | ||
{ | ||
public function run($data, array $items) | ||
{ | ||
$data = \json_decode($data, $items[0] === null ?: $items[0]); | ||
} | ||
} | ||
|
||
?> |
49 changes: 49 additions & 0 deletions
49
...tor/FuncCall/DowngradeJsonDecodeNullAssociativeArgRector/Fixture/clue_json_decode.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector\Fixture; | ||
|
||
/** | ||
* @see \Clue\React\NDJson\Decoder | ||
*/ | ||
final class ClueJsonDecode | ||
{ | ||
private $assoc; | ||
private $depth; | ||
private $options; | ||
|
||
public function run($data) | ||
{ | ||
if ($this->options === 0) { | ||
$data = \json_decode($data, $this->assoc, $this->depth); | ||
} else { | ||
$data = \json_decode($data, $this->assoc, $this->depth, $this->options); | ||
} | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector\Fixture; | ||
|
||
/** | ||
* @see \Clue\React\NDJson\Decoder | ||
*/ | ||
final class ClueJsonDecode | ||
{ | ||
private $assoc; | ||
private $depth; | ||
private $options; | ||
|
||
public function run($data) | ||
{ | ||
if ($this->options === 0) { | ||
$data = \json_decode($data, $this->assoc === null ?: $this->assoc, $this->depth); | ||
} else { | ||
$data = \json_decode($data, $this->assoc === null ?: $this->assoc, $this->depth, $this->options); | ||
} | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...cCall/DowngradeJsonDecodeNullAssociativeArgRector/Fixture/skip_already_downgraded.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector\Fixture; | ||
|
||
final class SkipAlreadyDowngraded | ||
{ | ||
public function run(string $json, $associative) | ||
{ | ||
$value = json_decode($json, $associative === null ?: $associative); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ecodeNullAssociativeArgRector/Fixture/skip_clue_json_decode_filled_in_constructor.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DowngradePhp72\Rector\FuncCall\DowngradeJsonDecodeNullAssociativeArgRector\Fixture; | ||
|
||
final class SkipClueJsonDecodeFilledInConstructor | ||
{ | ||
private $assoc; | ||
private $depth; | ||
|
||
/** | ||
* @param bool $assoc | ||
*/ | ||
public function __construct($assoc = false) | ||
{ | ||
$this->assoc = $assoc; | ||
} | ||
|
||
public function run($data) | ||
{ | ||
$data = \json_decode($data, $this->assoc, $this->depth); | ||
} | ||
} |
Oops, something went wrong.