Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yml,yaml}]
[*.{neon,yml,yaml}]
indent_size = 2
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/infection.json5 export-ignore
/mkdocs.yml export-ignore
/phpstan-baseline.php export-ignore
/phpstan.neon.dist export-ignore
/phpstan.dist.neon export-ignore
/phpunit.dist.xml export-ignore
/pyrameter.php export-ignore
/psalm_autoload.php export-ignore
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- 'composer.json'
- 'infection.json5'
- 'phpunit.dist.xml'
- 'phpstan.neon.dist'
- 'phpstan.dist.neon'
- '.github/workflows/mutation.yml'
push:
branches:
Expand All @@ -21,7 +21,7 @@ on:
- 'composer.json'
- 'infection.json5'
- 'phpunit.dist.xml'
- 'phpstan.neon.dist'
- 'phpstan.dist.neon'
- '.github/workflows/mutation.yml'

permissions:
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@ on:
- develop
paths:
- '**.php'
- 'composer.*'
- 'phpstan*'
- 'composer.json'
- 'phpstan.dist.neon'
- '.github/workflows/phpstan.yml'
push:
branches:
- develop
paths:
- '**.php'
- 'composer.*'
- 'phpstan*'
- 'composer.json'
- 'phpstan.dist.neon'
- '.github/workflows/phpstan.yml'

permissions:
contents: read

jobs:
phpstan:
uses: codeigniter4/.github/.github/workflows/phpstan.yml@CI47
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
},
"scripts": {
"analyze": [
"phpstan analyze",
"@phpstan:check",
"psalm",
"rector process --dry-run"
],
Expand All @@ -100,7 +100,8 @@
"@putenv PYRAMETER_DISABLED=1",
"bin/mutation-filter"
],
"sa": "@analyze",
"phpstan:baseline": "@phpstan:check --generate-baseline=phpstan-baseline.php",
"phpstan:check": "phpstan analyse --ansi --verbose",
"style": "@cs-fix",
"test": "phpunit"
}
Expand Down
126 changes: 0 additions & 126 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,6 @@
<?php declare(strict_types = 1);

