Completed
Push — master ( 7d6821...1d6bc5 )
by Dmitry
10:57
created

CartPositionTrait::getRelatedPositions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 0
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * Cart module for Yii2
5
 *
6
 * @link      https://github.com/hiqdev/yii2-cart
7
 * @package   yii2-cart
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\yii2\cart;
13
14
use Yii;
15
use yii\base\Model;
16
use yii\grid\GridView;
17
use yii\helpers\Html;
18
19
/**
20
 * CartPositionTrait trait
21
 * It is intended to be used in classes implementing [[CartPositionInterface]].
22
 * Holds:
23
 * - object (model) and ID.
24
 * - name and description
25
 * Provides:
26
 * - icon with getIcon() to be redefined in childs
27
 */
28
trait CartPositionTrait
29
{
30
    use \yz\shoppingcart\CartPositionTrait;
31
32
    /**
33
     * @var Model object being put in cart
34
     */
35
    protected $_model;
36
37
    /**
38
     * @var string|int ID of object being put in cart
39
     */
40
    protected $_id;
41
42
    public function rules()
43
    {
44
        return [
45
            [['model_id'], 'integer', 'min' => 1],
46
            [['name', 'description', 'parent_id'], 'string'],
47
        ];
48
    }
49
50
    public function attributeLabels()
51
    {
52
        return [
53
            'model_id' => Yii::t('cart', 'ID'),
54
            'name' => Yii::t('cart', 'Name'),
55
            'price' => Yii::t('cart', 'Price'),
56
            'quantity' => Yii::t('cart', 'Quantity'),
57
            'description' => Yii::t('cart', 'Description'),
58
        ];
59
    }
60
61
    public function attributes()
62
    {
63
        return [
64
            'model_id',
65
            'parent_id',
66
            'name',
67
            'quantity',
68
            'description',
69
        ];
70
    }
71
72
    /**
73
     * This closure will be called in [[GridView::rowOptions]].
74
     *
75
     * @param integer $key the key value associated with the current data model
76
     * @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]]
77
     * @param GridView $grid the GridView object
78
     * @return array
79
     */
80
    public function getRowOptions($key, $index, $grid)
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $index is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $grid is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82
        return [];
83
    }
84
85
    public function getIcon()
86
    {
87
        return '<i class="fa fa-check"></i>';
88
    }
89
90
    public function getName()
91
    {
92
        return $this->name;
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
93
    }
94
95
    public function getDescription()
96
    {
97
        return $this->description;
0 ignored issues
show
Bug introduced by
The property description does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
98
    }
99
100
    public function renderDescription()
101
    {
102
        return $this->getIcon() . ' ' . $this->getName() . ' ' . Html::tag('span', $this->getDescription(), ['class' => 'text-muted']);
103
    }
104
105
    public function getAdditionalLinks(): array
106
    {
107
        return [];
108
    }
109
110
    public function getRelatedPositions(): array
111
    {
112
        return [];
113
    }
114
115
    public function hasParent(): bool
116
    {
117
        return !empty($this->parent_id);
0 ignored issues
show
Bug introduced by
The property parent_id does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
118
    }
119
120
    public function getModel()
121
    {
122
        return $this->_model;
123
    }
124
}
125