Passed
Push — dev5 ( 1140b1...da16e0 )
by Ron
09:38
created

Customers::getChildCountAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\SoftDeletes;
7
8
class Customers extends Model
9
{
10
    use SoftDeletes;
11
12
    protected $primaryKey = 'cust_id';
13
    protected $fillable   = ['cust_id', 'parent_id', 'name', 'dba_name', 'address', 'city', 'state', 'zip', 'active'];
14
    protected $hidden     = ['created_at', 'deleted_at', 'updated_at'];
15
    protected $appends    = ['child_count'];
16
    protected $casts      = [
17
        'deleted_at' => 'datetime:M d, Y',
18
    ];
19
20 16
    public function CustomerSystems()
21
    {
22 16
        return $this->hasMany('App\CustomerSystems', 'cust_id', 'cust_id');
23
    }
24
25 18
    public function getChildCountAttribute()
26
    {
27 18
        return Customers::where('parent_id', $this->cust_id)->count();
0 ignored issues
show
Documentation introduced by
The property cust_id does not exist on object<App\Customers>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
28
    }
29
}
30