Completed
Push — master ( 398d0f...310d56 )
by Pascal
11:17 queued 06:22
created

AttributeModel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createWithName() 0 4 1
A getIdentifier() 0 11 2
1
<?php
2
3
namespace Pbmedia\Specifications\Laravel\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Pbmedia\Specifications\Interfaces\Attribute;
7
use Pbmedia\Specifications\Laravel\Exceptions\AttributeModelNotSavedException;
8
9
class AttributeModel extends Model implements Attribute
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14
    protected $fillable = ['name'];
15
16
    /**
17
     * {@inheritDoc}
18
     */
19
    protected $table = 'specifications_attributes';
20
21
    /**
22
     * Helper method to quickly create a new AttributeModel.
23
     *
24
     * @return \Pbmedia\Specifications\Laravel\Models\AttributeModel
25
     */
26
    public static function createWithName($name)
27
    {
28
        return static::create(compact('name'));
29
    }
30
31
    /**
32
     * Returns the key by which we can identify this model.
33
     *
34
     * @throws \Pbmedia\Specifications\Laravel\Exceptions\AttributeModelNotSavedException
35
     * @return int
36
     */
37
    public function getIdentifier()
38
    {
39
        if (!$this->exists) {
40
            $exception = new AttributeModelNotSavedException;
41
            $exception->setModel($this);
42
43
            throw $exception;
44
        }
45
46
        return $this->getKey();
47
    }
48
}
49