Passed
Push — master ( 023570...3c9f2b )
by Aleksandr
02:49
created

AttributeModel::getStrategy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the eav package.
4
 * @author    Aleksandr Drobotik <[email protected]>
5
 * @copyright 2023 Aleksandr Drobotik
6
 * @license   https://opensource.org/license/mit  The MIT License
7
 */
8
declare(strict_types=1);
9
10
namespace Drobotik\Eav\Model;
11
12
use Drobotik\Eav\Enum\ATTR_TYPE;
13
use Illuminate\Database\Eloquent\Model;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Drobotik\Eav\Model\Model. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
14
use Illuminate\Database\Eloquent\Relations\BelongsTo;
15
use Drobotik\Eav\Enum\_ATTR;
16
use Drobotik\Eav\Enum\_DOMAIN;
17
18
class AttributeModel extends Model
19
{
20
    public function __construct(array $attributes = [])
21
    {
22
        $this->table = _ATTR::table();
23
        $this->primaryKey = _ATTR::ID->column();
24
        $this->fillable = [
25
            _ATTR::NAME->column(),
26
            _ATTR::DOMAIN_ID->column(),
27
            _ATTR::TYPE->column(),
28
            _ATTR::DESCRIPTION->column(),
29
            _ATTR::DEFAULT_VALUE->column(),
30
            _ATTR::SOURCE->column(),
31
            _ATTR::STRATEGY->column()
32
        ];
33
        $this->timestamps = false;
34
        parent::__construct($attributes);
35
    }
36
37 1
    public function getDomainKey()
38
    {
39 1
        return $this->{_ATTR::DOMAIN_ID->column()};
40
    }
41
42 1
    public function setDomainKey(int $key) : self
43
    {
44 1
        $this->{_ATTR::DOMAIN_ID->column()} = $key;
45 1
        return $this;
46
    }
47
48 1
    public function getName()
49
    {
50 1
        return $this->{_ATTR::NAME->column()};
51
    }
52
53 1
    public function setName(string $name) : self
54
    {
55 1
        $this->{_ATTR::NAME->column()} = $name;
56 1
        return $this;
57
    }
58
59 1
    public function getType()
60
    {
61 1
        return $this->{_ATTR::TYPE->column()};
62
    }
63
64 1
    public function setType(string $type) : self
65
    {
66 1
        $this->{_ATTR::TYPE->column()} = $type;
67 1
        return $this;
68
    }
69
70 1
    public function getTypeEnum() : ATTR_TYPE
71
    {
72 1
        return ATTR_TYPE::getCase($this->getType());
73
    }
74
75 1
    public function getDescription()
76
    {
77 1
        return $this->{_ATTR::DESCRIPTION->column()};
78
    }
79
80 1
    public function setDescription(?string $description) : self
81
    {
82 1
        $this->{_ATTR::DESCRIPTION->column()} = $description;
83 1
        return $this;
84
    }
85
86 1
    public function getDefaultValue()
87
    {
88 1
        return $this->{_ATTR::DEFAULT_VALUE->column()};
89
    }
90
91 1
    public function setDefaultValue($value) : self
92
    {
93 1
        $this->{_ATTR::DEFAULT_VALUE->column()} = $value;
94 1
        return $this;
95
    }
96
97 1
    public function getSource()
98
    {
99 1
        return $this->{_ATTR::SOURCE->column()};
100
    }
101
102 1
    public function setSource(?string $source) : self
103
    {
104 1
        $this->{_ATTR::SOURCE->column()} = $source;
105 1
        return $this;
106
    }
107
108 1
    public function getStrategy()
109
    {
110 1
        return $this->{_ATTR::STRATEGY->column()};
111
    }
112
113 1
    public function setStrategy(string $strategy) : self
114
    {
115 1
        $this->{_ATTR::STRATEGY->column()} = $strategy;
116 1
        return $this;
117
    }
118
}
119