Test Failed
Push — master ( 55431f...64d5a8 )
by Jeff
04:55
created

AttributeValueRepository::findProductAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Shop\AttributeValues\Repositories;
4
5
use App\Shop\Attributes\Attribute;
6
use App\Shop\AttributeValues\AttributeValue;
7
use App\Shop\Base\BaseRepository;
8
use Illuminate\Support\Collection;
9
10
class AttributeValueRepository extends BaseRepository implements AttributeValueRepositoryInterface
11
{
12
    /**
13
     * AttributeValueRepository constructor.
14
     * @param AttributeValue $attributeValue
15
     */
16
    public function __construct(AttributeValue $attributeValue)
17
    {
18
        parent::__construct($attributeValue);
19
        $this->model = $attributeValue;
20
    }
21
22
    /**
23
     * @param Attribute $attribute
24
     * @param array $data
25
     * @return AttributeValue
26
     */
27
    public function createAttributeValue(Attribute $attribute, array $data) : AttributeValue
28
    {
29
        $attributeValue = new AttributeValue($data);
30
        $attributeValue->attribute()->associate($attribute);
31
        $attributeValue->save();
32
        return $attributeValue;
33
    }
34
35
    /**
36
     * Create the attribute value and associate to the attribute
37
     *
38
     * @param Attribute $attribute
39
     * @return AttributeValue
40
     */
41
    public function associateToAttribute(Attribute $attribute) : AttributeValue
42
    {
43
        $this->model->attribute()->associate($attribute);
44
        $this->model->save();
45
        return $this->model;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->model returns the type Illuminate\Database\Eloquent\Model which includes types incompatible with the type-hinted return App\Shop\AttributeValues\AttributeValue.
Loading history...
46
    }
47
48
    /**
49
     * Remove association from the attribute
50
     */
51
    public function dissociateFromAttribute() : bool
52
    {
53
        return $this->model->delete();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->model->delete() could return the type null which is incompatible with the type-hinted return boolean. Consider adding an additional type-check to rule them out.
Loading history...
54
    }
55
56
    /**
57
     * @return Collection
58
     */
59
    public function findProductAttributes() : Collection
60
    {
61
        return $this->model->productAttributes()->get();
62
    }
63
}
64