Skip to content

Commit ecb2507

Browse files
authored
Fixes IDE errors on Model/BaseModel
1 parent 3eec96e commit ecb2507

File tree

2 files changed

+13
-106
lines changed

2 files changed

+13
-106
lines changed

system/BaseModel.php

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
namespace CodeIgniter;
1313

1414
use Closure;
15+
use CodeIgniter\Database\BaseConnection;
1516
use CodeIgniter\Database\BaseResult;
1617
use CodeIgniter\Database\Exceptions\DatabaseException;
1718
use CodeIgniter\Database\Exceptions\DataException;
1819
use CodeIgniter\Exceptions\ModelException;
1920
use CodeIgniter\I18n\Time;
2021
use CodeIgniter\Pager\Pager;
22+
use CodeIgniter\Validation\Validation;
2123
use CodeIgniter\Validation\ValidationInterface;
2224
use Config\Services;
2325
use InvalidArgumentException;
@@ -44,8 +46,6 @@
4446
*/
4547
abstract class BaseModel
4648
{
47-
// region Properties
48-
4949
/**
5050
* Pager instance.
5151
* Populated after calling $this->paginate()
@@ -160,7 +160,7 @@ abstract class BaseModel
160160
/**
161161
* Database Connection
162162
*
163-
* @var object
163+
* @var BaseConnection
164164
*/
165165
protected $db;
166166

@@ -200,7 +200,7 @@ abstract class BaseModel
200200
/**
201201
* Our validator instance.
202202
*
203-
* @var ValidationInterface
203+
* @var Validation
204204
*/
205205
protected $validation;
206206

@@ -288,10 +288,6 @@ abstract class BaseModel
288288
*/
289289
protected $afterDelete = [];
290290

291-
// endregion
292-
293-
// region Constructor
294-
295291
/**
296292
* BaseModel constructor.
297293
*
@@ -302,12 +298,12 @@ public function __construct(ValidationInterface $validation = null)
302298
$this->tempReturnType = $this->returnType;
303299
$this->tempUseSoftDeletes = $this->useSoftDeletes;
304300
$this->tempAllowCallbacks = $this->allowCallbacks;
305-
$this->validation = $validation ?? Services::validation(null, false);
306-
}
307301

308-
// endregion
302+
/** @var Validation $validation */
303+
$validation = $validation ?? Services::validation(null, false);
309304

310-
// region Abstract Methods
305+
$this->validation = $validation;
306+
}
311307

312308
/**
313309
* Fetches the row of database
@@ -483,10 +479,6 @@ abstract public function countAllResults(bool $reset = true, bool $test = false)
483479
*/
484480
abstract public function chunk(int $size, Closure $userFunc);
485481

486-
// endregion
487-
488-
// region CRUD & Finders
489-
490482
/**
491483
* Fetches the row of database
492484
*
@@ -1101,10 +1093,6 @@ public function errors(bool $forceDB = false)
11011093
return $this->doErrors();
11021094
}
11031095

1104-
// endregion
1105-
1106-
// region Pager
1107-
11081096
/**
11091097
* Works with Pager to get the size and offset parameters.
11101098
* Expects a GET variable (?page=2) that specifies the page of results
@@ -1135,10 +1123,6 @@ public function paginate(int $perPage = null, string $group = 'default', int $pa
11351123
return $this->findAll($perPage, $offset);
11361124
}
11371125

1138-
// endregion
1139-
1140-
// region Allowed Fields
1141-
11421126
/**
11431127
* It could be used when you have to change default or override current allowed fields.
11441128
*
@@ -1204,10 +1188,6 @@ protected function doProtectFields(array $data): array
12041188
return $data;
12051189
}
12061190

1207-
// endregion
1208-
1209-
// region Timestamps
1210-
12111191
/**
12121192
* Sets the date or current date if null value is passed
12131193
*
@@ -1282,10 +1262,6 @@ protected function timeToDate(Time $value)
12821262
}
12831263
}
12841264

1285-
// endregion
1286-
1287-
// region Validation
1288-
12891265
/**
12901266
* Set the value of the skipValidation flag.
12911267
*
@@ -1428,7 +1404,6 @@ public function getValidationRules(array $options = []): array
14281404
// or an array of rules.
14291405
if (is_string($rules))
14301406
{
1431-
// @phpstan-ignore-next-line
14321407
$rules = $this->validation->loadRuleGroup($rules);
14331408
}
14341409

@@ -1483,10 +1458,6 @@ protected function cleanValidationRules(array $rules, array $data = null): array
14831458
return $rules;
14841459
}
14851460

1486-
// endregion
1487-
1488-
// region Callbacks
1489-
14901461
/**
14911462
* Sets $tempAllowCallbacks value so that we can temporarily override
14921463
* the setting. Resets after the next method that uses triggers.
@@ -1545,10 +1516,6 @@ protected function trigger(string $event, array $eventData)
15451516
return $eventData;
15461517
}
15471518

1548-
// endregion
1549-
1550-
// region Utility
1551-
15521519
/**
15531520
* Sets the return type of the results to be as an associative array.
15541521
*
@@ -1698,10 +1665,6 @@ protected function transformDataToArray($data, string $type): array
16981665
return $data;
16991666
}
17001667

1701-
// endregion
1702-
1703-
// region Magic
1704-
17051668
/**
17061669
* Provides the db connection and model's properties.
17071670
*
@@ -1758,10 +1721,6 @@ public function __call(string $name, array $params)
17581721
return null;
17591722
}
17601723

1761-
// endregion
1762-
1763-
// region Deprecated
1764-
17651724
/**
17661725
* Replace any placeholders within the rules with the values that
17671726
* match the 'key' of any properties being set. For example, if
@@ -1822,6 +1781,4 @@ protected function fillPlaceholders(array $rules, array $data): array
18221781

18231782
return $rules;
18241783
}
1825-
1826-
// endregion
18271784
}

system/Model.php

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,10 @@
4040
* - allow intermingling calls to the builder
4141
* - removes the need to use Result object directly in most cases
4242
*
43-
* @property ConnectionInterface $db
44-
*
4543
* @mixin BaseBuilder
4644
*/
4745
class Model extends BaseModel
4846
{
49-
// region Properties
50-
5147
/**
5248
* Name of database table
5349
*
@@ -93,10 +89,6 @@ class Model extends BaseModel
9389
*/
9490
protected $escape = [];
9591

96-
// endregion
97-
98-
// region Constructor
99-
10092
/**
10193
* Model constructor.
10294
*
@@ -107,19 +99,11 @@ public function __construct(ConnectionInterface &$db = null, ValidationInterface
10799
{
108100
parent::__construct($validation);
109101

110-
if (is_null($db))
111-
{
112-
$this->db = Database::connect($this->DBGroup);
113-
}
114-
else
115-
{
116-
$this->db = &$db;
117-
}
118-
}
119-
120-
// endregion
102+
/** @var BaseConnection $db */
103+
$db = $db ?? Database::connect($this->DBGroup);
121104

122-
// region Setters
105+
$this->db = &$db;
106+
}
123107

