-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0082465
commit f29cec7
Showing
1,351 changed files
with
1,749 additions
and
44,542 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,9 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
indent_style = space | ||
indent_size = 4 |
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
/.github export-ignore | ||
/tests export-ignore | ||
.gitattributes export-ignore | ||
.gitignore export-ignore | ||
.travis.yml export- | ||
phpunit.xml export-ignore | ||
*.md export-ignore | ||
/packages-tests export-ignore |
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
name: Bare Run on various PHP versions | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
bare_run: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php_version: ['7.2', '7.4', '8.0', '8.2'] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php_version }} | ||
coverage: none | ||
|
||
- run: mkdir nested-dir | ||
|
||
- run: composer require symplify/phpstan-rules --dev --ansi | ||
working-directory: nested-dir |
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,53 @@ | ||
name: Code Analysis | ||
|
||
on: | ||
pull_request: null | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
code_analysis: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
actions: | ||
- | ||
name: 'PHPStan' | ||
run: composer phpstan --ansi | ||
|
||
- | ||
name: 'Composer Validate' | ||
run: composer validate --ansi | ||
|
||
- | ||
name: 'Rector' | ||
run: composer rector --ansi | ||
|
||
- | ||
name: 'Coding Standard' | ||
run: composer fix-cs --ansi | ||
|
||
- | ||
name: 'Tests' | ||
run: vendor/bin/phpunit | ||
|
||
- | ||
name: 'Check Active Classes' | ||
run: vendor/bin/class-leak check src --ansi | ||
|
||
name: ${{ matrix.actions.name }} | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
# see https://github.com/shivammathur/setup-php | ||
- uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.1 | ||
coverage: none | ||
|
||
# composer install cache - https://github.com/ramsey/composer-install | ||
- uses: "ramsey/composer-install@v2" | ||
|
||
- run: ${{ matrix.actions.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
name: Downgraded Release | ||
|
||
on: | ||
push: | ||
tags: | ||
# avoid infinite looping, skip tags that ends with ".72" | ||
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-and-excluding-branches | ||
- '*' | ||
- '!**.72' | ||
|
||
jobs: | ||
downgrade_release: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: "actions/checkout@v3" | ||
with: | ||
token: ${{ secrets.WORKFLOWS_TOKEN }} | ||
|
||
- | ||
uses: "shivammathur/setup-php@v2" | ||
with: | ||
php-version: 8.1 | ||
coverage: none | ||
|
||
# invoke patches | ||
- run: composer install --ansi | ||
|
||
# but no dev packages | ||
- run: composer update --no-dev --ansi | ||
|
||
# get rector to "rector-local" directory, to avoid downgrading itself in the /vendor | ||
- run: mkdir rector-local | ||
- run: composer require rector/rector:^0.17.1 --working-dir rector-local --ansi | ||
|
||
# downgrade to PHP 7.2 | ||
- run: rector-local/vendor/bin/rector process src config --config build/rector-downgrade-php-72.php --ansi | ||
|
||
# clear the dev files | ||
- run: rm -rf tests rector-local ecs.php phpstan.neon phpunit.xml .editorconfig | ||
|
||
# copy PHP 7.2 composer + workflows | ||
- run: cp -r build/target-repository/. . | ||
|
||
# clear the dev files | ||
- run: rm -rf build monorepo-builder.php full-tool-build.sh rector.php phpstan-for-tests.neon tests | ||
|
||
# setup git user | ||
- | ||
run: | | ||
git config user.email "[email protected]" | ||
git config user.name "GitHub Action" | ||
# publish to the same repository with a new tag | ||
# see https://tomasvotruba.com/blog/how-to-release-php-81-and-72-package-in-the-same-repository/ | ||
- | ||
name: "Tag Downgraded Code" | ||
run: | | ||
# separate a "git add" to add untracked (new) files too | ||
git add --all | ||
git commit -m "release PHP 7.2 downgraded" | ||
# force push tag, so there is only 1 version | ||
git tag "${GITHUB_REF#refs/tags/}" --force | ||
git push origin "${GITHUB_REF#refs/tags/}" --force |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
/vendor | ||
composer.lock | ||
|
||
.phpunit.cache |
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 |
---|---|---|
@@ -1,113 +1,28 @@ | ||
# PHPStan Rules | ||
# Type Perfect | ||
|
||
[![Downloads](https://img.shields.io/packagist/dt/symplify/phpstan-rules.svg?style=flat-square)](https://packagist.org/packages/symplify/phpstan-rules/stats) | ||
[![Downloads](https://img.shields.io/packagist/dt/tomasvotruba/type-perfect.svg?style=flat-square)](https://packagist.org/packages/tomasvotruba/type-perfect/stats) | ||
|
||
Set of rules for PHPStan used by Symplify projects | ||
|
||
- See [Rules Overview](docs/rules_overview.md) | ||
|
||
<br> | ||
|
||
## Install | ||
|
||
```bash | ||
composer require symplify/phpstan-rules --dev | ||
composer requiretomasvotruba/type-perfect --dev | ||
``` | ||
|
||
## 1. Add Static Rules to `phpstan.neon` | ||
|
||
Some of rules here require configuration, some not. We recommend to start with rules that do not require any configuration, because there is just one way to use them: | ||
|
||
```yaml | ||
# phpstan.neon | ||
includes: | ||
- vendor/symplify/phpstan-rules/config/static-rules.neon | ||
``` | ||
Give it couple of days, before extending. | ||
*Note: Make sure you use [`phpstan/extension-installer`](https://github.com/phpstan/extension-installer#usage) to load necessary service configs.* | ||
|
||
<br> | ||
|
||
Some rules require extra services. To avoid service duplications, they're in the separate config that you can easily include: | ||
```yaml | ||
includes: | ||
- vendor/symplify/phpstan-rules/config/services/services.neon | ||
``` | ||
*Note:* [Rules in subpackages](https://github.com/symplify/symplify/tree/main/packages/phpstan-rules/packages) contain additional service definitions which need to be included, in case you configure these rules: | ||
```yaml | ||
includes: | ||
- vendor/symplify/phpstan-rules/config/packages/cognitive-complexity/cognitive-complexity-services.neon | ||
|
||
services: | ||
|
||
- | ||
class: Symplify\PHPStanRules\CognitiveComplexity\Rules\ClassLikeCognitiveComplexityRule | ||
tags: [phpstan.rules.rule] | ||
arguments: | ||
maxClassCognitiveComplexity: 10 | ||
|
||
``` | ||
|
||
## 2. Pick from Prepared Sets | ||
|
||
Do you know prepared sets from ECS or Rector? Bunch of rules in single set. We use the same approach here: | ||
|
||
```yaml | ||
includes: | ||
- vendor/symplify/phpstan-rules/config/array-rules.neon | ||
- vendor/symplify/phpstan-rules/config/code-complexity-rules.neon | ||
- vendor/symplify/phpstan-rules/config/doctrine-rules.neon | ||
- vendor/symplify/phpstan-rules/config/naming-rules.neon | ||
- vendor/symplify/phpstan-rules/config/regex-rules.neon | ||
- vendor/symplify/phpstan-rules/config/forbidden-static-rules.neon | ||
- vendor/symplify/phpstan-rules/config/test-rules.neon | ||
``` | ||
@todo enable by configuration | ||
one at a time :) levels? | ||
|
||
Pick what you need, drop the rest. | ||
## 3. How we use Configurable Rules | ||
Last but not least, configurable rules with *saints defaults*. That's just polite wording for *opinionated*, like [`AllowedExclusiveDependencyRule`](https://github.com/symplify/phpstan-rules/blob/main/docs/rules_overview.md#allowedexclusivedependencyrule). | ||
|
||
You might not like them, but maybe you do: | ||
|
||
```yaml | ||
# phpstan.neon | ||
includes: | ||
- vendor/symplify/phpstan-rules/config/configurable-rules.neon | ||
``` | ||
|
||
Give it a trial run... so many erros and unclear feedback.... Would you like to **configure them yourself?** | ||
That's good! We use one rule by another in other projects too, instead of one big import. | ||
|
||
- **Pick one and put it to your `phpstan.neon` manually**. | ||
- Configure it to your specific needs and re-run PHPStan. It's easier to be responsible, when you're in control. | ||
|
||
E.g. `ForbiddenNodeRule`: | ||
|
||
```yaml | ||
services: | ||
- | ||
class: Symplify\PHPStanRules\Rules\ForbiddenNodeRule | ||
tags: [phpstan.rules.rule] | ||
arguments: | ||
forbiddenNodes: | ||
- PhpParser\Node\Expr\Empty_ | ||
- PhpParser\Node\Stmt\Switch_ | ||
- PhpParser\Node\Expr\ErrorSuppress | ||
``` | ||
|
||
You'll find them all in [rules overview](docs/rules_overview.md). | ||
|
||
Happy coding! | ||
Add sets one by one, fix what you find useful and ignore the rest. | ||
|
||
<br> | ||
|
||
## Report Issues | ||
|
||
In case you are experiencing a bug or want to request a new feature head over to the [Symplify monorepo issue tracker](https://github.com/symplify/symplify/issues) | ||
|
||
## Contribute | ||
|
||
The sources of this package are contained in the Symplify monorepo. We welcome contributions for this package on [symplify/symplify](https://github.com/symplify/symplify). | ||
Happy coding! |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Removing\Rector\Class_\RemoveInterfacesRector; | ||
use Rector\Set\ValueObject\DowngradeLevelSetList; | ||
use Symplify\RuleDocGenerator\Contract\ConfigurableRuleInterface; | ||
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->parallel(); | ||
|
||
$rectorConfig->sets([DowngradeLevelSetList::DOWN_TO_PHP_72]); | ||
|
||
$rectorConfig->ruleWithConfiguration(RemoveInterfacesRector::class, [ | ||
DocumentedRuleInterface::class, | ||
ConfigurableRuleInterface::class, | ||
]); | ||
|
||
$rectorConfig->skip(['*/Tests/*', '*/tests/*', __DIR__ . '/../../tests']); | ||
}; | ||
|
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,3 @@ | ||
# These are supported funding model platforms | ||
github: tomasvotruba | ||
custom: https://www.paypal.me/rectorphp |
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
Oops, something went wrong.