Permalink
Browse files

Further linting of models

  • Loading branch information...
lovett committed Dec 25, 2018
1 parent ba842e1 commit dfbbade3f0e97e51448ec7a0ea20d3ebebcfa128
Showing with 80 additions and 64 deletions.
  1. +1 −2 app/Http/Requests/EstimateRequest.php
  2. +20 −26 app/Project.php
  3. +54 −34 app/Time.php
  4. +2 −0 phpcs.xml
  5. +3 −2 phpmd.xml
@@ -31,8 +31,7 @@ public function authorize()
*/
public function rules()
{
return [
];
return [];
}
/**
@@ -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.
@@ -91,7 +87,7 @@ class Project extends Model
*/
public function getAllottedTotalHoursAttribute()
{
if (is_null($this->allottedTotalMinutes)) {
if ($this->allottedTotalMinutes === null) {
return null;
}
@@ -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);
}
@@ -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;
}
@@ -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);
}
@@ -163,7 +165,7 @@ public function getBillableStatusAttribute()
*/
public function getTotalTimeRemainingAttribute()
{
if (is_null($this->allottedTotalMinutes)) {
if ($this->allottedTotalMinutes === null) {
return null;
}
@@ -172,7 +174,6 @@ public function getTotalTimeRemainingAttribute()
$remaining = $this->allottedTotalMinutes - $totalTime;
return $remaining;
}
/**
@@ -182,7 +183,7 @@ public function getTotalTimeRemainingAttribute()
*/
public function getWeeklyTimeRemainingAttribute()
{
if (is_null($this->allottedWeeklyMinutes)) {
if ($this->allottedWeeklyMinutes === null) {
return null;
}
@@ -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);
}
@@ -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);
}
@@ -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');
}
}
Oops, something went wrong.

0 comments on commit dfbbade

Please sign in to comment.