From e5a3b0e99b834151d5794f7bc571c3aa5c66fe29 Mon Sep 17 00:00:00 2001 From: Awilum Date: Tue, 14 Jul 2020 21:26:17 +0300 Subject: [PATCH] refactor(core): code standard fixes #436 --- src/flextype/Support/Collection.php | 24 +++++++++++++----------- src/flextype/Support/helpers.php | 4 +--- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/flextype/Support/Collection.php b/src/flextype/Support/Collection.php index f74c24bf..3bb88c57 100644 --- a/src/flextype/Support/Collection.php +++ b/src/flextype/Support/Collection.php @@ -13,6 +13,11 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Collections\Expr\Comparison; use Flextype\Component\Arr\Arr; +use function array_merge; +use function array_rand; +use function count; +use function error_reporting; +use const E_NOTICE; class Collection { @@ -103,7 +108,6 @@ class Collection // Flatten a multi-dimensional array with dots. if (Arr::isAssoc($array)) { - $flat_array = []; foreach ($array as $key => $value) { @@ -121,7 +125,6 @@ class Collection // Return return $this; - } public static function collect($array) @@ -149,7 +152,7 @@ class Collection * * @access public */ - public function where($field, $expr, $value) + public function where(string $field, string $expr, $value) { $this->criteria->where(new Comparison($field, $this->expression[$expr], $value)); @@ -187,7 +190,7 @@ class Collection * * @access public */ - public function orWhere($field, $expr, $value) + public function orWhere(string $field, string $expr, $value) { $this->criteria->orWhere(new Comparison($field, $this->expression[$expr], $value)); @@ -222,7 +225,7 @@ class Collection * * @access public */ - public function setFirstResult($firstResult) + public function setFirstResult(?int $firstResult) { $this->criteria->setFirstResult($firstResult); @@ -238,7 +241,7 @@ class Collection * * @access public */ - public function limit($limit) + public function limit(?int $limit) { $this->criteria->setMaxResults($limit); @@ -254,7 +257,7 @@ class Collection */ public function exists() : bool { - return ($this->count() > 0) ? true : false ; + return $this->count() > 0; } /** @@ -276,7 +279,7 @@ class Collection * * @access public */ - public function last() + public function last() : array { return Arr::undot($this->matchCollection()->last()); } @@ -336,7 +339,7 @@ class Collection * * @access public */ - public function random() + public function random() : array { $results = $this->matchCollection()->toArray(); @@ -345,7 +348,6 @@ class Collection $results[array_rand($results)]; } - /** * Extracts a slice of $length elements starting at position $offset from the Collection. * @@ -360,7 +362,7 @@ class Collection * * @access public */ - public function slice(int $offset = 0, int $limit = null) : array + public function slice(int $offset = 0, ?int $limit = null) : array { $results = $this->matchCollection()->slice($offset, $limit); diff --git a/src/flextype/Support/helpers.php b/src/flextype/Support/helpers.php index a8263304..38f10b1f 100644 --- a/src/flextype/Support/helpers.php +++ b/src/flextype/Support/helpers.php @@ -14,10 +14,8 @@ if (! function_exists('collect')) { * Create a collection from the given value. * * @param array $value Items to collect - * - * @return \Flextype\Collection */ - function collect($array) + function collect($array) : \Flextype\Collection { return new Collection($array); }