124108
/**
125109
* Specify the table associated with a model
@@ -135,10 +119,6 @@ public function setTable(string $table)
135119
return $this;
136120
}
137121

138-
// endregion
139-
140-
// region Database Methods
141-
142122
/**
143123
* Fetches the row of database from $this->table with a primary key
144124
* matching $id. This methods works only with dbCalls
@@ -284,7 +264,6 @@ protected function doInsert(array $data)
284264
}
285265
else
286266
{
287-
// @phpstan-ignore-next-line
288267
$this->insertID = $this->db->insertID();
289268
}
290269
}
@@ -401,9 +380,7 @@ protected function doDelete($id = null, bool $purge = false)
401380
);
402381
}
403382

404-
// @codeCoverageIgnoreStart
405-
return false;
406-
// @codeCoverageIgnoreEnd
383+
return false; // @codeCoverageIgnore
407384
}
408385

409386
$set[$this->deletedField] = $this->setDate();
@@ -574,10 +551,6 @@ public function countAllResults(bool $reset = true, bool $test = false)
574551
return $this->builder()->testMode($test)->countAllResults($reset);
575552
}
576553

577-
// endregion
578-
579-
// region Builder
580-
581554
/**
582555
* Provides a shared instance of the Query Builder.
583556
*
@@ -652,12 +625,6 @@ public function set($key, ?string $value = '', ?bool $escape = null)
652625
return $this;
653626
}
654627

655-
// endregion
656-
657-
// region Overrides
658-
659-
// region CRUD & Finders
660-
661628
/**
662629
* This method is called on save to determine if entry have to be updated
663630
* If this method return false insert operation will be executed
@@ -741,10 +708,6 @@ public function update($id = null, $data = null): bool
741708
return parent::update($id, $data);
742709
}
743710

744-
// endregion
745-
746-
// region Utility
747-
748711
/**
749712
* Takes a class an returns an array of it's public and protected
750713
* properties as an array with raw values.
@@ -771,10 +734,6 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
771734
return $properties;
772735
}
773736

774-
// endregion
775-
776-
// region Magic
777-
778737
/**
779738
* Provides/instantiates the builder/db connection and model's table/primary key names and return type.
780739
*
@@ -851,12 +810,6 @@ public function __call(string $name, array $params)
851810
return $result;
852811
}
853812

854-
// endregion
855-
856-
// endregion
857-
858-
// region Deprecated
859-
860813
/**
861814
* Takes a class an returns an array of it's public and protected
862815
* properties as an array suitable for use in creates and updates.
@@ -932,7 +885,4 @@ public static function classToArray($data, $primaryKey = null, string $dateForma
932885

933886
return $properties;
934887
}
935-
936-
// endregion
937-
938888
}

0 commit comments

Comments
 (0)