Skip to content
Closed
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 composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"mockery/mockery": "^1.0",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"rector/rector": "0.18.13"
"rector/rector": "0.19.0"
},
"provide": {
"codeigniter4/authentication-implementation": "1.0"
Expand Down
30 changes: 3 additions & 27 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,7 @@
'count' => 1,
'path' => __DIR__ . '/src/Collectors/Auth.php',
];
$ignoreErrors[] = [
'message' => '#^PHPDoc type array\\<string, string\\> of property CodeIgniter\\\\Shield\\\\Commands\\\\Generators\\\\UserModelGenerator\\:\\:\\$arguments is not the same as PHPDoc type array of overridden property CodeIgniter\\\\CLI\\\\BaseCommand\\:\\:\\$arguments\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Commands/Generators/UserModelGenerator.php',
];
$ignoreErrors[] = [
'message' => '#^PHPDoc type array\\<string, string\\> of property CodeIgniter\\\\Shield\\\\Commands\\\\Generators\\\\UserModelGenerator\\:\\:\\$options is not the same as PHPDoc type array of overridden property CodeIgniter\\\\CLI\\\\BaseCommand\\:\\:\\$options\\.$#',
'count' => 1,
'path' => __DIR__ . '/src/Commands/Generators/UserModelGenerator.php',
];

