Skip to content

Commit

Permalink
Fix static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
MGatner committed Apr 27, 2022
1 parent 78b9cb1 commit 7b1f045
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ parameters:
- '#.+Mockery.+#'
- '#Call to an undefined method .+::shouldReceive\(\)#'
- '#Call to an undefined method CodeIgniter\\Database\\BaseBuilder::[A-Za-z]+\(\)#'
- '#Call to an undefined method CodeIgniter\\Model::[A-Za-z]+\(\)#'
- '#Call to an undefined static method Config\\Services::[A-Za-z]+\(\)#'
- '#Cannot access property [\$a-z_]+ on (array|object)#'
- '#Parameter \$user of method Myth\\Auth\\Authentication\\Passwords\\ValidatorInterface::check\(\) has typehint with deprecated class CodeIgniter\\Entity#'
Expand Down
4 changes: 4 additions & 0 deletions src/Commands/SetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class SetPassword extends BaseCommand

public function run(array $params = [])
{
/**
* @var array<int, string> $params
*/

// Consume or prompt for password
$identity = $params[0] ?? null;
$password = $params[1] ?? null;
Expand Down
5 changes: 3 additions & 2 deletions src/Config/Services.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static function authentication(string $lib = 'local', ?Model $userModel =
->setLoginModel($loginModel);
}

// Note that these input models *must be* of types GroupModel, PermissionModel, and UserModel respectively
public static function authorization(?Model $groupModel = null, ?Model $permissionModel = null, ?Model $userModel = null, bool $getShared = true)
{
if ($getShared) {
Expand All @@ -47,9 +48,9 @@ public static function authorization(?Model $groupModel = null, ?Model $permissi
$permissionModel ??= model(PermissionModel::class);
$userModel ??= model(UserModel::class);

$instance = new FlatAuthorization($groupModel, $permissionModel);
$instance = new FlatAuthorization($groupModel, $permissionModel); // @phpstan-ignore-line

return $instance->setUserModel($userModel);
return $instance->setUserModel($userModel); // @phpstan-ignore-line
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/_support/AuthTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ protected function setUp(): void

$this->resetAuthServices();

$this->users = model(UserModel::class, false);
$this->groups = model(GroupModel::class, false);
$this->permissions = model(PermissionModel::class, false);
$this->users = model(UserModel::class, false); // @phpstan-ignore-line
$this->groups = model(GroupModel::class, false); // @phpstan-ignore-line
$this->permissions = model(PermissionModel::class, false); // @phpstan-ignore-line

$this->faker = Factory::create();
}
Expand Down
10 changes: 5 additions & 5 deletions tests/controllers/LoginTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use CodeIgniter\Test\ControllerTester;
use CodeIgniter\Test\ControllerTestTrait;
use Myth\Auth\Controllers\AuthController;
use Tests\Support\AuthTestCase;

Expand All @@ -9,7 +9,7 @@
*/
final class LoginTest extends AuthTestCase
{
use ControllerTester;
use ControllerTestTrait;

protected $refresh = true;

Expand All @@ -23,7 +23,7 @@ protected function setUp(): void
$vConfig = new \Config\Validation();
$vConfig->ruleSets[] = \Myth\Auth\Authentication\Passwords\ValidationRules::class;
$vConfig->ruleSets = array_reverse($vConfig->ruleSets);
\CodeIgniter\Config\Config::injectMock('Validation', $vConfig);
\CodeIgniter\Config\Factories::injectMock('Config', 'Validation', $vConfig);

// Make sure our routes are mapped
$routes = service('routes');
Expand Down Expand Up @@ -82,7 +82,7 @@ public function testAttemptLoginSuccess()
// Just make sure since it's a default
$config = config('Auth');
$config->allowRemembering = false;
\CodeIgniter\Config\Config::injectMock('Auth', $config);
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config);

$result = $this->withUri(site_url('login'))
->withRequest($request)
Expand Down Expand Up @@ -122,7 +122,7 @@ public function testAttemptLoginSuccessWithRememberMe()
// Just make sure since it's a default
$config = config('Auth');
$config->allowRemembering = true;
\CodeIgniter\Config\Config::injectMock('Auth', $config);
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config);

$result = $this->withUri(site_url('login'))
->withRequest($request)
Expand Down
10 changes: 5 additions & 5 deletions tests/controllers/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp(): void
$vConfig = new \Config\Validation();
$vConfig->ruleSets[] = \Myth\Auth\Authentication\Passwords\ValidationRules::class;
$vConfig->ruleSets = array_reverse($vConfig->ruleSets);
\CodeIgniter\Config\Config::injectMock('Validation', $vConfig);
\CodeIgniter\Config\Factories::injectMock('Config', 'Validation', $vConfig);

// Make sure our routes are mapped
$routes = service('routes');
Expand All @@ -49,7 +49,7 @@ public function testAttemptRegisterDisabled()
{
$config = new \Myth\Auth\Config\Auth();
$config->allowRegistration = false;
\CodeIgniter\Config\Config::injectMock('Auth', $config);
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config);

$result = $this->withUri(site_url('register'))
->controller(AuthController::class)
Expand All @@ -63,7 +63,7 @@ public function testAttemptRegisterValidationErrors()
{
$config = new \Myth\Auth\Config\Auth();
$config->allowRegistration = true;
\CodeIgniter\Config\Config::injectMock('Auth', $config);
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config);

$result = $this->withUri(site_url('register'))
->controller(AuthController::class)
Expand Down Expand Up @@ -93,7 +93,7 @@ public function testAttemptRegisterCreatesUser()
// don't require activation for this...
$config = config('Auth');
$config->requireActivation = null;
\CodeIgniter\Config\Config::injectMock('Auth', $config);
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config);

$result = $this->withUri(site_url('register'))
->withRequest($request)
Expand Down Expand Up @@ -132,7 +132,7 @@ public function testAttemptRegisterCreatesUserWithDefaultGroup()
$config = config('Auth');
$config->requireActivation = null;
$config->defaultUserGroup = $group->name;
\CodeIgniter\Config\Config::injectMock('Auth', $config);
\CodeIgniter\Config\Factories::injectMock('Config', 'Auth', $config);

$result = $this->withUri(site_url('register'))
->withRequest($request)
Expand Down
17 changes: 5 additions & 12 deletions tests/unit/NothingPersonalValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,11 @@ public function testIsNotPersonalFalsePositivesCaughtByIsNotSimilar($password)
$config->maxSimilarity = 50;
$this->validator->setConfig($config);

$isNotPersonal = $this->getPrivateMethodInvoker(
$this->validator,
'isNotPersonal',
[$password, $user]
);
$method = $this->getPrivateMethodInvoker($this->validator, 'isNotPersonal');
$isNotPersonal = $method($password, $user);

$isNotSimilar = $this->getPrivateMethodInvoker(
$this->validator,
'isNotSimilar',
[$password, $user]
);
$method = $this->getPrivateMethodInvoker($this->validator, 'isNotSimilar');
$isNotSimilar = $method($password, $user);

$this->assertNotSame($isNotPersonal, $isNotSimilar);
}
Expand Down Expand Up @@ -194,8 +188,7 @@ public function firstLastNameProvider()
public function testMaxSimilarityZeroTurnsOffSimilarityCalculation(
$maxSimilarity,
$expected
)
{
) {
$config = new \Myth\Auth\Config\Auth();
$config->maxSimilarity = $maxSimilarity;
$this->validator->setConfig($config);
Expand Down

0 comments on commit 7b1f045

Please sign in to comment.