Skip to content
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

feat: PHPStan Request Factories - Upgrade to PHPStan 2.x #5

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
php-version: '8.3'
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3

- name: Run PHPStan
run: composer test:types
27 changes: 8 additions & 19 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,12 @@ on:

jobs:
test:
runs-on: ${{ matrix.os }}
name: PHPStan
runs-on: ubuntu-latest
env:
PREVENT_OUTPUT: true
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.2, 8.3]
laravel: [10.*, 11.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*

name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
fail-fast: false

steps:
- name: Checkout code
Expand All @@ -33,18 +22,18 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: 8.3
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update --ansi
composer update --${{ matrix.stability }} --prefer-dist --no-interaction --ansi
- name: Install composer dependencies
uses: ramsey/composer-install@v3

- name: Execute tests
run: composer test:unit
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
"php": "^8.2",
"illuminate/contracts": "^10.0 || ^11.0",
"illuminate/http": "^10.0 || ^11.0",
"phpstan/phpstan": "^1.10.57",
"phpstan/phpstan": "^2.0",
"worksome/request-factories": "^3.2"
},
"require-dev": {
"larastan/larastan": "^3.0",
"nunomaduro/collision": "^7.10 || ^8.1",
"larastan/larastan": "^2.6",
"orchestra/testbench": "^8.5.8 || ^9.0",
"pestphp/pest": "^2.33",
"worksome/coding-style": "^2.8"
"worksome/coding-style": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
ignoreErrors:
-
message: '#^Function class_parents\(\) is a runtime reflection concept that might not work in PHPStan because it uses fully static reflection engine\. Use objects retrieved from ReflectionProvider instead\.$#'
identifier: phpstanApi.runtimeReflection
count: 2
path: src/RequireRequestFactoryRule.php
9 changes: 7 additions & 2 deletions src/RequireRequestFactoryRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public function getNodeType(): string

/**
* @param Class_ $node
*/
*
* @return array<int, \PHPStan\Rules\RuleError>
*/
public function processNode(Node $node, Scope $scope): array
{
if ($node->namespacedName === null) {
Expand All @@ -57,6 +59,7 @@ public function processNode(Node $node, Scope $scope): array
return $this->checkForCorrespondingFactory($className);
}

/** @return array<int, \PHPStan\Rules\RuleError> */
public function checkForCorrespondingFactory(string $className): array
{
$subName = Str::after($className, "{$this->requestsNamespace}\\");
Expand All @@ -69,7 +72,9 @@ public function checkForCorrespondingFactory(string $className): array
return [
RuleErrorBuilder::message(
"Request \"{$className}\" does not have a corresponding Request Factory at \"{$factoryName}\"."
)->build()
)
->identifier('worksome.missingRequestFactory')
->build(),
];
}
}
Loading