-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add configs for strict PHP checks #56522
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
provokateurin
wants to merge
2
commits into
master
Choose a base branch
from
feat/strict-php-checks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,45 @@ | ||
| # SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-or-later | ||
| name: Rector | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: rector-${{ github.head_ref || github.run_id }} | ||
| cancel-in-progress: true | ||
|
|
||
| jobs: | ||
| strict: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| if: ${{ github.event_name != 'push' && github.repository_owner != 'nextcloud-gmbh' }} | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 | ||
| with: | ||
| persist-credentials: false | ||
| submodules: true | ||
|
|
||
| - name: Set up php | ||
| uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 #v2.35.4 | ||
| with: | ||
| php-version: '8.2' | ||
| extensions: apcu,ctype,curl,dom,fileinfo,ftp,gd,imagick,intl,json,ldap,mbstring,openssl,pdo_sqlite,posix,sqlite,xml,zip | ||
| coverage: none | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Composer install | ||
| run: composer i | ||
|
|
||
| - name: Rector | ||
| run: composer run rector:strict | ||
|
|
||
| - name: Show changes | ||
| if: always() | ||
| run: git diff --exit-code -- . ':!lib/composer' |
This file contains hidden or 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 hidden or 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 hidden or 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,92 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| */ | ||
|
|
||
| use Nextcloud\Rector\Set\NextcloudSets; | ||
| use PhpParser\Node; | ||
| use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface; | ||
| use Rector\Config\RectorConfig; | ||
| use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; | ||
| use Rector\PHPUnit\Set\PHPUnitSetList; | ||
| use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType; | ||
| use Rector\ValueObject\Application\File; | ||
|
|
||
| $nextcloudDir = dirname(__DIR__); | ||
|
|
||
| class NextcloudNamespaceSkipVoter implements ClassNameImportSkipVoterInterface { | ||
| private array $namespacePrefixes = [ | ||
| 'OC', | ||
| 'OCA', | ||
| 'OCP', | ||
| ]; | ||
| private array $skippedClassNames = [ | ||
| 'Backend', | ||
| 'Connection', | ||
| 'Exception', | ||
| 'IManager', | ||
| 'IProvider', | ||
| 'Manager', | ||
| 'Plugin', | ||
| 'Provider', | ||
| ]; | ||
| public function shouldSkip(File $file, FullyQualifiedObjectType $fullyQualifiedObjectType, Node $node) : bool { | ||
| if (in_array($fullyQualifiedObjectType->getShortName(), $this->skippedClassNames)) { | ||
| // Skip common class names to avoid confusion | ||
| return true; | ||
| } | ||
| foreach ($this->namespacePrefixes as $prefix) { | ||
| if (str_starts_with($fullyQualifiedObjectType->getClassName(), $prefix . '\\')) { | ||
| // Import Nextcloud namespaces | ||
| return false; | ||
| } | ||
| } | ||
| // Skip everything else | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| $config = RectorConfig::configure() | ||
| ->withSkip([ | ||
| $nextcloudDir . '/apps/*/3rdparty/*', | ||
| $nextcloudDir . '/apps/*/build/stubs/*', | ||
| $nextcloudDir . '/apps/*/composer/*', | ||
| $nextcloudDir . '/apps/*/config/*', | ||
| // The mock classes are excluded, as the tests explicitly test the annotations which should not be migrated to attributes | ||
| $nextcloudDir . '/tests/lib/AppFramework/Middleware/Mock/*', | ||
| $nextcloudDir . '/tests/lib/AppFramework/Middleware/Security/Mock/*', | ||
| ]) | ||
| // uncomment to reach your current PHP version | ||
| // ->withPhpSets() | ||
| ->withImportNames(importShortClasses:false) | ||
| ->withConfiguredRule(ClassPropertyAssignToConstructorPromotionRector::class, [ | ||
| 'inline_public' => true, | ||
| 'rename_property' => true, | ||
| ]) | ||
| ->withSets([ | ||
| NextcloudSets::NEXTCLOUD_27, | ||
| PHPUnitSetList::PHPUNIT_100, | ||
| ]); | ||
|
|
||
| $config->registerService(NextcloudNamespaceSkipVoter::class, tag:ClassNameImportSkipVoterInterface::class); | ||
|
|
||
| /* Ignore all files ignored by git */ | ||
| $ignoredEntries = shell_exec('git status --porcelain --ignored ' . escapeshellarg($nextcloudDir)); | ||
| $ignoredEntries = explode("\n", $ignoredEntries); | ||
| $ignoredEntries = array_filter($ignoredEntries, static fn (string $line) => str_starts_with($line, '!! ')); | ||
| $ignoredEntries = array_map(static fn (string $line) => substr($line, 3), $ignoredEntries); | ||
| $ignoredEntries = array_values($ignoredEntries); | ||
|
|
||
| foreach ($ignoredEntries as $ignoredEntry) { | ||
| if (str_ends_with($ignoredEntry, '/')) { | ||
| $config->withSkip([$ignoredEntry . '*']); | ||
| } else { | ||
| $config->withSkip([$ignoredEntry . '/*']); | ||
| } | ||
| } | ||
|
|
||
| return $config; |
This file contains hidden or 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,30 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
|
|
||
| $nextcloudDir = dirname(__DIR__); | ||
|
|
||
| return (require __DIR__ . '/rector-shared.php') | ||
| ->withPaths([ | ||
| $nextcloudDir . '/build/rector-strict.php', | ||
| ]) | ||
| ->withPreparedSets( | ||
| deadCode: true, | ||
| codeQuality: true, | ||
| codingStyle: true, | ||
| typeDeclarations: true, | ||
| typeDeclarationDocblocks: true, | ||
| privatization: true, | ||
| instanceOf: true, | ||
| earlyReturn: true, | ||
| rectorPreset: true, | ||
| phpunitCodeQuality: true, | ||
| doctrineCodeQuality: true, | ||
| symfonyCodeQuality: true, | ||
| symfonyConfigs: true, | ||
| )->withPhpSets( | ||
| php82: true, | ||
| ); | ||
This file contains hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| <?xml version="1.0"?> | ||
| <!-- | ||
| - SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| - SPDX-License-Identifier: AGPL-3.0-or-later | ||
| --> | ||
| <psalm | ||
| errorLevel="1" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xmlns="https://getpsalm.org/schema/config" | ||
| xsi:schemaLocation="https://getpsalm.org/schema/config" | ||
| resolveFromConfigFile="false" | ||
| findUnusedBaselineEntry="true" | ||
| findUnusedCode="false" | ||
| findUnusedPsalmSuppress="true" | ||
| findUnusedVariablesAndParams="true" | ||
| phpVersion="8.2" | ||
| > | ||
| <projectFiles> | ||
| <ignoreFiles> | ||
| <directory name="apps/**/composer"/> | ||
| <directory name="apps/**/tests"/> | ||
| <directory name="lib/composer"/> | ||
| <directory name="lib/l10n"/> | ||
| <directory name="3rdparty"/> | ||
| </ignoreFiles> | ||
| </projectFiles> | ||
| <extraFiles> | ||
| <directory name="3rdparty"/> | ||
| </extraFiles> | ||
| </psalm> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m uneasy about using rector for code style like this because it has no ignore mechanism so we’re screwed on any false-positive, no?
Also, this PR adds rector-strict.php but only runs it on itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because rector will complain if you run it without any files, so it's just meant as a placeholder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Can you explain that in a comment? 😆