Skip to content

Commit

Permalink
Further linting of models
Browse files Browse the repository at this point in the history
  • Loading branch information
lovett committed Dec 25, 2018
1 parent ba842e1 commit dfbbade
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 64 deletions.
3 changes: 1 addition & 2 deletions app/Http/Requests/EstimateRequest.php
Expand Up @@ -31,8 +31,7 @@ public function authorize()
*/
public function rules()
{
return [
];
return [];
}

/**
Expand Down
46 changes: 20 additions & 26 deletions app/Project.php
Expand Up @@ -24,19 +24,15 @@ class Project extends Model
*
* @var array
*/
public static $searchables = [
'name' => 'projects.name',
];
public static $searchables = ['name' => 'projects.name'];


/**
* When a project is updated, mark its client as updated as well.
*
* @var array
*/
protected $touches = [
'client',
];
protected $touches = ['client'];

/**
* The attributes that are mass-assignable.
Expand Down Expand Up @@ -91,7 +87,7 @@ class Project extends Model
*/
public function getAllottedTotalHoursAttribute()
{
if (is_null($this->allottedTotalMinutes)) {
if ($this->allottedTotalMinutes === null) {
return null;
}

Expand All @@ -103,8 +99,10 @@ public function getAllottedTotalHoursAttribute()
*
* For occasions when it's more convenient to deal with hours
* rather than minutes.
*
* @param float $value The number of hours to be converted to minutes
*/
public function setAllottedTotalHoursAttribute($value)
public function setAllottedTotalHoursAttribute(float $value)
{
$this->attributes['allottedTotalMinutes'] = round($value * 60);
}
Expand All @@ -114,10 +112,12 @@ public function setAllottedTotalHoursAttribute($value)
*
* Although the database stores minutes, sometimes it is more
* convenient to use hours.
*
* @return float Total minutes expressed as hours to 2 decimal places.
*/
public function getAllottedWeeklyHoursAttribute()
{
if (is_null($this->allottedWeeklyMinutes)) {
if ($this->allottedWeeklyMinutes === null) {
return null;
}

Expand All @@ -129,8 +129,10 @@ public function getAllottedWeeklyHoursAttribute()
*
* For occasions when it's more convenient to deal with hours
* rather than minutes.
*
* @param float $value The number of hours to be converted to minutes
*/
public function setAllottedWeeklyHoursAttribute($value)
public function setAllottedWeeklyHoursAttribute(float $value)
{
$this->attributes['allottedWeeklyMinutes'] = round($value * 60);
}
Expand Down Expand Up @@ -163,7 +165,7 @@ public function getBillableStatusAttribute()
*/
public function getTotalTimeRemainingAttribute()
{
if (is_null($this->allottedTotalMinutes)) {
if ($this->allottedTotalMinutes === null) {
return null;
}

Expand All @@ -172,7 +174,6 @@ public function getTotalTimeRemainingAttribute()
$remaining = $this->allottedTotalMinutes - $totalTime;

return $remaining;

}

/**
Expand All @@ -182,7 +183,7 @@ public function getTotalTimeRemainingAttribute()
*/
public function getWeeklyTimeRemainingAttribute()
{
if (is_null($this->allottedWeeklyMinutes)) {
if ($this->allottedWeeklyMinutes === null) {
return null;
}

Expand Down Expand Up @@ -265,9 +266,9 @@ public function invoices()
*
* @param Builder $query An existing query.
*
* @return Builder;
* @return Builder
*/
public function scopeActive($query)
public function scopeActive(Builder $query)
{
return $query->where('active', true);
}
Expand All @@ -277,9 +278,9 @@ public function scopeActive($query)
*
* @param Builder $query An existing query.
*
* @return Builder;
* @return Builder
*/
public function scopeInActive($query)
public function scopeInActive(Builder $query)
{
return $query->where('active', false);
}
Expand All @@ -288,23 +289,16 @@ public function scopeInActive($query)
* Query scope to restrict by recentness
*
* @param Builder $query An existing query.
* @param int $limit If greater than zero, the max number of records to return.
* @param int $limit If greater than zero, the max number of records to return.
*
* @return Builder;
*/
public function scopeNewest($query, $limit=0)
public function scopeNewest(Builder $query, int $limit = 0)
{
$query->orderBy('updated_at', 'DESC');
if ($limit > 0) {
$query->limit($limit);
}
return $query;
}


public function scopeUnbilledTime($query)
{
$query->with('time');
}

}

0 comments on commit dfbbade

Please sign in to comment.