$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 1,
Expand Down Expand Up @@ -317,23 +308,8 @@
'path' => __DIR__ . '/src/Models/UserModel.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$data \\(array\\|CodeIgniter\\\\Shield\\\\Entities\\\\User\\) of method CodeIgniter\\\\Shield\\\\Models\\\\UserModel\\:\\:insert\\(\\) should be contravariant with parameter \\$data \\(array\\|object\\|null\\) of method CodeIgniter\\\\Model\\:\\:insert\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/src/Models/UserModel.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#1 \\$data \\(array\\|CodeIgniter\\\\Shield\\\\Entities\\\\User\\) of method CodeIgniter\\\\Shield\\\\Models\\\\UserModel\\:\\:save\\(\\) should be contravariant with parameter \\$data \\(array\\|object\\) of method CodeIgniter\\\\BaseModel\\:\\:save\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/src/Models/UserModel.php',
];
$ignoreErrors[] = [
'message' => '#^Parameter \\#2 \\$data \\(array\\|CodeIgniter\\\\Shield\\\\Entities\\\\User\\) of method CodeIgniter\\\\Shield\\\\Models\\\\UserModel\\:\\:update\\(\\) should be contravariant with parameter \\$data \\(array\\|object\\|null\\) of method CodeIgniter\\\\Model\\:\\:update\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/src/Models/UserModel.php',
];
$ignoreErrors[] = [
'message' => '#^Return type \\(int\\|string\\|true\\) of method CodeIgniter\\\\Shield\\\\Models\\\\UserModel\\:\\:insert\\(\\) should be covariant with return type \\(int\\|object\\|string\\|false\\) of method CodeIgniter\\\\Model\\:\\:insert\\(\\)$#',
'count' => 1,
'message' => '#^Return type \\(int|string|true\\) of method CodeIgniter\\\\Shield\\\\Models\\\\UserModel\\:\\:insert\\(\\) should be covariant with return type \\(\\(\\$returnID is true \\? int|string|false \\: bool\\) of method CodeIgniter\\\\Model\\:\\:insert\\(\\)\\$#',
'count' => 4,
'path' => __DIR__ . '/src/Models/UserModel.php',
];
$ignoreErrors[] = [
Expand Down
6 changes: 0 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector;
use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\DeadCode\Rector\StmtsAwareInterface\RemoveJustPropertyFetchForAssignRector;
use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector;
use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector;
Expand Down Expand Up @@ -99,11 +98,6 @@
// May load view files directly when detecting classes
StringClassNameToClassConstantRector::class,

// See https://github.com/codeigniter4/shield/issues/228
RemoveJustPropertyFetchForAssignRector::class => [
__DIR__ . '/src/Models/UserModel.php',
],

// Ignore tests that use CodeIgniter::CI_VERSION
UnwrapFutureCompatibleIfPhpVersionRector::class => [
__DIR__ . '/src/Test/MockInputOutput.php',
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Hmac.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Hmac extends BaseCommand
/**
* the Command's Arguments
*
* @var array
* @var array<string, string>
*/
protected $arguments = [
'action' => <<<'EOL'
Expand All @@ -72,7 +72,7 @@ class Hmac extends BaseCommand
/**
* the Command's Options
*
* @var array
* @var array<string, string>
*/
protected $options = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ class Setup extends BaseCommand
/**
* the Command's Arguments
*
* @var array
* @var array<string, string>
*/
protected $arguments = [];

/**
* the Command's Options
*
* @var array
* @var array<string, string>
*/
protected $options = [
'-f' => 'Force overwrite ALL existing files in destination.',
Expand Down
8 changes: 6 additions & 2 deletions src/Commands/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class User extends BaseCommand
/**
* Command's Arguments
*
* @var array
* @var array<string, string>
*/
protected $arguments = [
'action' => <<<'EOL'
Expand All @@ -107,7 +107,7 @@ class User extends BaseCommand
/**
* Command's Options
*
* @var array
* @var array<string, string>
*/
protected $options = [
'-i' => 'User id',
Expand Down Expand Up @@ -301,6 +301,10 @@ private function create(?string $username = null, ?string $email = null): void
$user = new UserEntity($data);
$userModel->save($user);

// Add to default group
$user = $userModel->findById($userModel->getInsertID());
$userModel->addToDefaultGroup($user);

$this->write('User "' . $username . '" created', 'green');
}

Expand Down
6 changes: 3 additions & 3 deletions src/Models/UserIdentityModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,15 +542,15 @@ public function forceGlobalPasswordReset(): void
* Throws an Exception when it fails.
*
* @param array|int|string|null $id
* @param array|object|null $data
* @param array|object|null $row
*
* @return true if the update is successful
*
* @throws ValidationException
*/
public function update($id = null, $data = null): bool
public function update($id = null, $row = null): bool
{
$result = parent::update($id, $data);
$result = parent::update($id, $row);

$this->checkQueryReturn($result);

Expand Down
22 changes: 11 additions & 11 deletions src/Models/UserModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,18 @@ public function activate(User $user): void
* Override the BaseModel's `insert()` method.
* If you pass User object, also inserts Email Identity.
*
* @param array|User $data
* @param array|User $row
*
* @return int|string|true Insert ID if $returnID is true
*
* @throws ValidationException
*/
public function insert($data = null, bool $returnID = true)
public function insert($row = null, bool $returnID = true)
{
// Clone User object for not changing the passed object.
$this->tempUser = $data instanceof User ? clone $data : null;
$this->tempUser = $row instanceof User ? clone $row : null;

$result = parent::insert($data, $returnID);
$result = parent::insert($row, $returnID);

$this->checkQueryReturn($result);

Expand All @@ -274,20 +274,20 @@ public function insert($data = null, bool $returnID = true)
* If you pass User object, also updates Email Identity.
*
* @param array|int|string|null $id
* @param array|User $data
* @param array|User $row
*
* @return true if the update is successful
*
* @throws ValidationException
*/
public function update($id = null, $data = null): bool
public function update($id = null, $row = null): bool
{
// Clone User object for not changing the passed object.
$this->tempUser = $data instanceof User ? clone $data : null;
$this->tempUser = $row instanceof User ? clone $row : null;

try {
/** @throws DataException */
$result = parent::update($id, $data);
$result = parent::update($id, $row);
} catch (DataException $e) {
// When $data is an array.
if ($this->tempUser === null) {
Expand Down Expand Up @@ -316,15 +316,15 @@ public function update($id = null, $data = null): bool
* Override the BaseModel's `save()` method.
* If you pass User object, also updates Email Identity.
*
* @param array|User $data
* @param array|User $row
*
* @return true if the save is successful
*
* @throws ValidationException
*/
public function save($data): bool
public function save($row): bool
{
$result = parent::save($data);
$result = parent::save($row);

$this->checkQueryReturn($result);

Expand Down
4 changes: 2 additions & 2 deletions tests/Authentication/MagicLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function testMagicLinkVerifyExpired(): void
'user_id' => $user->id,
'type' => Session::ID_TYPE_MAGIC_LINK,
'secret' => 'abasdasdf',
'expires' => Time::now()->subDays(5),
'expires' => Time::now()->subDays(5)->format('Y-m-d H:i:s'),
]);

$result = $this->get(route_to('verify-magic-link') . '?token=abasdasdf');
Expand All @@ -136,7 +136,7 @@ public function testMagicLinkVerifySuccess(): void
'user_id' => $user->id,
'type' => Session::ID_TYPE_MAGIC_LINK,
'secret' => 'abasdasdf',
'expires' => Time::now()->addMinutes(60),
'expires' => Time::now()->addMinutes(60)->format('Y-m-d H:i:s'),
]);

$result = $this->get(route_to('verify-magic-link') . '?token=abasdasdf');
Expand Down
5 changes: 5 additions & 0 deletions tests/Commands/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Tests\Commands;

use CodeIgniter\Shield\Commands\User;
use CodeIgniter\Shield\Config\AuthGroups;
use CodeIgniter\Shield\Entities\User as UserEntity;
use CodeIgniter\Shield\Models\UserModel;
use CodeIgniter\Shield\Test\MockInputOutput;
Expand Down Expand Up @@ -93,6 +94,10 @@ public function testCreate(): void
'id' => $user->id,
'active' => 0,
]);
$this->seeInDatabase($this->tables['groups_users'], [
'user_id' => $user->id,
'group' => config(AuthGroups::class)->defaultGroup,
]);
}

public function testCreateNotUniqueName(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/Controllers/MagicLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function testMagicLinkVerifyPendingRegistrationActivation(): void
'user_id' => $user->id,
'type' => Session::ID_TYPE_MAGIC_LINK,
'secret' => 'abasdasdf',
'expires' => Time::now()->addMinutes(60),
'expires' => Time::now()->addMinutes(60)->format('Y-m-d H:i:s'),
]);

$result = $this->get(route_to('verify-magic-link') . '?token=abasdasdf');
Expand Down