Skip to content

Commit

Permalink
minors
Browse files Browse the repository at this point in the history
phpdoc + pk -> primaryKey +   $data->$var -> $data->{$var}
  • Loading branch information
nowackipawel authored Feb 9, 2019
1 parent 14ee71c commit d31c86c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions system/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class Model
//--------------------------------------------------------------------

/**
* The column used for insert timestampes
* The column used for insert timestamps
*
* @var string
*/
Expand Down Expand Up @@ -487,28 +487,27 @@ public function save($data)
return $response;
}

//--------------------------------------------------------------------

/**
* Takes a class an returns an array of it's public and protected
* properties as an array suitable for use in creates and updates.
*
* @param string|object $data
* @param string $dateFormat
* @param string|null $primaryKey
* @param string $dateFormat
*
* @return array
* @throws \ReflectionException
*/
public static function classToArray($data, $pk = null, string $dateFormat = 'datetime'): array
public static function classToArray($data, $primaryKey = null, string $dateFormat = 'datetime'): array
{
if (method_exists($data, 'toRawArray'))
{
$properties = $data->toRawArray(true);

// Always grab the primary key otherwise updates will fail.
if (! empty($properties) && ! empty($pk) && ! in_array($pk, $properties))
if (! empty($properties) && ! empty($primaryKey) && ! in_array($primaryKey, $properties))
{
$properties[$pk] = $data->$pk;
$properties[$primaryKey] = $data->{$primaryKey};
}
}
else
Expand Down Expand Up @@ -573,14 +572,16 @@ public function getInsertID()

//--------------------------------------------------------------------


/**
* Inserts data into the current table. If an object is provided,
* it will attempt to convert it to an array.
*
* @param array|object $data
* @param boolean $returnID Whether insert ID should be returned or not.
* @param boolean $returnID Whether insert ID should be returned or not.
*
* @return integer|string|boolean
* @throws \ReflectionException
*/
public function insert($data = null, bool $returnID = true)
{
Expand Down Expand Up @@ -698,9 +699,10 @@ public function insertBatch($set = null, $escape = null, $batchSize = 100, $test
* it will attempt to convert it into an array.
*
* @param integer|array|string $id
* @param array|object $data
* @param array|object $data
*
* @return boolean
* @throws \ReflectionException
*/
public function update($id = null, $data = null)
{
Expand Down

0 comments on commit d31c86c

Please sign in to comment.