Completed
Push — master ( 7f5e4e...7d6b52 )
by Klochok
41:12 queued 26:13
created

CartPositionTrait::getAdditionalLinks()   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
ccs 0
cts 1
cp 0
rs 10
c 0
b 0
f 0
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'], '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
            'name',
66
            'quantity',
67
            'description',
68
        ];
69
    }
70
71
    /**
72
     * This closure will be called in [[GridView::rowOptions]].
73
     *
74
     * @param integer $key the key value associated with the current data model
75
     * @param integer $index the zero-based index of the data model in the model array returned by [[dataProvider]]
76
     * @param GridView $grid the GridView object
77
     * @return array
78
     */
79
    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...
80
    {
81
        return [];
82
    }
83
84
    public function getIcon()
85
    {
86
        return '<i class="fa fa-check"></i>';
87
    }
88
89
    public function getName()
90
    {
91
        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...
92
    }
93
94
    public function getDescription()
95
    {
96
        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...
97
    }
98
99
    public function renderDescription()
100
    {
101
        return $this->getIcon() . ' ' . $this->getName() . ' ' . Html::tag('span', $this->getDescription(), ['class' => 'text-muted']);
102
    }
103
104
    public function getAdditionalLinks(): array
105
    {
106
        return [];
107
    }
108
109
    public function getModel()
110
    {
111
        return $this->_model;
112
    }
113
}
114