GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 2ec89f...0b541d )
by Alexey
13:03
created

BProduct   A

Complexity

Total Complexity 29

Size/Duplication

Total Lines 194
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 86.36%

Importance

Changes 0
Metric Value
dl 0
loc 194
ccs 95
cts 110
cp 0.8636
rs 10
c 0
b 0
f 0
wmc 29
lcom 1
cbo 6

13 Methods

Rating   Name   Duplication   Size   Complexity  
B __get() 0 22 4
A __set() 0 9 2
A __isset() 0 9 2
B rules() 0 25 2
A behaviors() 0 16 1
A relations() 0 12 1
A beforeSave() 0 12 3
A getImageTypes() 0 7 1
A getParameterVariants() 0 10 2
A attributeLabels() 0 9 1
C getSearchCriteria() 0 30 8
A getSearchParams() 0 4 1
A getFilteredGridSettings() 0 6 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 44 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @author Sergey Glagolev <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2014 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package backend.modules.product.models
8
 */
9
10 1
Yii::import('backend.modules.product.models.behaviors.*');
11
12
/**
13
 * @method static BProduct model(string $class = __CLASS__)
14
 *
15
 * @property string $id
16
 * @property integer $parent
17
 * @property integer $position
18
 * @property string $url
19
 * @property string $name
20
 * @property string $articul
21
 * @property string $price
22
 * @property string $price_old
23
 * @property string $notice
24
 * @property string $content
25
 *
26
 * @property integer $gift
27
 * @property integer $visible
28
 * @property integer $spec
29
 * @property integer $novelty
30
 * @property integer $discount
31
 * @property integer $main
32
 * @property integer $dump
33
 * @property integer $archive
34
 * @property integer $xml
35
36
 * @property integer $section_id
37
 * @property integer $type_id
38
 * @property integer $category_id
39
 * @property integer $collection_id
40
 *
41
 * @property BProductAssignment $assignment
42
 * @property BAssociation[] $associations
43
 */
44
class BProduct extends BActiveRecord
45
{
46 24
  public function __get($name)
47
  {
48 24
    $fields = BProductAssignment::model()->getFields();
49
50 24
    if( isset($fields[$name]) )
51 24
    {
52 9
      $relation = str_replace('_id', '', $name);
53
54 9
      if( is_array($this->$relation) )
55 9
        $value = CHtml::listData($this->$relation, 'id', 'id');
56
      else if( isset($this->$relation->id) )
57 9
        $value = $this->$relation->id;
58
      else
59 8
        $value = null;
60 9
    }
61
    else
62
    {
63 24
      $value = parent::__get($name);
64
    }
65
66 24
    return $value;
67
  }
68
69 20
  public function __set($name, $value)
70
  {
71 20
    $fields = BProductAssignment::model()->getFields();
72
73 20
    if( isset($fields[$name]) )
74 20
      $this->$name = $value;
75
    else
76 19
      parent::__set($name, $value);
77 20
  }
78
79 10
  public function __isset($name)
80
  {
81 10
    $fields = BProductAssignment::model()->getFields();
82
83 10
    if( isset($fields[$name]) )
84 10
      return true;
85
    else
86 10
      return parent::__isset($name);
87
  }
88
89 24
  public function rules()
90
  {
91
    return array(
92 24
      array('url, name, articul', 'required'),
93 24
      array('url, articul', 'unique'),
94 24
      array('parent, position, visible, spec, novelty, main, dump, discount, archive, xml', 'numerical', 'integerOnly' => true),
95 24
      array('url, name, articul', 'length', 'max' => 255),
96 24
      array('notice, content, video, rating', 'safe'),
97 24
      array('price, price_old', 'numerical'),
98
99 24
      array('price_old', 'filter', 'filter' => function($value) {
100 5
        if( PriceHelper::isEmpty($value) )
101 5
          return null;
102
        return $value;
103 24
      }),
104 24
      array('price_old', 'compare', 'allowEmpty' => true, 'compareAttribute' => 'price', 'operator' => '>'),
105
106 24
      array('url', 'SUriValidator'),
107 24
      array('name, url, articul', 'filter', 'filter' => array(Yii::app()->format, 'trim')),
108 24
      array('url', 'filter', 'filter' => array(Yii::app()->format, 'toLower')),
109
110 24
      array('section_id', 'required', 'except' => BModificationBehavior::SCENARIO_MODIFICATION),
111 24
      array(implode(", ", array_keys(BProductAssignment::model()->getFields())), 'safe'),
112 24
    );
113
  }
114
115 24
  public function behaviors()
116
  {
117
    return array(
118
      'uploadBehavior' => array(
119 24
        'class' => 'UploadBehavior',
120
        'validAttributes' => 'product_img'
121 24
      ),
122
      'facetedSearchBehavior' => array(
123
        'class' => 'BFacetedSearchBehavior'
124 24
      ),
125
      'associatedFilter' => array(
126 24
        'class' => 'AssociatedFilterBehavior',
127 24
      ),
128 24
      'modificationBehavior' => array('class' => 'BModificationBehavior')
129 24
    );
130
  }
131
132 1
  public function relations()
133
  {
134
    return array(
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array('assignment...ugh' => 'assignment')); (array<string,array>) is incompatible with the return type of the parent method BActiveRecord::relations of type array<string,array<*,string>>.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
135 1
      'assignment' => array(self::HAS_MANY, 'BProductAssignment', 'product_id'),
136 1
      'associations' => array(self::HAS_MANY, 'BAssociation', 'src_id', 'on' => 'src="bproduct"'),
137 1
      'products' => array(self::HAS_MANY, 'BProduct', 'dst_id', 'on' => 'dst="product"', 'through' => 'associations'),
138 1
      'section' => array(self::HAS_ONE, 'BProductSection', 'section_id', 'through' => 'assignment'),
139 1
      'category' => array(self::HAS_ONE, 'BProductCategory', 'category_id', 'through' => 'assignment'),
140 1
      'collection' => array(self::HAS_ONE, 'BProductCollection', 'collection_id', 'through' => 'assignment'),
141 1
      'type' => array(self::HAS_ONE, 'BProductType', 'type_id', 'through' => 'assignment'),
142 1
    );
143
  }
