diff --git a/.gitattributes b/.gitattributes index 634b37f..3a4a594 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,6 +2,7 @@ /.github export-ignore /.gitignore export-ignore /tests export-ignore +/phpstan* export-ignore /phpunit.xml export-ignore /composer.lock export-ignore /.scrutinizer.yml export-ignore diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..b2a0b23 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,31 @@ +name: PHPStan + +on: + pull_request: + paths: + - '**.php' + - 'phpstan.neon.dist' + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.4 + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v2 + + - name: Install larastan + run: | + composer require "larastan/larastan" --no-interaction --no-update + composer update --prefer-dist --no-interaction + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/.gitignore b/.gitignore index 3f1dbe8..e5860df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /vendor/ *.phpunit.result.cache +/build/ composer.lock /.idea diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..9278bf7 --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,6 @@ +parameters: + ignoreErrors: + - + message: "#^Consider using bind method instead or pass a closure\\.$#" + count: 1 + path: src/ImpersonateServiceProvider.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..4e42adc --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,23 @@ +includes: + - ./vendor/larastan/larastan/extension.neon + - phpstan-baseline.neon + +parameters: + level: 5 + paths: + - src + - config + - migrations + tmpDir: build/phpstan + checkOctaneCompatibility: true + reportUnmatchedIgnoredErrors: false + + ignoreErrors: + - '#Call to an undefined method .*::isImpersonated#' + - '#Call to an undefined method .*::canImpersonate#' + - '#Call to an undefined method .*::canBeImpersonated#' + - '#Call to an undefined method .*::quietLogin#' + - '#Call to an undefined method .*::quietLogout#' + - '#Call to function method_exists\(\) with Lab404\\Impersonate\\Guard\\SessionGuard .* will always evaluate to true#' + - '#Constructor of class Lab404\\Impersonate\\Exceptions\\.* has an unused parameter \$message#' + - '#Parameter.* expects Illuminate\\Database\\Eloquent\\Model\|null, Illuminate\\Contracts\\Auth\\Authenticatable given#' diff --git a/src/Guard/SessionGuard.php b/src/Guard/SessionGuard.php index 7dff530..d0b4921 100644 --- a/src/Guard/SessionGuard.php +++ b/src/Guard/SessionGuard.php @@ -24,7 +24,6 @@ public function quietLogin(Authenticatable $user) * Logout the user without updating remember_token * and without firing the Logout event. * - * @param void * @return void */ public function quietLogout() diff --git a/src/ImpersonateServiceProvider.php b/src/ImpersonateServiceProvider.php index 0082015..37fb5c7 100644 --- a/src/ImpersonateServiceProvider.php +++ b/src/ImpersonateServiceProvider.php @@ -66,7 +66,6 @@ public function boot() /** * Register plugin blade directives. * - * @param void * @return void */ protected function registerBladeDirectives() @@ -104,7 +103,6 @@ protected function registerBladeDirectives() /** * Register routes macro. * - * @param void * @return void */ protected function registerRoutesMacro() @@ -120,7 +118,6 @@ protected function registerRoutesMacro() } /** - * @param void * @return void */ protected function registerAuthDriver() @@ -152,7 +149,6 @@ protected function registerAuthDriver() /** * Register plugin middleware. * - * @param void * @return void */ public function registerMiddleware() @@ -163,7 +159,6 @@ public function registerMiddleware() /** * Merge config file. * - * @param void * @return void */ protected function mergeConfig() @@ -176,7 +171,6 @@ protected function mergeConfig() /** * Publish config file. * - * @param void * @return void */ protected function publishConfig() diff --git a/src/Models/Impersonate.php b/src/Models/Impersonate.php index eaa7985..51bb3d6 100644 --- a/src/Models/Impersonate.php +++ b/src/Models/Impersonate.php @@ -5,6 +5,7 @@ use Illuminate\Database\Eloquent\Model; use Lab404\Impersonate\Services\ImpersonateManager; +// @phpstan-ignore trait.unused trait Impersonate { /** diff --git a/src/Services/ImpersonateManager.php b/src/Services/ImpersonateManager.php index 026c8b5..467b7c3 100644 --- a/src/Services/ImpersonateManager.php +++ b/src/Services/ImpersonateManager.php @@ -210,7 +210,7 @@ public function getLeaveRedirectTo(): string } /** - * @return array|null + * @return string|null */ public function getCurrentAuthGuardName() { @@ -252,11 +252,11 @@ protected function extractAuthCookieFromSession(): void } /** - * @param array $values + * @param array|null $values * @param string $search * @return \Illuminate\Support\Collection */ - protected function findByKeyInArray(array $values, string $search) + protected function findByKeyInArray(?array $values, string $search) { return collect($values ?? session()->all()) ->filter(function ($val, $key) use ($search) { diff --git a/src/helpers.php b/src/helpers.php index 0d68157..c08160d 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -28,7 +28,7 @@ function can_impersonate(?string $guard = null): bool * @param string|null $guard * @return bool */ - function can_be_impersonated(Authenticatable $user, ?string $guard = null): bool + function can_be_impersonated(Authenticatable $user, ?string $guard = null): bool { $guard = $guard ?? app('impersonate')->getCurrentAuthGuardName(); return app('auth')->guard($guard)->check()