diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 1498e1d..290a2c6 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -20,10 +20,6 @@ jobs: name: 'Composer Validate' run: composer validate --ansi - - - name: 'Rector' - run: composer rector --ansi - - name: 'Coding Standard' run: composer fix-cs --ansi diff --git a/.github/workflows/rector.yaml b/.github/workflows/rector.yaml new file mode 100644 index 0000000..7050916 --- /dev/null +++ b/.github/workflows/rector.yaml @@ -0,0 +1,47 @@ +name: Rector + +on: + pull_request: null + + +jobs: + rector: + # Don't run on forks. + if: github.repository == 'tomasvotruba/unused-public' + + runs-on: ubuntu-latest + + steps: + - + uses: actions/checkout@v3 + with: + # Must be used to trigger workflow after push + token: ${{ secrets.ACCESS_TOKEN }} + + - + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + coverage: none + + - uses: "ramsey/composer-install@v2" + + ## First run Rector - here can't be --dry-run !!! it would stop the job with it and not commit anything in the future + - run: vendor/bin/rector --ansi + + - run: vendor/bin/ecs check --fix --ansi + + # see https://github.com/EndBug/add-and-commit + - + # commit only to core contributors who have repository access + if: github.event.pull_request.head.repo.full_name == github.repository + uses: EndBug/add-and-commit@v7.5.0 + with: + # The arguments for the `git add` command (see the paragraph below for more info) + add: . + message: "[ci-review] Rector Rectify" + author_name: "GitHub Action" + author_email: "action@github.com" + env: + # to get push access + GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} diff --git a/src/Collectors/PublicPropertyCollector.php b/src/Collectors/PublicPropertyCollector.php index 1ec3839..1a64e7d 100644 --- a/src/Collectors/PublicPropertyCollector.php +++ b/src/Collectors/PublicPropertyCollector.php @@ -4,6 +4,7 @@ namespace TomasVotruba\UnusedPublic\Collectors; +use Livewire\Component; use PhpParser\Node; use PhpParser\Node\Stmt\Class_; use PHPStan\Analyser\Scope; @@ -18,6 +19,11 @@ */ final class PublicPropertyCollector implements Collector { + /** + * @var array> + */ + private const CLASSES_TO_SKIP = ['Livewire\Component']; + public function __construct( private readonly ApiDocStmtAnalyzer $apiDocStmtAnalyzer, private readonly Configuration $configuration @@ -47,12 +53,12 @@ public function processNode(Node $node, Scope $scope): ?array return null; } - if ($this->apiDocStmtAnalyzer->isApiDoc($node, $classReflection)) { + $classLike = $node->getOriginalNode(); + if (! $classLike instanceof Class_) { return null; } - $classLike = $node->getOriginalNode(); - if (! $classLike instanceof Class_) { + if ($this->shouldSkipClass($classReflection, $classLike)) { return null; } @@ -73,4 +79,15 @@ public function processNode(Node $node, Scope $scope): ?array return $publicPropertyNames; } + + private function shouldSkipClass(ClassReflection $classReflection, Class_ $class): bool + { + foreach (self::CLASSES_TO_SKIP as $classToSkip) { + if ($classReflection->isSubclassOf($classToSkip)) { + return true; + } + } + + return $this->apiDocStmtAnalyzer->isApiDoc($class, $classReflection); + } } diff --git a/stubs/Livewire/Component.php b/stubs/Livewire/Component.php new file mode 100644 index 0000000..9b22f2e --- /dev/null +++ b/stubs/Livewire/Component.php @@ -0,0 +1,8 @@ +