Skip to content

Commit

Permalink
Fixes IDE errors on Model/BaseModel
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalandan authored Feb 26, 2021
1 parent 3eec96e commit ecb2507
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 106 deletions.
59 changes: 8 additions & 51 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
namespace CodeIgniter;

use Closure;
use CodeIgniter\Database\BaseConnection;
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\Exceptions\DataException;
use CodeIgniter\Exceptions\ModelException;
use CodeIgniter\I18n\Time;
use CodeIgniter\Pager\Pager;
use CodeIgniter\Validation\Validation;
use CodeIgniter\Validation\ValidationInterface;
use Config\Services;
use InvalidArgumentException;
Expand All @@ -44,8 +46,6 @@
*/
abstract class BaseModel
{
// region Properties

/**
* Pager instance.
* Populated after calling $this->paginate()
Expand Down Expand Up @@ -160,7 +160,7 @@ abstract class BaseModel
/**
* Database Connection
*
* @var object
* @var BaseConnection
*/
protected $db;

Expand Down Expand Up @@ -200,7 +200,7 @@ abstract class BaseModel
/**
* Our validator instance.
*
* @var ValidationInterface
* @var Validation
*/
protected $validation;

Expand Down Expand Up @@ -288,10 +288,6 @@ abstract class BaseModel
*/
protected $afterDelete = [];

// endregion

// region Constructor

/**
* BaseModel constructor.
*
Expand All @@ -302,12 +298,12 @@ public function __construct(ValidationInterface $validation = null)
$this->tempReturnType = $this->returnType;
$this->tempUseSoftDeletes = $this->useSoftDeletes;
$this->tempAllowCallbacks = $this->allowCallbacks;
$this->validation = $validation ?? Services::validation(null, false);
}

// endregion
/** @var Validation $validation */
$validation = $validation ?? Services::validation(null, false);

// region Abstract Methods
$this->validation = $validation;
}

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

// endregion

// region CRUD & Finders

/**
* Fetches the row of database
*
Expand Down Expand Up @@ -1101,10 +1093,6 @@ public function errors(bool $forceDB = false)
return $this->doErrors();
}

// endregion

// region Pager

/**
* Works with Pager to get the size and offset parameters.
* Expects a GET variable (?page=2) that specifies the page of results
Expand Down Expand Up @@ -1135,10 +1123,6 @@ public function paginate(int $perPage = null, string $group = 'default', int $pa
return $this->findAll($perPage, $offset);
}

// endregion

// region Allowed Fields

/**
* It could be used when you have to change default or override current allowed fields.
*
Expand Down Expand Up @@ -1204,10 +1188,6 @@ protected function doProtectFields(array $data): array
return $data;
}

// endregion

// region Timestamps

/**
* Sets the date or current date if null value is passed
*
Expand Down Expand Up @@ -1282,10 +1262,6 @@ protected function timeToDate(Time $value)
}
}

// endregion

// region Validation

/**
* Set the value of the skipValidation flag.
*
Expand Down Expand Up @@ -1428,7 +1404,6 @@ public function getValidationRules(array $options = []): array
// or an array of rules.
if (is_string($rules))
{
// @phpstan-ignore-next-line
$rules = $this->validation->loadRuleGroup($rules);
}

Expand Down Expand Up @@ -1483,10 +1458,6 @@ protected function cleanValidationRules(array $rules, array $data = null): array
return $rules;
}

// endregion

// region Callbacks

/**
* Sets $tempAllowCallbacks value so that we can temporarily override
* the setting. Resets after the next method that uses triggers.
Expand Down Expand Up @@ -1545,10 +1516,6 @@ protected function trigger(string $event, array $eventData)
return $eventData;
}

// endregion

// region Utility

/**
* Sets the return type of the results to be as an associative array.
*
Expand Down Expand Up @@ -1698,10 +1665,6 @@ protected function transformDataToArray($data, string $type): array
return $data;
}

// endregion

// region Magic

/**
* Provides the db connection and model's properties.
*
Expand Down Expand Up @@ -1758,10 +1721,6 @@ public function __call(string $name, array $params)
return null;
}

// endregion

// region Deprecated

/**
* Replace any placeholders within the rules with the values that
* match the 'key' of any properties being set. For example, if
Expand Down Expand Up @@ -1822,6 +1781,4 @@ protected function fillPlaceholders(array $rules, array $data): array

return $rules;
}

// endregion
}
60 changes: 5 additions & 55 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@
* - allow intermingling calls to the builder
* - removes the need to use Result object directly in most cases
*
* @property ConnectionInterface $db
*
* @mixin BaseBuilder
*/
class Model extends BaseModel
{
// region Properties

/**
* Name of database table
*
Expand Down Expand Up @@ -93,10 +89,6 @@ class Model extends BaseModel
*/
protected $escape = [];

// endregion

// region Constructor

/**
* Model constructor.
*
Expand All @@ -107,19 +99,11 @@ public function __construct(ConnectionInterface &$db = null, ValidationInterface
{
parent::__construct($validation);

if (is_null($db))
{
$this->db = Database::connect($this->DBGroup);
}
else
{
$this->db = &$db;
}
}

// endregion
/** @var BaseConnection $db */
$db = $db ?? Database::connect($this->DBGroup);

// region Setters
$this->db = &$db;
}

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

// endregion

// region Database Methods

/**
* Fetches the row of database from $this->table with a primary key
* matching $id. This methods works only with dbCalls
Expand Down Expand Up @@ -284,7 +264,6 @@ protected function doInsert(array $data)
}
else
{
// @phpstan-ignore-next-line
$this->insertID = $this->db->insertID();
}
}
Expand Down Expand Up @@ -401,9 +380,7 @@ protected function doDelete($id = null, bool $purge = false)
);
}

// @codeCoverageIgnoreStart
return false;
// @codeCoverageIgnoreEnd
return false; // @codeCoverageIgnore
}

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

// endregion

// region Builder

/**
* Provides a shared instance of the Query Builder.
*
Expand Down Expand Up @@ -652,12 +625,6 @@ public function set($key, ?string $value = '', ?bool $escape = null)
return $this;
}

// endregion

// region Overrides

// region CRUD & Finders

/**
* This method is called on save to determine if entry have to be updated
* If this method return false insert operation will be executed
Expand Down Expand Up @@ -741,10 +708,6 @@ public function update($id = null, $data = null): bool
return parent::update($id, $data);
}

// endregion

// region Utility

/**
* Takes a class an returns an array of it's public and protected
* properties as an array with raw values.
Expand All @@ -771,10 +734,6 @@ protected function objectToRawArray($data, bool $onlyChanged = true, bool $recur
return $properties;
}

// endregion

// region Magic

/**
* Provides/instantiates the builder/db connection and model's table/primary key names and return type.
*
Expand Down Expand Up @@ -851,12 +810,6 @@ public function __call(string $name, array $params)
return $result;
}

// endregion

// endregion

// region Deprecated

/**
* Takes a class an returns an array of it's public and protected
* properties as an array suitable for use in creates and updates.
Expand Down Expand Up @@ -932,7 +885,4 @@ public static function classToArray($data, $primaryKey = null, string $dateForma

return $properties;
}

// endregion

}

0 comments on commit ecb2507

Please sign in to comment.