Skip to content

Commit

Permalink
Added some static typings, minor code tweaks and code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleangioni committed Mar 9, 2019
1 parent 98dd1a5 commit 0fbd02d
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 77 deletions.
2 changes: 0 additions & 2 deletions src/MicheleAngioni/Support/Facades/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

use Illuminate\Support\Facades\Facade;


class Helpers extends Facade
{

protected static function getFacadeAccessor()
{
return 'helpers';
}

}
33 changes: 16 additions & 17 deletions src/MicheleAngioni/Support/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Helpers
* int(4.1), string '1.2', string '0x8', float(1.2) return false.
* min and max allowed values can be inserted
*
* @param int $int
* @param int|null $min
* @param int|null $max
* @param mixed $int
* @param int|null $min
* @param int|null $max
*
* @return bool
*/
Expand Down Expand Up @@ -50,8 +50,7 @@ static public function isInt($int, int $min = null, int $max = null): bool
/**
* Return a random value out of an array
*
* @param array $array
*
* @param array $array
* @return mixed
*/
static public function randInArray(array $array)
Expand All @@ -62,8 +61,8 @@ static public function randInArray(array $array)
/**
* Check date validity. Return true on success or false on failure.
*
* @param string $date
* @param string $format = 'Y-m-d'
* @param string $date
* @param string $format = 'Y-m-d'
*
* @return bool
*/
Expand All @@ -77,8 +76,7 @@ static public function checkDate(string $date, string $format = 'Y-m-d'): bool
/**
* Check datetime 'Y-m-d H:i:s' validity. Returns true if ok or false if it fails.
*
* @param string $datetime
*
* @param string $datetime
* @return bool
*/
static public function checkDatetime(string $datetime): bool
Expand All @@ -91,9 +89,9 @@ static public function checkDatetime(string $datetime): bool
* $firstDate must be < than $secondDate
* Third optional parameter indicates max days difference allowed (0 = no limits).
*
* @param string $firstDate
* @param string $secondDate
* @param int $maxDifference = 0
* @param string $firstDate
* @param string $secondDate
* @param int $maxDifference = 0
*
* @return array
*/
Expand Down Expand Up @@ -141,8 +139,8 @@ static public function splitDates(string $firstDate, string $secondDate, int $ma
* $date2 must be >= than $date1.
* Returns null on failure.
*
* @param string $date1
* @param string $date2
* @param string $date1
* @param string $date2
*
* @return int|null
*/
Expand Down Expand Up @@ -170,9 +168,10 @@ static public function daysBetweenDates(string $date1, string $date2):? int
* Return $quantity UNIQUE random value between $min and $max.
* Return null on failure.
*
* @param int $min = 0
* @param int $max
* @param int $quantity = 1
* @param int $min = 0
* @param int $max
* @param int $quantity = 1
* @throws \Exception
*
* @return int[]|null
*/
Expand Down
99 changes: 56 additions & 43 deletions src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function getBy(array $where = [], array $with = [])
*
* @return Collection
*/
public function getByLimit($limit, array $where = [], array $with = [])
public function getByLimit(int $limit, array $where = [], array $with = [])
{
$query = $this->make($with);

Expand All @@ -172,15 +172,15 @@ public function getByLimit($limit, array $where = [], array $with = [])
* Return the first ordered $limit records querying input parameters.
* $limit = 0 means no limits.
*
* @param $orderBy
* @param string $orderBy
* @param array $where
* @param array $with
* @param string $order
* @param int $limit
*
* @return Collection
*/
public function getByOrder($orderBy, array $where = [], array $with = [], $order = 'desc', $limit = 0)
public function getByOrder(string $orderBy, array $where = [], array $with = [], string $order = 'desc', int $limit = 0)
{
$query = $this->make($with);

Expand Down Expand Up @@ -208,8 +208,14 @@ public function getByOrder($orderBy, array $where = [], array $with = [], $order
*
* @return Collection
*/
public function getIn($whereInKey, array $whereIn = [], $with = [], $orderBy = null, $order = 'desc', $limit = 0)
{
public function getIn(
$whereInKey,
array $whereIn = [],
array $with = [],
string $orderBy = null,
string $order = 'desc',
int $limit = 0
) {
$query = $this->make($with);

$query = $query->whereIn($whereInKey, $whereIn);
Expand Down Expand Up @@ -241,10 +247,10 @@ public function getIn($whereInKey, array $whereIn = [], $with = [], $orderBy = n
public function getNotIn(
$whereNotInKey,
array $whereNotIn = [],
$with = [],
$orderBy = null,
$order = 'desc',
$limit = 0
array $with = [],
string $orderBy = null,
string $order = 'desc',
int $limit = 0
) {
$query = $this->make($with);

Expand All @@ -264,14 +270,14 @@ public function getNotIn(
/**
* Return all results that have a required relationship.
*
* @param string $relation
* @param array $where
* @param array $with
* @param int $hasAtLeast = 1
* @param string $relation
* @param array $where
* @param array $with
* @param int $hasAtLeast = 1
*
* @return Collection
*/
public function getHas($relation, array $where = [], array $with = [], $hasAtLeast = 1)
public function getHas(string $relation, array $where = [], array $with = [], int $hasAtLeast = 1)
{
$query = $this->make($with);

Expand All @@ -284,14 +290,14 @@ public function getHas($relation, array $where = [], array $with = [], $hasAtLea
* Return the first result that has a required relationship.
* Return null if no record is found.
*
* @param string $relation
* @param array $where
* @param array $with
* @param int $hasAtLeast = 1
* @param string $relation
* @param array $where
* @param array $with
* @param int $hasAtLeast = 1
*
* @return Collection
* @return mixed
*/
public function hasFirst($relation, array $where = [], array $with = [], $hasAtLeast = 1)
public function hasFirst(string $relation, array $where = [], array $with = [], int $hasAtLeast = 1)
{
$query = $this->make($with);

Expand All @@ -304,16 +310,16 @@ public function hasFirst($relation, array $where = [], array $with = [], $hasAtL
* Return the first result that have a required relationship.
* Throws exception if no record is found.
*
* @param string $relation
* @param array $where
* @param array $with
* @param int $hasAtLeast = 1
* @param string $relation
* @param array $where
* @param array $with
* @param int $hasAtLeast = 1
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*
* @return Collection
*/
public function hasFirstOrFail($relation, array $where = [], array $with = [], $hasAtLeast = 1)
public function hasFirstOrFail(string $relation, array $where = [], array $with = [], int $hasAtLeast = 1)
{
$query = $this->make($with);

Expand All @@ -325,10 +331,10 @@ public function hasFirstOrFail($relation, array $where = [], array $with = [], $
/**
* Return all results that have a required relationship with input constraints.
*
* @param string $relation
* @param array $where
* @param array $whereHas
* @param array $with
* @param string $relation
* @param array $where
* @param array $whereHas
* @param array $with
*
* @return Collection
*/
Expand All @@ -348,17 +354,23 @@ public function whereHas($relation, array $where = [], array $whereHas = [], arr
/**
* Get ordered results by Page.
*
* @param int $page
* @param int $limit
* @param array $where
* @param array $with
* @param string|null $orderBy
* @param string $order
* @param int $page
* @param int $limit
* @param array $where
* @param array $with
* @param string|null $orderBy
* @param string $order
*
* @return Collection
*/
public function getByPage($page = 1, $limit = 10, array $where = [], $with = [], $orderBy = null, $order = 'desc')
{
public function getByPage(
int $page = 1,
int $limit = 10,
array $where = [],
array $with = [],
string $orderBy = null,
string $order = 'desc'
) {
$query = $this->make($with);

$query = $this->applyWhere($query, $where);
Expand Down Expand Up @@ -556,6 +568,7 @@ public function count()
/**
* Count the number of records matching input parameters.
*
* @param array $where
* @return int
*/
public function countBy(array $where = [])
Expand All @@ -570,9 +583,9 @@ public function countBy(array $where = [])
/**
* Count all records that have a required relationship and matching input parameters..
*
* @param string $relation
* @param array $where
* @param array $whereHas
* @param string $relation
* @param array $where
* @param array $whereHas
*
* @return int
*/
Expand All @@ -596,8 +609,8 @@ public function countWhereHas($relation, array $where = [], array $whereHas = []
* Apply the where clauses to input query.
* $where can have the format ['key' => 'value'] or ['key' => [<operator>, 'value']]
*
* @param Builder $query
* @param array $where
* @param Builder $query
* @param array $where
*
* @return Builder
*/
Expand All @@ -621,7 +634,7 @@ protected function applyWhere(Builder $query, array $where)
/**
* Remove keys from the $inputs array beginning with '_' .
*
* @param array $inputs
* @param array $inputs
*
* @return array
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function __construct()
*
* @return string
*/
public function getFilePath()
public function getFilePath(): string
{
return $this->xmlPath;
}
Expand Down
Loading

0 comments on commit 0fbd02d

Please sign in to comment.