Skip to content

Commit

Permalink
Use readonly properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 27, 2022
1 parent 6a0202b commit 137f9b8
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 48 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/e2e-tests.yml
Expand Up @@ -33,8 +33,6 @@ jobs:
strategy:
fail-fast: false
matrix:
php-version:
- "8.0"
operating-system: [ubuntu-latest, windows-latest]

steps:
Expand All @@ -45,7 +43,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
php-version: "8.1"
extensions: mbstring
ini-values: memory_limit=256M

Expand Down Expand Up @@ -82,7 +80,7 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "8.0"
php-version: "8.1"
tools: ${{ matrix.tools }}
extensions: ${{ matrix.extensions }}

Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/lint.yml
Expand Up @@ -49,7 +49,7 @@ jobs:
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
Expand All @@ -58,25 +58,25 @@ jobs:

- name: "Rector downgrade cache key"
id: rector-cache-key
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
run: |
echo "::set-output name=sha::$(php build/rector-cache-files-hash.php)"
- name: "Rector downgrade cache"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: actions/cache@v3
with:
path: ./tmp/rectorCache.php
key: "rector-v1-lint-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
key: "rector-v2-lint-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
restore-keys: |
rector-v1-lint-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
rector-v2-lint-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
- name: "Transform source code"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
run: "build/transform-source ${{ matrix.php-version }}"

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/phar.yml
Expand Up @@ -60,9 +60,9 @@ jobs:
uses: actions/cache@v3
with:
path: ./tmp/rectorCache.php
key: "rector-v1-phar-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ steps.rector-cache-key.outputs.sha }}"
key: "rector-v2-phar-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ steps.rector-cache-key.outputs.sha }}"
restore-keys: |
rector-v1-phar-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-
rector-v2-phar-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-
- name: "Prepare for PHAR compilation"
working-directory: "compiler"
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/static-analysis.yml
Expand Up @@ -56,7 +56,7 @@ jobs:
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
Expand All @@ -65,26 +65,26 @@ jobs:

- name: "Rector downgrade cache key"
id: rector-cache-key
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
run: |
echo "::set-output name=sha::$(php build/rector-cache-files-hash.php)"
- name: "Rector downgrade cache"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: actions/cache@v3
with:
path: ./tmp/rectorCache.php
key: "rector-v1-sa-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
key: "rector-v2-sa-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
restore-keys: |
rector-v1-sa-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
rector-v2-sa-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
- name: "Transform source code"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
shell: bash
run: "build/transform-source ${{ matrix.php-version }}"

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/tests.yml
Expand Up @@ -57,7 +57,7 @@ jobs:
run: "composer install --no-interaction --no-progress"

- name: "Install PHP for code transform"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
Expand All @@ -66,26 +66,26 @@ jobs:

- name: "Rector downgrade cache key"
id: rector-cache-key
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
run: |
echo "::set-output name=sha::$(php build/rector-cache-files-hash.php)"
- name: "Rector downgrade cache"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: actions/cache@v3
with:
path: ./tmp/rectorCache.php
key: "rector-v1-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
key: "rector-v2-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
restore-keys: |
rector-v1-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
rector-v2-tests-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
- name: "Transform source code"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
shell: bash
run: "build/transform-source ${{ matrix.php-version }}"

- name: "Reinstall matrix PHP version"
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
Expand Down Expand Up @@ -187,17 +187,17 @@ jobs:

- name: "Rector downgrade cache key"
id: rector-cache-key
if: matrix.php-version != '8.0' && matrix.php-version != '8.1' && matrix.php-version != '8.2'
if: matrix.php-version != '8.1' && matrix.php-version != '8.2'
run: |
echo "::set-output name=sha::$(php build/rector-cache-files-hash.php)"
- name: "Rector downgrade cache"
uses: actions/cache@v3
with:
path: ./tmp/rectorCache.php
key: "rector-v1-tests-old-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
key: "rector-v2-tests-old-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-${{ steps.rector-cache-key.outputs.sha }}"
restore-keys: |
rector-v1-tests-old-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
rector-v2-tests-old-${{ matrix.script }}-${{ matrix.operating-system }}-${{ hashFiles('composer.lock', 'build/rector-downgrade.php') }}-${{ matrix.php-version }}-
- name: "Transform source code"
shell: bash
Expand Down
5 changes: 5 additions & 0 deletions build/rector-downgrade.php
Expand Up @@ -12,6 +12,7 @@
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector;
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDeclarationRector;
use Rector\DowngradePhp80\Rector\Property\DowngradeUnionTypeTypedPropertyRector;
use Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector;

return static function (RectorConfig $config): void {
$parsePhpVersion = static function (string $version, int $defaultPatch = 0): int {
Expand All @@ -27,6 +28,10 @@
$config->phpVersion($targetPhpVersionId);
$config->skip(RectorCache::SKIP_PATHS);

if ($targetPhpVersionId < 80100) {
$config->rule(DowngradeReadonlyPropertyRector::class);
}

if ($targetPhpVersionId < 80000) {
$config->rule(DowngradeTrailingCommasInParamUseRector::class);
$config->rule(DowngradeNonCapturingCatchesRector::class);
Expand Down
36 changes: 18 additions & 18 deletions src/Analyser/NodeScopeResolver.php
Expand Up @@ -188,24 +188,24 @@ class NodeScopeResolver
* @param array<int, string> $earlyTerminatingFunctionCalls
*/
public function __construct(
private ReflectionProvider $reflectionProvider,
private InitializerExprTypeResolver $initializerExprTypeResolver,
private Reflector $reflector,
private ClassReflectionExtensionRegistryProvider $classReflectionExtensionRegistryProvider,
private Parser $parser,
private FileTypeMapper $fileTypeMapper,
private StubPhpDocProvider $stubPhpDocProvider,
private PhpVersion $phpVersion,
private PhpDocInheritanceResolver $phpDocInheritanceResolver,
private FileHelper $fileHelper,
private TypeSpecifier $typeSpecifier,
private DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
private ReadWritePropertiesExtensionProvider $readWritePropertiesExtensionProvider,
private bool $polluteScopeWithLoopInitialAssignments,
private bool $polluteScopeWithAlwaysIterableForeach,
private array $earlyTerminatingMethodCalls,
private array $earlyTerminatingFunctionCalls,
private bool $implicitThrows,
private readonly ReflectionProvider $reflectionProvider,
private readonly InitializerExprTypeResolver $initializerExprTypeResolver,
private readonly Reflector $reflector,
private readonly ClassReflectionExtensionRegistryProvider $classReflectionExtensionRegistryProvider,
private readonly Parser $parser,
private readonly FileTypeMapper $fileTypeMapper,
private readonly StubPhpDocProvider $stubPhpDocProvider,
private readonly PhpVersion $phpVersion,
private readonly PhpDocInheritanceResolver $phpDocInheritanceResolver,
private readonly FileHelper $fileHelper,
private readonly TypeSpecifier $typeSpecifier,
private readonly DynamicThrowTypeExtensionProvider $dynamicThrowTypeExtensionProvider,
private readonly ReadWritePropertiesExtensionProvider $readWritePropertiesExtensionProvider,
private readonly bool $polluteScopeWithLoopInitialAssignments,
private readonly bool $polluteScopeWithAlwaysIterableForeach,
private readonly array $earlyTerminatingMethodCalls,
private readonly array $earlyTerminatingFunctionCalls,
private readonly bool $implicitThrows,
)
{
$earlyTerminatingMethodNames = [];
Expand Down

0 comments on commit 137f9b8

Please sign in to comment.