16
16
use CodeIgniter \Database \BaseResult ;
17
17
use CodeIgniter \Database \Exceptions \DatabaseException ;
18
18
use CodeIgniter \Database \Exceptions \DataException ;
19
+ use CodeIgniter \Database \Query ;
19
20
use CodeIgniter \Exceptions \ModelException ;
20
21
use CodeIgniter \I18n \Time ;
21
22
use CodeIgniter \Pager \Pager ;
@@ -311,8 +312,8 @@ protected function initialize()
311
312
}
312
313
313
314
/**
314
- * Fetches the row of database
315
- * This methods works only with dbCalls
315
+ * Fetches the row of database.
316
+ * This method works only with dbCalls.
316
317
*
317
318
* @param bool $singleton Single or multiple results
318
319
* @param array|int|string|null $id One primary key or an array of primary keys
@@ -322,8 +323,8 @@ protected function initialize()
322
323
abstract protected function doFind (bool $ singleton , $ id = null );
323
324
324
325
/**
325
- * Fetches the column of database
326
- * This methods works only with dbCalls
326
+ * Fetches the column of database.
327
+ * This method works only with dbCalls.
327
328
*
328
329
* @param string $columnName Column Name
329
330
*
@@ -335,7 +336,7 @@ abstract protected function doFindColumn(string $columnName);
335
336
336
337
/**
337
338
* Fetches all results, while optionally limiting them.
338
- * This methods works only with dbCalls
339
+ * This method works only with dbCalls.
339
340
*
340
341
* @param int $limit Limit
341
342
* @param int $offset Offset
@@ -346,15 +347,15 @@ abstract protected function doFindAll(int $limit = 0, int $offset = 0);
346
347
347
348
/**
348
349
* Returns the first row of the result set.
349
- * This methods works only with dbCalls
350
+ * This method works only with dbCalls.
350
351
*
351
352
* @return array|object|null
352
353
*/
353
354
abstract protected function doFirst ();
354
355
355
356
/**
356
- * Inserts data into the current database
357
- * This method works only with dbCalls
357
+ * Inserts data into the current database.
358
+ * This method works only with dbCalls.
358
359
*
359
360
* @param array $data Data
360
361
*
@@ -364,7 +365,7 @@ abstract protected function doInsert(array $data);
364
365
365
366
/**
366
367
* Compiles batch insert and runs the queries, validating each row prior.
367
- * This methods works only with dbCalls
368
+ * This method works only with dbCalls.
368
369
*
369
370
* @param array|null $set An associative array of insert values
370
371
* @param bool|null $escape Whether to escape values
@@ -377,31 +378,31 @@ abstract protected function doInsertBatch(?array $set = null, ?bool $escape = nu
377
378
378
379
/**
379
380
* Updates a single record in the database.
380
- * This methods works only with dbCalls
381
+ * This method works only with dbCalls.
381
382
*
382
383
* @param array|int|string|null $id ID
383
384
* @param array|null $data Data
384
385
*/
385
386
abstract protected function doUpdate ($ id = null , $ data = null ): bool ;
386
387
387
388
/**
388
- * Compiles an update and runs the query
389
- * This methods works only with dbCalls
389
+ * Compiles an update and runs the query.
390
+ * This method works only with dbCalls.
390
391
*
391
392
* @param array|null $set An associative array of update values
392
393
* @param string|null $index The where key
393
394
* @param int $batchSize The size of the batch to run
394
395
* @param bool $returnSQL True means SQL is returned, false will execute the query
395
396
*
396
- * @return mixed Number of rows affected or FALSE on failure
397
+ * @return false|int|string[] Number of rows affected or FALSE on failure, SQL array when testMode
397
398
*
398
399
* @throws DatabaseException
399
400
*/
400
401
abstract protected function doUpdateBatch (?array $ set = null , ?string $ index = null , int $ batchSize = 100 , bool $ returnSQL = false );
401
402
402
403
/**
403
- * Deletes a single record from the database where $id matches
404
- * This methods works only with dbCalls
404
+ * Deletes a single record from the database where $id matches.
405
+ * This method works only with dbCalls.
405
406
*
406
407
* @param array|int|string|null $id The rows primary key(s)
407
408
* @param bool $purge Allows overriding the soft deletes setting.
@@ -413,9 +414,9 @@ abstract protected function doUpdateBatch(?array $set = null, ?string $index = n
413
414
abstract protected function doDelete ($ id = null , bool $ purge = false );
414
415
415
416
/**
416
- * Permanently deletes all rows that have been marked as deleted
417
- * through soft deletes (deleted = 1)
418
- * This methods works only with dbCalls
417
+ * Permanently deletes all rows that have been marked as deleted.
418
+ * through soft deletes (deleted = 1).
419
+ * This method works only with dbCalls.
419
420
*
420
421
* @return bool|string Returns a string if in test mode.
421
422
*/
@@ -424,31 +425,31 @@ abstract protected function doPurgeDeleted();
424
425
/**
425
426
* Works with the find* methods to return only the rows that
426
427
* have been deleted.
427
- * This methods works only with dbCalls
428
+ * This method works only with dbCalls.
428
429
*/
429
430
abstract protected function doOnlyDeleted ();
430
431
431
432
/**
432
- * Compiles a replace and runs the query
433
- * This methods works only with dbCalls
433
+ * Compiles a replace and runs the query.
434
+ * This method works only with dbCalls.
434
435
*
435
436
* @param array|null $data Data
436
437
* @param bool $returnSQL Set to true to return Query String
437
438
*
438
- * @return mixed
439
+ * @return BaseResult|false|Query|string
439
440
*/
440
441
abstract protected function doReplace (?array $ data = null , bool $ returnSQL = false );
441
442
442
443
/**
443
444
* Grabs the last error(s) that occurred from the Database connection.
444
- * This methods works only with dbCalls
445
+ * This method works only with dbCalls.
445
446
*
446
447
* @return array|null
447
448
*/
448
449
abstract protected function doErrors ();
449
450
450
451
/**
451
- * Returns the id value for the data array or object
452
+ * Returns the id value for the data array or object.
452
453
*
453
454
* @param array|object $data Data
454
455
*
@@ -459,8 +460,8 @@ abstract protected function doErrors();
459
460
abstract protected function idValue ($ data );
460
461
461
462
/**
462
- * Public getter to return the id value using the idValue() method
463
- * For example with SQL this will return $data->$this->primaryKey
463
+ * Public getter to return the id value using the idValue() method.
464
+ * For example with SQL this will return $data->$this->primaryKey.
464
465
*
465
466
* @param array|object $data
466
467
*
@@ -475,18 +476,18 @@ public function getIdValue($data)
475
476
476
477
/**
477
478
* Override countAllResults to account for soft deleted accounts.
478
- * This methods works only with dbCalls
479
+ * This method works only with dbCalls.
479
480
*
480
481
* @param bool $reset Reset
481
482
* @param bool $test Test
482
483
*
483
- * @return mixed
484
+ * @return int|string
484
485
*/
485
486
abstract public function countAllResults (bool $ reset = true , bool $ test = false );
486
487
487
488
/**
488
489
* Loops over records in batches, allowing you to operate on them.
489
- * This methods works only with dbCalls
490
+ * This method works only with dbCalls.
490
491
*
491
492
* @param int $size Size
492
493
* @param Closure $userFunc Callback Function
@@ -496,7 +497,7 @@ abstract public function countAllResults(bool $reset = true, bool $test = false)
496
497
abstract public function chunk (int $ size , Closure $ userFunc );
497
498
498
499
/**
499
- * Fetches the row of database
500
+ * Fetches the row of database.
500
501
*
501
502
* @param array|int|string|null $id One primary key or an array of primary keys
502
503
*
@@ -538,7 +539,7 @@ public function find($id = null)
538
539
}
539
540
540
541
/**
541
- * Fetches the column of database
542
+ * Fetches the column of database.
542
543
*
543
544
* @param string $columnName Column Name
544
545
*
@@ -667,8 +668,8 @@ public function save($data): bool
667
668
}
668
669
669
670
/**
670
- * This method is called on save to determine if entry have to be updated
671
- * If this method return false insert operation will be executed
671
+ * This method is called on save to determine if entry have to be updated.
672
+ * If this method returns false insert operation will be executed
672
673
*
673
674
* @param array|object $data Data
674
675
*/
@@ -719,7 +720,7 @@ public function insert($data = null, bool $returnID = true)
719
720
// Restore $cleanValidationRules
720
721
$ this ->cleanValidationRules = $ cleanValidationRules ;
721
722
722
- // Must be called first so we don't
723
+ // Must be called first, so we don't
723
724
// strip out created_at values.
724
725
$ data = $ this ->doProtectFields ($ data );
725
726
@@ -896,14 +897,14 @@ public function update($id = null, $data = null): bool
896
897
}
897
898
898
899
/**
899
- * Compiles an update and runs the query
900
+ * Compiles an update and runs the query.
900
901
*
901
902
* @param array|null $set An associative array of update values
902
903
* @param string|null $index The where key
903
904
* @param int $batchSize The size of the batch to run
904
905
* @param bool $returnSQL True means SQL is returned, false will execute the query
905
906
*
906
- * @return mixed Number of rows affected or FALSE on failure
907
+ * @return false|int|string[] Number of rows affected or FALSE on failure, SQL array when testMode
907
908
*
908
909
* @throws DatabaseException
909
910
* @throws ReflectionException
@@ -953,7 +954,7 @@ public function updateBatch(?array $set = null, ?string $index = null, int $batc
953
954
}
954
955
955
956
/**
956
- * Deletes a single record from the database where $id matches
957
+ * Deletes a single record from the database where $id matches.
957
958
*
958
959
* @param array|int|string|null $id The rows primary key(s)
959
960
* @param bool $purge Allows overriding the soft deletes setting.
@@ -995,9 +996,9 @@ public function delete($id = null, bool $purge = false)
995
996
996
997
/**
997
998
* Permanently deletes all rows that have been marked as deleted
998
- * through soft deletes (deleted = 1)
999
+ * through soft deletes (deleted = 1).
999
1000
*
1000
- * @return mixed
1001
+ * @return bool|string Returns a string if in test mode.
1001
1002
*/
1002
1003
public function purgeDeleted ()
1003
1004
{
@@ -1038,12 +1039,12 @@ public function onlyDeleted()
1038
1039
}
1039
1040
1040
1041
/**
1041
- * Compiles a replace and runs the query
1042
+ * Compiles a replace and runs the query.
1042
1043
*
1043
1044
* @param array|null $data Data
1044
1045
* @param bool $returnSQL Set to true to return Query String
1045
1046
*
1046
- * @return mixed
1047
+ * @return BaseResult|false|Query|string
1047
1048
*/
1048
1049
public function replace (?array $ data = null , bool $ returnSQL = false )
1049
1050
{
@@ -1063,6 +1064,7 @@ public function replace(?array $data = null, bool $returnSQL = false)
1063
1064
* Grabs the last error(s) that occurred. If data was validated,
1064
1065
* it will first check for errors there, otherwise will try to
1065
1066
* grab the last error from the Database connection.
1067
+ *
1066
1068
* The return array should be in the following format:
1067
1069
* ['source' => 'message']
1068
1070
*
@@ -1170,11 +1172,11 @@ protected function doProtectFields(array $data): array
1170
1172
}
1171
1173
1172
1174
/**
1173
- * Sets the date or current date if null value is passed
1175
+ * Sets the date or current date if null value is passed.
1174
1176
*
1175
1177
* @param int|null $userData An optional PHP timestamp to be converted.
1176
1178
*
1177
- * @return mixed
1179
+ * @return int|string
1178
1180
*
1179
1181
* @throws ModelException
1180
1182
*/
@@ -1220,7 +1222,7 @@ protected function intToDate(int $value)
1220
1222
}
1221
1223
1222
1224
/**
1223
- * Converts Time value to string using $this->dateFormat
1225
+ * Converts Time value to string using $this->dateFormat.
1224
1226
*
1225
1227
* The available time formats are:
1226
1228
* - 'int' - Stores the date as an integer timestamp
@@ -1397,7 +1399,7 @@ public function getValidationRules(array $options = []): array
1397
1399
}
1398
1400
1399
1401
/**
1400
- * Returns the model's define validation messages so they
1402
+ * Returns the model's validation messages, so they
1401
1403
* can be used elsewhere, if needed.
1402
1404
*/
1403
1405
public function getValidationMessages (): array
@@ -1454,14 +1456,14 @@ public function allowCallbacks(bool $val = true)
1454
1456
*
1455
1457
* Each $eventData array MUST have a 'data' key with the relevant
1456
1458
* data for callback methods (like an array of key/value pairs to insert
1457
- * or update, an array of results, etc)
1459
+ * or update, an array of results, etc. )
1458
1460
*
1459
1461
* If callbacks are not allowed then returns $eventData immediately.
1460
1462
*
1461
1463
* @param string $event Event
1462
1464
* @param array $eventData Event Data
1463
1465
*
1464
- * @return mixed
1466
+ * @return array
1465
1467
*
1466
1468
* @throws DataException
1467
1469
*/
@@ -1513,14 +1515,14 @@ public function asObject(string $class = 'object')
1513
1515
}
1514
1516
1515
1517
/**
1516
- * Takes a class and returns an array of it's public and protected
1518
+ * Takes a class and returns an array of its public and protected
1517
1519
* properties as an array suitable for use in creates and updates.
1518
1520
* This method uses objectToRawArray() internally and does conversion
1519
1521
* to string on all Time instances
1520
1522
*
1521
1523
* @param object|string $data Data
1522
1524
* @param bool $onlyChanged Only Changed Property
1523
- * @param bool $recursive If true, inner entities will be casted as array as well
1525
+ * @param bool $recursive If true, inner entities will be cast as array as well
1524
1526
*
1525
1527
* @return array Array
1526
1528
*
@@ -1579,7 +1581,7 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
1579
1581
}
1580
1582
1581
1583
/**
1582
- * Transform data to array
1584
+ * Transform data to array.
1583
1585
*
1584
1586
* @param array|object|null $data Data
1585
1587
* @param string $type Type of data (insert|update)
0 commit comments