Skip to content

Commit 1bdd37c

Browse files
committed
refactor: use CheckQueryReturnTrait in BaseModel
1 parent 2d93da1 commit 1bdd37c

7 files changed

Lines changed: 8 additions & 25 deletions

File tree

src/Models/CheckQueryReturnTrait.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010

1111
trait CheckQueryReturnTrait
1212
{
13-
private ?bool $currentDBDebug = null;
13+
protected ?bool $currentDBDebug = null;
1414

1515
/**
1616
* @param bool|int|string $return insert() returns insert ID.
1717
*/
18-
private function checkQueryReturn($return): void
18+
protected function checkQueryReturn($return): void
1919
{
2020
$this->restoreDBDebug();
2121

@@ -30,7 +30,7 @@ private function checkQueryReturn($return): void
3030
}
3131
}
3232

33-
private function checkValidationError(): void
33+
protected function checkValidationError(): void
3434
{
3535
$validationErrors = $this->getValidationErrors();
3636

@@ -50,14 +50,14 @@ private function checkValidationError(): void
5050
*
5151
* @return string[]
5252
*/
53-
private function getValidationErrors(): array
53+
protected function getValidationErrors(): array
5454
{
5555
// @TODO When CI v4.3 is released, you don't need this hack.
5656
// See https://github.com/codeigniter4/CodeIgniter4/pull/6384
5757
return $this->getValidationPropertyErrors();
5858
}
5959

60-
private function getValidationPropertyErrors(): array
60+
protected function getValidationPropertyErrors(): array
6161
{
6262
$refClass = new ReflectionObject($this->validation);
6363
$refProperty = $refClass->getProperty('errors');
@@ -66,7 +66,7 @@ private function getValidationPropertyErrors(): array
6666
return $refProperty->getValue($this->validation);
6767
}
6868

69-
private function disableDBDebug(): void
69+
protected function disableDBDebug(): void
7070
{
7171
if (! $this->db->DBDebug) {
7272
// `DBDebug` is false. Do nothing.
@@ -79,7 +79,7 @@ private function disableDBDebug(): void
7979
$propertyDBDebug->setValue($this->db, false);
8080
}
8181

82-
private function restoreDBDebug(): void
82+
protected function restoreDBDebug(): void
8383
{
8484
if ($this->currentDBDebug === null) {
8585
// `DBDebug` has not been changed. Do nothing.
@@ -92,7 +92,7 @@ private function restoreDBDebug(): void
9292
$this->currentDBDebug = null;
9393
}
9494

95-
private function getPropertyDBDebug(): ReflectionProperty
95+
protected function getPropertyDBDebug(): ReflectionProperty
9696
{
9797
$refClass = new ReflectionObject($this->db);
9898
$refProperty = $refClass->getProperty('DBDebug');

src/Models/GroupModel.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
class GroupModel extends BaseModel
1010
{
11-
use CheckQueryReturnTrait;
12-
1311
protected $primaryKey = 'id';
1412
protected $returnType = 'array';
1513
protected $useSoftDeletes = false;

src/Models/LoginModel.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66

77
use CodeIgniter\I18n\Time;
88
use CodeIgniter\Shield\Authentication\Authenticators\Session;
9-
use CodeIgniter\Shield\Config\Auth;
109
use CodeIgniter\Shield\Entities\Login;
1110
use CodeIgniter\Shield\Entities\User;
1211
use Faker\Generator;
1312

1413
class LoginModel extends BaseModel
1514
{
16-
use CheckQueryReturnTrait;
17-
1815
protected $primaryKey = 'id';
1916
protected $returnType = Login::class;
2017
protected $useSoftDeletes = false;

src/Models/PermissionModel.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
class PermissionModel extends BaseModel
1010
{
11-
use CheckQueryReturnTrait;
12-
1311
protected $primaryKey = 'id';
1412
protected $returnType = 'array';
1513
protected $useSoftDeletes = false;

src/Models/RememberModel.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@
55
namespace CodeIgniter\Shield\Models;
66

77
use CodeIgniter\I18n\Time;
8-
use CodeIgniter\Shield\Config\Auth;
98
use CodeIgniter\Shield\Entities\User;
109
use DateTime;
1110
use Faker\Generator;
1211
use stdClass;
1312

1413
class RememberModel extends BaseModel
1514
{
16-
use CheckQueryReturnTrait;
17-
1815
protected $primaryKey = 'id';
1916
protected $returnType = 'object';
2017
protected $useSoftDeletes = false;

src/Models/UserIdentityModel.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
namespace CodeIgniter\Shield\Models;
66

77
use CodeIgniter\I18n\Time;
8-
use CodeIgniter\Model;
98
use CodeIgniter\Shield\Authentication\Authenticators\AccessTokens;
109
use CodeIgniter\Shield\Authentication\Authenticators\Session;
1110
use CodeIgniter\Shield\Authentication\Passwords;
12-
use CodeIgniter\Shield\Config\Auth;
1311
use CodeIgniter\Shield\Entities\AccessToken;
1412
use CodeIgniter\Shield\Entities\User;
1513
use CodeIgniter\Shield\Entities\UserIdentity;
@@ -19,8 +17,6 @@
1917

2018
class UserIdentityModel extends BaseModel
2119
{
22-
use CheckQueryReturnTrait;
23-
2420
protected $primaryKey = 'id';
2521
protected $returnType = UserIdentity::class;
2622
protected $useSoftDeletes = false;

src/Models/UserModel.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use CodeIgniter\Database\Exceptions\DataException;
88
use CodeIgniter\I18n\Time;
9-
use CodeIgniter\Model;
109
use CodeIgniter\Shield\Authentication\Authenticators\Session;
1110
use CodeIgniter\Shield\Entities\User;
1211
use CodeIgniter\Shield\Entities\UserIdentity;
@@ -19,8 +18,6 @@
1918
*/
2019
class UserModel extends BaseModel
2120
{
22-
use CheckQueryReturnTrait;
23-
2421
protected $primaryKey = 'id';
2522
protected $returnType = User::class;
2623
protected $useSoftDeletes = true;

0 commit comments

Comments
 (0)