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

PHPStan test and fixes #194

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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:
push:
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.3
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/
/build/
*.phpunit.result.cache
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
20 changes: 20 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
includes:
- ./vendor/larastan/larastan/extension.neon
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src
- config
- migrations
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkMissingIterableValueType: false

ignoreErrors:
- '#Call to an undefined method .*::isImpersonated#'
- '#Call to an undefined method .*::canImpersonate#'
- '#Call to an undefined method .*::canBeImpersonated#'
- '#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
6 changes: 3 additions & 3 deletions src/Services/ImpersonateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public function getLeaveRedirectTo(): string
}

/**
* @return array|null
* @return string|null
*/
public function getCurrentAuthGuardName()
{
Expand Down Expand Up @@ -245,11 +245,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