diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 00000000..1f304953 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,50 @@ +name: PHPStan + +on: + pull_request: + push: + branches: + - main + - develop + - release/** + schedule: + # Run Monday morning at 3 o'clock + # ┌───────────── minute (0 - 59) + # │ ┌───────────── hour (0 - 23) + # │ │ ┌───────────── day of the month (1 - 31) + # │ │ │ ┌───────────── month (1 - 12) + # │ │ │ │ ┌───────────── day of the week (0 - 6) + # │ │ │ │ │ + # │ │ │ │ │ + # │ │ │ │ │ + - cron: 0 3 * * 1 + workflow_dispatch: + +jobs: + phpstan: + runs-on: ubuntu-latest + env: + COMPOSER_NO_INTERACTION: 1 + + steps: + - uses: actions/checkout@v2 + + - uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + coverage: none + + - name: Get composer cache directory + id: composercache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + + - name: Cache dependencies + uses: actions/cache@v2 + with: + path: ${{ steps.composercache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - run: composer update --prefer-dist --no-progress + + - run: composer phpstan -- --no-progress diff --git a/composer.json b/composer.json index 410fa601..20dbf5e2 100644 --- a/composer.json +++ b/composer.json @@ -48,6 +48,7 @@ "illuminate/console": "^6|^7|^8", "illuminate/routing": "^6|^7|^8", "mockery/mockery": "^1.4", + "phpstan/phpstan": "^1", "phpunit/phpunit": "^8.5|^9.4", "rector/rector": "^0.12.4", "vlucas/phpdotenv": "^5.2.0", @@ -86,6 +87,8 @@ "scripts": { "php-cs-fixer": "php-cs-fixer fix --diff", "test": "phpunit --colors=always", - "test:ci": "composer test -- --verbose --coverage-text --coverage-clover=coverage.xml" + "test:ci": "composer test -- --verbose --coverage-text --coverage-clover=coverage.xml", + "phpstan": "phpstan analyse --memory-limit=256M", + "phpstan-baseline": "phpstan analyse --generate-baseline --memory-limit=256M" } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 00000000..54c5a5f4 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,62 @@ +parameters: + ignoreErrors: + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/Claims/Collection.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\Expiration\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: src/Claims/Expiration.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\IssuedAt\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: src/Claims/IssuedAt.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\IssuedAt\\:\\:validateRefresh\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: src/Claims/IssuedAt.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Claims\\\\NotBefore\\:\\:validatePayload\\(\\) should return bool but return statement is missing\\.$#" + count: 1 + path: src/Claims/NotBefore.php + + - + message: "#^Result of method PHPOpenSourceSaver\\\\JWTAuth\\\\Console\\\\JWTGenerateSecretCommand\\:\\:displayKey\\(\\) \\(void\\) is used\\.$#" + count: 1 + path: src/Console/JWTGenerateSecretCommand.php + + - + message: "#^Function config not found\\.$#" + count: 1 + path: src/Providers/AbstractServiceProvider.php + + - + message: "#^Function config_path not found\\.$#" + count: 1 + path: src/Providers/LaravelServiceProvider.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Test\\\\Stubs\\\\LaravelUserStub\\:\\:getAuthIdentifierName\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: tests/Stubs/LaravelUserStub.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Test\\\\Stubs\\\\LaravelUserStub\\:\\:getAuthPassword\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: tests/Stubs/LaravelUserStub.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Test\\\\Stubs\\\\LaravelUserStub\\:\\:getRememberToken\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: tests/Stubs/LaravelUserStub.php + + - + message: "#^Method PHPOpenSourceSaver\\\\JWTAuth\\\\Test\\\\Stubs\\\\LaravelUserStub\\:\\:getRememberTokenName\\(\\) should return string but return statement is missing\\.$#" + count: 1 + path: tests/Stubs/LaravelUserStub.php + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 00000000..84da7eb3 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,7 @@ +includes: + - ./phpstan-baseline.neon +parameters: + level: 1 + paths: + - src/ + - tests/ diff --git a/src/Payload.php b/src/Payload.php index 9b8a0bac..2cb447c3 100644 --- a/src/Payload.php +++ b/src/Payload.php @@ -202,6 +202,7 @@ public function __toString() * * @return bool */ + #[\ReturnTypeWillChange] public function offsetExists($key) { return Arr::has($this->toArray(), $key); @@ -227,6 +228,7 @@ public function offsetGet($key) * * @throws PayloadException */ + #[\ReturnTypeWillChange] public function offsetSet($key, $value) { throw new PayloadException('The payload is immutable'); @@ -241,6 +243,7 @@ public function offsetSet($key, $value) * @throws PayloadException * */ + #[\ReturnTypeWillChange] public function offsetUnset($key) { throw new PayloadException('The payload is immutable'); @@ -251,6 +254,7 @@ public function offsetUnset($key) * * @return int */ + #[\ReturnTypeWillChange] public function count() { return count($this->toArray());