Skip to content

Commit

Permalink
Merge pull request #828 from paulbalandan/phpstan-codeigniter
Browse files Browse the repository at this point in the history
chore: add phpstan-codeigniter
  • Loading branch information
kenjis authored Sep 13, 2023
2 parents 1b1e9e2 + 16f1eee commit c0f86e8
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 22 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"mikey179/vfsstream": "^1.6.7",
"mockery/mockery": "^1.0",
"firebase/php-jwt": "^6.4",
"rector/rector": "0.18.2"
"rector/rector": "0.18.2",
"codeigniter/phpstan-codeigniter": "^1.1",
"phpstan/extension-installer": "^1.3"
},
"provide": {
"codeigniter4/authentication-implementation": "1.0"
Expand Down
135 changes: 135 additions & 0 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php declare(strict_types = 1);

$ignoreErrors = [];
$ignoreErrors[] = [
'message' => '#^Call to deprecated function random_string\\(\\)\\:
The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Actions/Email2FA.php',
];
$ignoreErrors[] = [
'message' => '#^Call to deprecated function random_string\\(\\)\\:
The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Actions/EmailActivator.php',
];
$ignoreErrors[] = [
'message' => '#^Call to deprecated function random_string\\(\\)\\:
The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Controllers/MagicLinkController.php',
];
$ignoreErrors[] = [
'message' => '#^Call to function assert\\(\\) with false and \'Config Auth…\' will always evaluate to false\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Controllers/RegisterController.php',
];
$ignoreErrors[] = [
'message' => '#^Instanceof between null and CodeIgniter\\\\Shield\\\\Models\\\\UserModel will always evaluate to false\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Controllers/RegisterController.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$name of function model expects a valid class string, array\\|bool\\|float\\|int\\|object\\|string\\|null given\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Controllers/RegisterController.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined method CodeIgniter\\\\Database\\\\ConnectionInterface\\:\\:disableForeignKeyChecks\\(\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Database/Migrations/2020-12-28-223112_create_auth_tables.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined method CodeIgniter\\\\Database\\\\ConnectionInterface\\:\\:enableForeignKeyChecks\\(\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Database/Migrations/2020-12-28-223112_create_auth_tables.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Shield\\\\Filters\\\\AuthRates\\:\\:before\\(\\) should return CodeIgniter\\\\HTTP\\\\RedirectResponse\\|void but returns CodeIgniter\\\\HTTP\\\\ResponseInterface\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Filters/AuthRates.php',
];
$ignoreErrors[] = [
'message' => '#^Method CodeIgniter\\\\Shield\\\\Filters\\\\TokenAuth\\:\\:before\\(\\) should return CodeIgniter\\\\HTTP\\\\RedirectResponse\\|void but returns CodeIgniter\\\\HTTP\\\\ResponseInterface\\.$#',
'count' => 2,
'path' => __DIR__ . '/src/Filters/TokenAuth.php',
];
$ignoreErrors[] = [
'message' => '#^Call to deprecated function random_string\\(\\)\\:
The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Models/TokenLoginModel.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Models/TokenLoginModel.php',
];
$ignoreErrors[] = [
'message' => '#^Call to deprecated function random_string\\(\\)\\:
The type \'basic\', \'md5\', and \'sha1\' are deprecated\\. They are not cryptographically secure\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Models/UserIdentityModel.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Models/UserIdentityModel.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 2,
'path' => __DIR__ . '/tests/Authentication/AuthHelperTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 2,
'path' => __DIR__ . '/tests/Authentication/Authenticators/AccessTokenAuthenticatorTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 6,
'path' => __DIR__ . '/tests/Authentication/Filters/SessionFilterTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 2,
'path' => __DIR__ . '/tests/Authentication/HasAccessTokensTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 4,
'path' => __DIR__ . '/tests/Authorization/AuthorizableTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Unit/UserModelTest.php',
];
$ignoreErrors[] = [
'message' => '#^Call to an undefined method CodeIgniter\\\\Shield\\\\Models\\\\UserModel\\:\\:getLastQuery\\(\\)\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Unit/UserTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$active on array\\|object\\.$#',
'count' => 2,
'path' => __DIR__ . '/tests/Unit/UserTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$email on array\\|object\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Unit/UserTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$id on array\\|object\\.$#',
'count' => 4,
'path' => __DIR__ . '/tests/Unit/UserTest.php',
];
$ignoreErrors[] = [
'message' => '#^Cannot access property \\$password_hash on array\\|object\\.$#',
'count' => 1,
'path' => __DIR__ . '/tests/Unit/UserTest.php',
];

return ['parameters' => ['ignoreErrors' => $ignoreErrors]];
26 changes: 9 additions & 17 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
includes:
- phpstan-baseline.php

parameters:
tmpDir: build/phpstan
level: 5
Expand All @@ -8,27 +11,16 @@ parameters:
- vendor/codeigniter4/framework/system/Test/bootstrap.php
excludePaths:
- src/Views/*
ignoreErrors:
- '#Call to an undefined method CodeIgniter\\Database\\ConnectionInterface::[A-Za-z].+\(\)#'
- '#Cannot access property [\$a-z_]+ on (array|object)#'
- '#Call to an undefined method CodeIgniter\\Shield\\Models\\UserModel::getLastQuery\(\)#'
-
message: '#Call to deprecated function random_string\(\):#'
paths:
- src/Authentication/Actions/Email2FA.php
- src/Authentication/Actions/EmailActivator.php
- src/Controllers/MagicLinkController.php
- src/Models/TokenLoginModel.php
- src/Models/UserIdentityModel.php
universalObjectCratesClasses:
- CodeIgniter\Entity
- CodeIgniter\Entity\Entity
- Faker\Generator
scanDirectories:
- vendor/codeigniter4/framework/system/Helpers
- vendor/codeigniter4/settings/src/Helpers
dynamicConstantNames:
- APP_NAMESPACE
- CI_DEBUG
- ENVIRONMENT
- CodeIgniter\CodeIgniter::CI_VERSION
codeigniter:
additionalConfigNamespaces:
- CodeIgniter\Settings\Config
- CodeIgniter\Shield\Config
additionalServices:
- CodeIgniter\Shield\Config\Services
7 changes: 4 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@
realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php',
]);

if (is_file(__DIR__ . '/phpstan.neon.dist')) {
$rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist');
}
$rectorConfig->phpstanConfigs([
__DIR__ . '/phpstan.neon.dist',
__DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon',
]);

// Set the target version for refactoring
$rectorConfig->phpVersion(PhpVersion::PHP_74);
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace CodeIgniter\Shield\Config;

use CodeIgniter\Config\BaseService;
use CodeIgniter\Shield\Auth;
use CodeIgniter\Shield\Authentication\Authentication;
use CodeIgniter\Shield\Authentication\JWTManager;
use CodeIgniter\Shield\Authentication\Passwords;
use Config\Services as BaseService;

class Services extends BaseService
{
Expand Down

0 comments on commit c0f86e8

Please sign in to comment.