Skip to content

Commit

Permalink
Normalize use of attributes property and constructor across all models
Browse files Browse the repository at this point in the history
  • Loading branch information
lovett committed Sep 19, 2019
1 parent 6d5f7ef commit a635f68
Show file tree
Hide file tree
Showing 10 changed files with 26,706 additions and 17,295 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,6 +2,7 @@
._*
.\#*
\#*
.ac-php-conf.json
/build
/node_modules
/public/hot
Expand Down
17 changes: 17 additions & 0 deletions app/Client.php
Expand Up @@ -21,6 +21,13 @@ class Client extends Model
{
use SoftDeletes, Search;

/**
* Default values for newly-created instances.
*
* @var array
*/
protected $attributes = [];

/**
* Fields that can be used for searching.
*
Expand Down Expand Up @@ -126,6 +133,16 @@ function ($join) {
return $builder;
}

/**
* Set instance defaults.
*
* @param array $attributes The key-value array to populate.
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
}

/**
* At-a-glance numbers that summarize a client in various ways.
*/
Expand Down
17 changes: 17 additions & 0 deletions app/Estimate.php
Expand Up @@ -19,6 +19,13 @@ class Estimate extends Model
{
use SoftDeletes, Search;

/**
* Default values for newly-created instances.
*
* @var array
*/
protected $attributes = [];

/**
* Map of states an estimate can be assigned to a human-readable label.
*
Expand Down Expand Up @@ -100,6 +107,16 @@ public static function listing(Builder $builder)
return $builder;
}

/**
* Set instance defaults.
*
* @param array $attributes The key-value array to populate.
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
}

/**
* Users associated with the client.
*
Expand Down
21 changes: 12 additions & 9 deletions app/Invoice.php
Expand Up @@ -226,21 +226,24 @@ public static function listing(Builder $builder)
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$now = new Carbon();

$this->attributes = [
'sent' => $now,
'start' => $now->copy()->subDays(30),
'end' => $now,
'due' => $now->copy()->addDays(30),
'amount' => 0,
];
$this->attributes = array_merge(
$this->attributes,
[
'sent' => $now,
'start' => $now->copy()->subDays(30),
'end' => $now,
'due' => $now->copy()->addDays(30),
'amount' => 0,
],
);

while ($this->due->isWeekend()) {
$this->due = $this->due->addDays(1);
}

parent::__construct($attributes);
}


Expand Down
17 changes: 17 additions & 0 deletions app/Project.php
Expand Up @@ -20,6 +20,13 @@ class Project extends Model
{
use SoftDeletes, Search;

/**
* Default values for newly-created instances.
*
* @var array
*/
protected $attributes = [];

/**
* Fields that can be used for searching.
*
Expand Down Expand Up @@ -100,6 +107,16 @@ class Project extends Model
'lastActive',
];

/**
* Set instance defaults.
*
* @param array $attributes The key-value array to populate.
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
}

/**
* Custom accessor for allottedTotalMinutes specified in hours
*
Expand Down
17 changes: 17 additions & 0 deletions app/Tag.php
Expand Up @@ -10,6 +10,13 @@
class Tag extends Model
{

/**
* Default values for newly-created instances.
*
* @var array
*/
protected $attributes = [];

/**
* This model does not have created_at and updated_at fields.
*
Expand All @@ -24,6 +31,16 @@ class Tag extends Model
*/
protected $fillable = ['name'];

/**
* Set instance defaults.
*
* @param array $attributes The key-value array to populate.
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
}

/**
* Time entries associated with a tag.
*/
Expand Down
26 changes: 22 additions & 4 deletions app/Time.php
Expand Up @@ -29,10 +29,7 @@ class Time extends Model
*
* @var array
*/
protected $attributes = [
'minutes' => 0,
'billable' => true,
];
protected $attributes = [];

/**
* When a time entry is updated, mark its project as updated as well.
Expand Down Expand Up @@ -147,6 +144,27 @@ public static function listing(Builder $builder)
return $builder;
}

/**
* Set instance defaults.
*
* @param array $attributes The key-value array to populate.
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);

$now = new Carbon();

$this->attributes = array_merge(
$this->attributes,
[
'start' => $now,
'minutes' => 0,
'billable' => true,
]
);
}

/**
* Query scope to restrict to in-progress, unfinished records.
*
Expand Down
17 changes: 17 additions & 0 deletions app/User.php
Expand Up @@ -17,6 +17,13 @@ class User extends Authenticatable
{
use Notifiable, AsMenu;

/**
* Default values for newly-created instances.
*
* @var array
*/
protected $attributes = [];

/**
* The database table used by the model.
*
Expand Down Expand Up @@ -55,6 +62,16 @@ class User extends Authenticatable
'updated_at',
];

/**
* Set instance defaults.
*
* @param array $attributes The key-value array to populate.
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
}

/**
* Clients associated with the user.
*
Expand Down

0 comments on commit a635f68

Please sign in to comment.