$ignoreErrors = [];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Actions/Email2FA.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Authentication.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 2,
'path' => __DIR__ . '/src/Authentication/Authenticators/AccessTokens.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in &&, CodeIgniter\\I18n\\Time|null given on the left side.',
'identifier' => 'booleanAnd.leftNotBoolean',
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Authenticators/AccessTokens.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Parameter #1 $credentials (array{token?: string}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\JWT::attempt() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::attempt()',
'identifier' => 'method.childParameterType',
Expand All @@ -37,18 +13,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Authenticators/JWT.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Authenticators/Session.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in an if condition, int|string|null given.',
'identifier' => 'if.condNotBoolean',
'count' => 3,
'path' => __DIR__ . '/src/Authentication/Authenticators/Session.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Parameter #1 $credentials (array{email?: string, username?: string, password?: string, ...<string, string>}) of method CodeIgniter\\Shield\\Authentication\\Authenticators\\Session::attempt() should be contravariant with parameter $credentials (array) of method CodeIgniter\\Shield\\Authentication\\AuthenticatorInterface::attempt()',
'identifier' => 'method.childParameterType',
Expand All @@ -61,24 +25,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Authenticators/Session.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 4,
'path' => __DIR__ . '/src/Authentication/Passwords/NothingPersonalValidator.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in &&, CodeIgniter\\Shield\\Entities\\User|null given on the right side.',
'identifier' => 'booleanAnd.rightNotBoolean',
'count' => 1,
'path' => __DIR__ . '/src/Authentication/Passwords/ValidationRules.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 3,
'path' => __DIR__ . '/src/Authorization/Groups.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Return type (int|string|null) of method CodeIgniter\\Shield\\Collectors\\Auth::getBadgeValue() should be covariant with return type (int|null) of method CodeIgniter\\Debug\\Toolbar\\Collectors\\BaseCollector::getBadgeValue()',
'identifier' => 'method.childReturnType',
Expand Down Expand Up @@ -133,18 +79,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Database/Migrations/2020-12-28-223112_create_auth_tables.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in a ternary operator condition, int<0, max> given.',
'identifier' => 'ternary.condNotBoolean',
'count' => 1,
'path' => __DIR__ . '/src/Entities/User.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 1,
'path' => __DIR__ . '/src/Filters/AbstractAuthFilter.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Return type (CodeIgniter\\HTTP\\RedirectResponse|void) of method CodeIgniter\\Shield\\Filters\\AbstractAuthFilter::before() should be covariant with return type (CodeIgniter\\HTTP\\RequestInterface|CodeIgniter\\HTTP\\ResponseInterface|string|null) of method CodeIgniter\\Filters\\FilterInterface::before()',
'identifier' => 'method.childReturnType',
Expand Down Expand Up @@ -229,12 +163,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Filters/SessionAuth.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 1,
'path' => __DIR__ . '/src/Filters/TokenAuth.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Method CodeIgniter\\Shield\\Filters\\TokenAuth::before() should return CodeIgniter\\HTTP\\RedirectResponse|void but returns CodeIgniter\\HTTP\\ResponseInterface.',
'identifier' => 'return.type',
Expand All @@ -253,12 +181,6 @@
'count' => 1,
'path' => __DIR__ . '/src/Filters/TokenAuth.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Construct empty() is not allowed. Use more strict comparison.',
'identifier' => 'empty.notAllowed',
'count' => 2,
'path' => __DIR__ . '/src/Models/UserModel.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Parameter #1 $row (array|CodeIgniter\\Shield\\Entities\\User) of method CodeIgniter\\Shield\\Models\\UserModel::insert() should be contravariant with parameter $row (array<mixed>|object|null) of method CodeIgniter\\Model::insert()',
'identifier' => 'method.childParameterType',
Expand All @@ -283,42 +205,12 @@
'count' => 1,
'path' => __DIR__ . '/src/Models/UserModel.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to method PHPUnit\\Framework\\Assert::assertInstanceOf() with \'CodeIgniter\\\\Shield\\\\Result\' and CodeIgniter\\Shield\\Result will always evaluate to true.',
'identifier' => 'method.alreadyNarrowedType',
'count' => 3,
'path' => __DIR__ . '/tests/Authentication/Authenticators/JWTAuthenticatorTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to method PHPUnit\\Framework\\Assert::assertInstanceOf() with \'CodeIgniter\\\\Shield\\\\Result\' and CodeIgniter\\Shield\\Result will always evaluate to true.',
'identifier' => 'method.alreadyNarrowedType',
'count' => 8,
'path' => __DIR__ . '/tests/Authentication/Authenticators/SessionAuthenticatorTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to method setCookie() of internal class CodeIgniter\\Superglobals from outside its root namespace CodeIgniter.',
'identifier' => 'method.internalClass',
'count' => 2,
'path' => __DIR__ . '/tests/Authentication/Authenticators/SessionAuthenticatorTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Implicit array creation is not allowed - variable $users might not exist.',
'identifier' => 'variable.implicitArray',
'count' => 1,
'path' => __DIR__ . '/tests/Authentication/ForcePasswordResetTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Variable $users might not be defined.',
'identifier' => 'variable.undefined',
'count' => 1,
'path' => __DIR__ . '/tests/Authentication/ForcePasswordResetTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to method PHPUnit\\Framework\\Assert::assertInstanceOf() with \'CodeIgniter\\\\Shield\\\\Entities\\\\AccessToken\' and CodeIgniter\\Shield\\Entities\\AccessToken will always evaluate to true.',
'identifier' => 'method.alreadyNarrowedType',
'count' => 1,
'path' => __DIR__ . '/tests/Authentication/HasAccessTokensTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to method setServer() of internal class CodeIgniter\\Superglobals from outside its root namespace CodeIgniter.',
'identifier' => 'method.internalClass',
Expand Down Expand Up @@ -349,18 +241,6 @@
'count' => 1,
'path' => __DIR__ . '/tests/Controllers/MagicLinkTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Only booleans are allowed in a ternary operator condition, string|null given.',
'identifier' => 'ternary.condNotBoolean',
'count' => 2,
'path' => __DIR__ . '/tests/Language/AbstractTranslationTestCase.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to method PHPUnit\\Framework\\Assert::assertIsString() with string will always evaluate to true.',
'identifier' => 'method.alreadyNarrowedType',
'count' => 6,
'path' => __DIR__ . '/tests/Unit/Authentication/JWT/JWTManagerTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to deprecated method __construct() of class CodeIgniter\\HTTP\\Response:
4.5.0 The param $config is no longer used.',
Expand All @@ -374,12 +254,6 @@
'count' => 9,
'path' => __DIR__ . '/tests/Unit/UserTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Call to method PHPUnit\\Framework\\Assert::assertInstanceOf() with \'CodeIgniter\\\\Shield\\\\Entities\\\\UserIdentity\' and CodeIgniter\\Shield\\Entities\\UserIdentity will always evaluate to true.',
'identifier' => 'method.alreadyNarrowedType',
'count' => 1,
'path' => __DIR__ . '/tests/Unit/UserTest.php',
];
$ignoreErrors[] = [
'rawMessage' => 'Offset 1 does not exist on array{CodeIgniter\\Shield\\Entities\\User}.',
'identifier' => 'offsetAccess.notFound',
Expand Down
40 changes: 40 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
includes:
- phpstan-baseline.php
- phar://vendor/phpstan/phpstan/phpstan.phar/conf/bleedingEdge.neon

parameters:
tmpDir: build/phpstan
level: 5
paths:
- src/
- tests/
bootstrapFiles:
- vendor/codeigniter4/framework/system/Test/bootstrap.php
excludePaths:
- src/Views/*
universalObjectCratesClasses:
- Faker\Generator
scanDirectories:
- vendor/codeigniter4/framework/system/Helpers
- vendor/codeigniter4/settings/src/Helpers
dynamicConstantNames:
- CodeIgniter\CodeIgniter::CI_VERSION
codeigniter:
additionalConfigNamespaces:
- CodeIgniter\Settings\Config
- CodeIgniter\Shield\Config
additionalServices:
- CodeIgniter\Shield\Config\Services
strictRules:
allRules: false
disallowedLooseComparison: true
booleansInConditions: true
disallowedBacktick: true
disallowedEmpty: true
disallowedImplicitArrayCreation: true
disallowedShortTernary: true
matchingInheritedMethodNames: true
ignoreErrors:
- identifier: function.internal
- identifier: return.internalClass
- identifier: staticMethod.internal
40 changes: 0 additions & 40 deletions phpstan.neon.dist

This file was deleted.

2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
]);

$rectorConfig->phpstanConfigs([
__DIR__ . '/phpstan.neon.dist',
__DIR__ . '/phpstan.dist.neon',
__DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon',
__DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon',
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Actions/Email2FA.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function handle(IncomingRequest $request)
throw new RuntimeException('Cannot get the pending login User.');
}

if (empty($email) || $email !== $user->email) {
if ($email !== $user->email) {
return redirect()->route('auth-action-show')->with('error', lang('Auth.invalidEmail', [$email]));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Authentication/Authentication.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function factory(?string $alias = null): AuthenticatorInterface
$alias ??= $this->config->defaultAuthenticator;

// Return the cached instance if we have it
if (! empty($this->instances[$alias])) {
if (isset($this->instances[$alias])) {
return $this->instances[$alias];
}

Expand Down
Loading
Loading