Skip to content

Commit

Permalink
New commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user authored and TomasVotruba committed May 26, 2024
1 parent 0082465 commit f29cec7
Show file tree
Hide file tree
Showing 1,351 changed files with 1,749 additions and 44,542 deletions.
9 changes: 9 additions & 0 deletions .editorconfig
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
2 changes: 1 addition & 1 deletion .gitattributes
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
23 changes: 0 additions & 23 deletions .github/workflows/auto_closer.yaml

This file was deleted.

29 changes: 29 additions & 0 deletions .github/workflows/bare_run.yaml
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
53 changes: 53 additions & 0 deletions .github/workflows/code_analysis.yaml
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 }}
64 changes: 64 additions & 0 deletions .github/workflows/downgraded_release.yaml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/vendor
composer.lock

.phpunit.cache
105 changes: 10 additions & 95 deletions README.md
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!
23 changes: 23 additions & 0 deletions build/rector-downgrade-php-72.php
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']);
};

3 changes: 3 additions & 0 deletions build/target-repository/.github/FUNDING.yml
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Tests
name: Standalone Install

on: [pull_request, push]

jobs:
tests:
standalone_install:
runs-on: ubuntu-latest

strategy:
Expand All @@ -17,15 +17,6 @@ jobs:
- run: composer config --no-plugins allow-plugins.phpstan/extension-installer true

- run: composer require phpstan/phpstan phpstan/extension-installer --dev

# get current dev-main version
- run: composer require symplify/phpstan-rules:@dev --dev

# prepare local files
- run: wget https://raw.githubusercontent.com/symplify/phpstan-rules/main/phpstan-for-tests.neon
- run: wget https://raw.githubusercontent.com/symplify/phpstan-rules/main/tests/SomeClass.php.inc

- run: vendor/bin/phpstan analyze SomeClass.php.inc --configuration phpstan-for-tests.neon

- run: composer require tomasvotruba/type-perfect:dev-main --dev


Loading

0 comments on commit f29cec7

Please sign in to comment.