Skip to content

Commit

Permalink
PHPStan test and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
erikn69 committed Feb 6, 2025
1 parent 395c73b commit cd9ee9a
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/vendor/
*.phpunit.result.cache
/build/
composer.lock
/.idea
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
ignoreErrors:
-
message: "#^Consider using bind method instead or pass a closure\\.$#"
count: 1
path: src/ImpersonateServiceProvider.php
23 changes: 23 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -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#'
1 change: 0 additions & 1 deletion src/Guard/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 0 additions & 6 deletions src/ImpersonateServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function boot()
/**
* Register plugin blade directives.
*
* @param void
* @return void
*/
protected function registerBladeDirectives()
Expand Down Expand Up @@ -104,7 +103,6 @@ protected function registerBladeDirectives()
/**
* Register routes macro.
*
* @param void
* @return void
*/
protected function registerRoutesMacro()
Expand All @@ -120,7 +118,6 @@ protected function registerRoutesMacro()
}

/**
* @param void
* @return void
*/
protected function registerAuthDriver()
Expand Down Expand Up @@ -152,7 +149,6 @@ protected function registerAuthDriver()
/**
* Register plugin middleware.
*
* @param void
* @return void
*/
public function registerMiddleware()
Expand All @@ -163,7 +159,6 @@ public function registerMiddleware()
/**
* Merge config file.
*
* @param void
* @return void
*/
protected function mergeConfig()
Expand All @@ -176,7 +171,6 @@ protected function mergeConfig()
/**
* Publish config file.
*
* @param void
* @return void
*/
protected function publishConfig()
Expand Down
1 change: 1 addition & 0 deletions src/Models/Impersonate.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Lab404\Impersonate\Services\ImpersonateManager;

// @phpstan-ignore trait.unused
trait Impersonate
{
/**
Expand Down
6 changes: 3 additions & 3 deletions src/Services/ImpersonateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function getLeaveRedirectTo(): string
}

/**
* @return array|null
* @return string|null
*/
public function getCurrentAuthGuardName()
{
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit cd9ee9a

Please sign in to comment.