144
145 4
  public function beforeSave()
146
  {
147 4
    if( parent::beforeSave() )
148 4
    {
149 4
      if( empty($this->articul) )
150 4
        $this->articul = null;
151
152 4
      return true;
153
    }
154
155
    return false;
156
  }
157
158
  public function getImageTypes()
159
  {
160
    return array(
161
      'main' => 'Основное',
162
      'gallery' => 'Галерея'
163
    );
164
  }
165
166
  public function getParameterVariants($key)
167
  {
168
    $variants  = array();
169
    $parameter = BProductParamName::model()->findByAttributes(array('key' => $key));
170
171
    if( $parameter )
172
      $variants = $parameter->variants;
173
174
    return $variants;
175
  }
176
177 3
  public function attributeLabels()
178
  {
179 3
    return CMap::mergeArray(parent::attributeLabels(), array(
180 3
      'product_img' => 'Изображения',
181 3
      'BProduct' => 'Продукты',
182 3
      'spec' => 'Лидер продаж',
183 3
      'price_raw' => 'Цена',
184 3
    ));
185
  }
186
187
  /**
188
   * @param CDbCriteria $criteria
189
   *
190
   * @return CDbCriteria
191
   */
192 5
  protected function getSearchCriteria(CDbCriteria $criteria)
193
  {
194 5
    $criteria->together = true;
195 5
    $criteria->distinct = true;
196
197 5
    $criteria->with = array('assignment' => [
198 5
      'select' => false,
199 5
    ]);
200
201 5
    foreach($this->getFilteredGridSettings() as $filteredGridSetting)
202
    {
203 5
      if( property_exists($this, $filteredGridSetting->name) || isset($this->getMetaData()->columns[$filteredGridSetting->name]) )
204 5
      {
205 5
        if( $filteredGridSetting->filter == BGridSettings::FILTER_COMPARE )
206 5
        {
207 5
          $criteria->compare('t.'.$filteredGridSetting->name, trim($this->{$filteredGridSetting->name}));
208 5
        }
209
        else if( $filteredGridSetting->filter == BGridSettings::FILTER_CONTAIN )
210
        {
211
          $criteria->compare('t.'.$filteredGridSetting->name, trim($this->{$filteredGridSetting->name}), true);
212
        }
213 5
      }
214 5
    }
215
216 5
    foreach(BProductAssignment::model()->getFields() as $key => $field)
217 5
      if( !is_array($this->$key) )
218 5
        $criteria->compare('assignment.'.$key, $this->$key);
219
220 5
    return $criteria;
221
  }
222
223 5
  protected function getSearchParams()
224
  {
225 5
    return array('sort' => array('defaultOrder' => 't.id ASC'));
226
  }
227
228
  /**
229
   * @return BGridSettings[]
230
   */
231 5
  protected function getFilteredGridSettings()
232
  {
233 5
    Yii::import('backend.modules.settings.models.BGridSettings');
234
235 5
    return BGridSettings::model()->visible()->filter()->findAll();
236
  }
237
}