diff --git a/src/CounterCache.php b/src/CounterCache.php index 00fd969..9b0a32b 100644 --- a/src/CounterCache.php +++ b/src/CounterCache.php @@ -1,4 +1,5 @@ * - * @access public * @param \Illuminate\Database\Eloquent\Model $model - * @return boolean + * @return bool * @throws \Nodes\CounterCache\Exceptions\NoCounterCachesFound * @throws \Nodes\CounterCache\Exceptions\NotCounterCacheableException * @throws \Nodes\CounterCache\Exceptions\RelationNotFoundException @@ -33,7 +31,7 @@ class CounterCache { // If model does not implement the CounterCacheable // interface, we'll jump ship and abort. - if (!$model instanceof CounterCacheable) { + if (! $model instanceof CounterCacheable) { Log::error(sprintf('[%s] Model [%s] does not implement CounterCacheable.', __CLASS__, get_class($model))); throw new NotCounterCacheableException(sprintf('Model [%s] does not implement CounterCacheable.', __CLASS__, get_class($model))); } @@ -54,11 +52,11 @@ class CounterCache foreach ((array) $relations as $relationName => $counterCacheConditions) { // Sometimes our counter cache might require additional conditions // which means, we need to support both scenarios - $relationName = !is_array($counterCacheConditions) ? $counterCacheConditions : $relationName; + $relationName = ! is_array($counterCacheConditions) ? $counterCacheConditions : $relationName; // When we've figured out the name of our relation // we'll just make a quick validation, that it actually exists - if (!method_exists($model, $relationName)) { + if (! method_exists($model, $relationName)) { Log::error(sprintf('[%s] Relation [%s] was not found on model [%s]', __CLASS__, $relationName, get_class($model))); throw new RelationNotFoundException(sprintf('Relation [%s] was not found on model [%s]', __CLASS__, $relationName, get_class($model))); } @@ -71,7 +69,7 @@ class CounterCache // If our model's foreign key has been updated, // we need to update the counter cache for the previous value as well - if (!is_null($model->getOriginal($relation->getForeignKey())) && $model->getOriginal($relation->getForeignKey()) != $model->getAttribute($relation->getForeignKey())) { + if (! is_null($model->getOriginal($relation->getForeignKey())) && $model->getOriginal($relation->getForeignKey()) != $model->getAttribute($relation->getForeignKey())) { // Retrieve original foreign key $originalForeignKey = $model->getOriginal($relation->getForeignKey()); @@ -88,13 +86,12 @@ class CounterCache } /** - * Perform counter caching on all entities of model + * Perform counter caching on all entities of model. * * @author Morten Rugaard * - * @access public * @param \Illuminate\Database\Eloquent\Model $model - * @return boolean + * @return bool * @throws \Nodes\CounterCache\Exceptions\NoEntitiesFoundException * @throws \Nodes\CounterCache\Exceptions\NoCounterCachesFound * @throws \Nodes\CounterCache\Exceptions\NotCounterCacheableException @@ -107,7 +104,7 @@ class CounterCache // If no entities found, we'll log the error, // throw an exception and abort. - if (!$entities->isEmpty()) { + if (! $entities->isEmpty()) { Log::error(sprintf('[%s] No entities found of model [%s]', __CLASS__, get_class($model))); throw new NoEntitiesFoundException(sprintf('No entities found of model [%s]', get_class($model))); } @@ -121,17 +118,16 @@ class CounterCache } /** - * Update counter cache column + * Update counter cache column. * * @author Morten Rugaard * - * @access protected * @param \Illuminate\Database\Eloquent\Model $model * @param \Illuminate\Database\Eloquent\Relations\Relation $relation * @param array|null $counterCacheConditions * @param string $foreignKey * @param string $counterCacheColumnName - * @return boolean + * @return bool */ protected function updateCount(IlluminateModel $model, IlluminateRelation $relation, $counterCacheConditions, $foreignKey, $counterCacheColumnName) { @@ -166,21 +162,20 @@ class CounterCache // Fire the update query // to update counter cache column return (bool) $relation->getBaseQuery()->update([ - sprintf('%s.%s', $relationTableName, $counterCacheColumnName) => DB::raw(sprintf('(%s)', vsprintf($countQuerySql, $countQuery->getBindings()))) + sprintf('%s.%s', $relationTableName, $counterCacheColumnName) => DB::raw(sprintf('(%s)', vsprintf($countQuerySql, $countQuery->getBindings()))), ]); } /** - * Prepare value for SQL insertion + * Prepare value for SQL insertion. * * @author Morten Rugaard * - * @access public * @param string $value - * @return integer|string + * @return int|string */ private function prepareValue($value) { return is_numeric($value) ? $value : sprintf('"%s"', $value); } -} \ No newline at end of file +} diff --git a/src/CounterCacheable.php b/src/CounterCacheable.php index f1a0075..f6df7ab 100644 --- a/src/CounterCacheable.php +++ b/src/CounterCacheable.php @@ -1,21 +1,20 @@ * - * @access public * @return array */ public function counterCaches(); -} \ No newline at end of file +} diff --git a/src/Exceptions/CounterCacheException.php b/src/Exceptions/CounterCacheException.php index 003b965..ed4dfc7 100644 --- a/src/Exceptions/CounterCacheException.php +++ b/src/Exceptions/CounterCacheException.php @@ -1,29 +1,27 @@ * - * @access public * @param string $message - * @param integer $code + * @param int $code * @param array $headers - * @param boolean $report + * @param bool $report * @param string $severity */ public function __construct($message = 'Counter cache failed', $code = 500, array $headers = [], $report = true, $severity = 'error') { parent::__construct($message, $code, $headers, $report, $severity); } -} \ No newline at end of file +} diff --git a/src/Exceptions/NoCounterCachesFoundException.php b/src/Exceptions/NoCounterCachesFoundException.php index 00fd608..ab500c5 100644 --- a/src/Exceptions/NoCounterCachesFoundException.php +++ b/src/Exceptions/NoCounterCachesFoundException.php @@ -1,27 +1,25 @@ * - * @access public * @param string $message - * @param integer $code + * @param int $code * @param array $headers - * @param boolean $report + * @param bool $report * @param string $severity */ public function __construct($message = 'No counter caches found on model', $code = 500, array $headers = [], $report = true, $severity = 'error') { parent::__construct($message, $code, $headers, $report, $severity); } -} \ No newline at end of file +} diff --git a/src/Exceptions/NoEntitiesFoundException.php b/src/Exceptions/NoEntitiesFoundException.php index 4f1bb04..8551402 100644 --- a/src/Exceptions/NoEntitiesFoundException.php +++ b/src/Exceptions/NoEntitiesFoundException.php @@ -1,27 +1,25 @@ * - * @access public * @param string $message - * @param integer $code + * @param int $code * @param array $headers - * @param boolean $report + * @param bool $report * @param string $severity */ public function __construct($message = 'No entities found', $code = 500, array $headers = [], $report = true, $severity = 'error') { parent::__construct($message, $code, $headers, $report, $severity); } -} \ No newline at end of file +} diff --git a/src/Exceptions/NotCounterCacheableException.php b/src/Exceptions/NotCounterCacheableException.php index 6762e22..3b7d0e4 100644 --- a/src/Exceptions/NotCounterCacheableException.php +++ b/src/Exceptions/NotCounterCacheableException.php @@ -1,27 +1,25 @@ * - * @access public * @param string $message - * @param integer $code + * @param int $code * @param array $headers - * @param boolean $report + * @param bool $report * @param string $severity */ public function __construct($message = 'Model does not implement CounterCacheable', $code = 500, array $headers = [], $report = true, $severity = 'error') { parent::__construct($message, $code, $headers, $report, $severity); } -} \ No newline at end of file +} diff --git a/src/Exceptions/RelationNotFoundException.php b/src/Exceptions/RelationNotFoundException.php index 5d937f4..372eb76 100644 --- a/src/Exceptions/RelationNotFoundException.php +++ b/src/Exceptions/RelationNotFoundException.php @@ -1,27 +1,25 @@ * - * @access public * @param string $message - * @param integer $code + * @param int $code * @param array $headers - * @param boolean $report + * @param bool $report * @param string $severity */ public function __construct($message = 'Relation not found on model', $code = 500, array $headers = [], $report = true, $severity = 'error') { parent::__construct($message, $code, $headers, $report, $severity); } -} \ No newline at end of file +} diff --git a/src/Traits/CounterCache.php b/src/Traits/CounterCache.php index 324c3cf..1b53daa 100644 --- a/src/Traits/CounterCache.php +++ b/src/Traits/CounterCache.php @@ -1,15 +1,15 @@ * @@ -19,8 +19,8 @@ trait CounterCacheCreated */ public static function bootCounterCacheCreated() { - static::created(function($model) { + static::created(function ($model) { app('Nodes\CounterCache\CounterCache')->count($model); }); } -} \ No newline at end of file +} diff --git a/src/Traits/CounterCacheDeleted.php b/src/Traits/CounterCacheDeleted.php index 9ec4602..2dd369d 100644 --- a/src/Traits/CounterCacheDeleted.php +++ b/src/Traits/CounterCacheDeleted.php @@ -1,16 +1,16 @@ * @@ -19,8 +19,8 @@ trait CounterCacheDeleted */ public static function bootCounterCacheDeleted() { - static::deleted(function($model) { + static::deleted(function ($model) { app('Nodes\CounterCache\CounterCache')->count($model); }); } -} \ No newline at end of file +} diff --git a/src/Traits/CounterCacheRestored.php b/src/Traits/CounterCacheRestored.php index f82f2d7..609d6ec 100644 --- a/src/Traits/CounterCacheRestored.php +++ b/src/Traits/CounterCacheRestored.php @@ -1,16 +1,16 @@ * @@ -25,4 +25,4 @@ trait CounterCacheRestored }); } } -} \ No newline at end of file +} diff --git a/src/Traits/CounterCacheSaved.php b/src/Traits/CounterCacheSaved.php index cca20c6..9dbc3ce 100644 --- a/src/Traits/CounterCacheSaved.php +++ b/src/Traits/CounterCacheSaved.php @@ -1,16 +1,16 @@ * @@ -19,8 +19,8 @@ trait CounterCacheSaved */ public static function bootCounterCacheSaved() { - static::saved(function($model) { + static::saved(function ($model) { app('Nodes\CounterCache\CounterCache')->count($model); }); } -} \ No newline at end of file +} diff --git a/src/Traits/CounterCacheUpdated.php b/src/Traits/CounterCacheUpdated.php index cbae553..87d7fad 100644 --- a/src/Traits/CounterCacheUpdated.php +++ b/src/Traits/CounterCacheUpdated.php @@ -1,16 +1,16 @@ * @@ -19,8 +19,8 @@ trait CounterCacheUpdated */ public static function bootCounterCacheUpdated() { - static::updated(function($model) { + static::updated(function ($model) { app('Nodes\CounterCache\CounterCache')->count($model); }); } -} \ No newline at end of file +}