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 ( 6b4feb...75ea9f )
by Alexey
18:40 queued 09:49
created

ProductController   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 145
Duplicated Lines 40 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 11.54%

Importance

Changes 0
Metric Value
dl 58
loc 145
ccs 9
cts 78
cp 0.1154
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A actionSection() 19 19 2
A actionType() 19 19 2
A behaviors() 0 12 1
A actionCategories() 0 8 1
A actionCategory() 20 20 2
B actionOne() 0 26 3
A isFirstPage() 0 4 1
B renderPage() 0 25 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
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 frontend.controllers
8
 */
9
10
/**
11
 * Class ProductController
12
 * @mixin ProductTextBehavior
13
 * @mixin ProductFilterBehavior
14
 * @mixin ProductSortingBehavior
15
 */
16
class ProductController extends FController
17
{
18
  public $pageSize = 10;
19
20 15
  public function behaviors()
21
  {
22 15
    return CMap::mergeArray(parent::behaviors(), array(
23 15
      'productTextBehavior' => array('class' => 'backend.modules.product.modules.text.frontend.ProductTextBehavior'),
24 15
      'productFilterBehavior' => array('class' => 'ProductFilterBehavior'),
25
      'productSortingBehavior' => array(
26 15
        'class' => 'ProductSortingBehavior',
27 15
        'defaultSorting' => 'default',
28 15
        'pageSizeRange' => array(20, 40, 60)
29 15
      )
30 15
    ));
31
  }
32
33
  public function actionCategories()
34
  {
35
    $this->breadcrumbs = array('Производители');
36
37
    $categories = ProductCategory::model()->findAll();
38
39
    $this->render('categories', array('categories' => $categories));
40
  }
41
42 View Code Duplication
  public function actionCategory($category)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
  {
44
    /**
45
     * @var ProductCategory $model
46
     */
47
    $model = ProductCategory::model()->findByAttributes(array('url' => $category));
48
49
    if( !$model )
50
      throw new CHttpException(404, 'Страница не найдена');
51
52
    $this->breadcrumbs = array(
53
      'Производители' => $this->createUrl('product/categories'),
54
      $model->name,
55
    );
56
57
    $criteria = new CDbCriteria();
58
    $criteria->compare('a.category_id', $model->id);
59
60
    $this->renderPage(array($model), $criteria);
61
  }
62
63 View Code Duplication
  public function actionSection($section)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
64
  {
65
    /**
66
     * @var ProductSection $model
67
     */
68
    $model = ProductSection::model()->findByAttributes(array('url' => $section));
69
70
    if( !$model )
71
      throw new CHttpException(404, 'Страница не найдена');
72
73
    $this->breadcrumbs = array(
74
      $model->name,
75
    );
76
77
    $criteria = new CDbCriteria();
78
    $criteria->compare('a.section_id', $model->id);
79
80
    $this->renderPage(array($model), $criteria);
81
  }
82
83 View Code Duplication
  public function actionType($type)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
  {
85
    /**
86
     * @var ProductType $model
87
     */
88
    $model = ProductType::model()->findByAttributes(array('url' => $type));
89
90
    if( !$model )
91
      throw new CHttpException(404, 'Страница не найдена');
92
93
    $this->breadcrumbs = array(
94
      $model->name,
95
    );
96
97
    $criteria = new CDbCriteria();
98
    $criteria->compare('a.type_id', $model->id);
99
100
    $this->renderPage(array($model), $criteria);
101
  }
102
103
  public function actionOne($url)
104
  {
105
    /**
106
     * @var Product $model
107
     */
108
    $model = Product::model()->visible()->findByAttributes(array('url' => $url));
109
110
    if( !$model )
111
      throw new CHttpException(404, 'Страница не найдена');
112
113
    $this->breadcrumbs = array(
114
      $model->section->name => array('product/section', 'section' => $model->section->url),
115
      $model->name,
116
    );
117
118
    $data = array(
119
      'model' => $model,
120
      'similarDataProvider' => $model->getSimilarProducts(4),
121
      'relatedDataProvider' => $model->getRelatedProducts(4),
122
    );
123
124
    if( Yii::app()->request->isAjaxRequest )
125
      $this->renderPartial('_details', array('data' => $model));
126
    else
127
      $this->render('one/product', $data);
128
  }
129
130
  public function isFirstPage()
131
  {
132
    return (int)Yii::app()->request->getParam('page', 1) === 1;
133
  }
134
135
  private function renderPage(array $models, CDbCriteria $criteria)
136
  {
137
    Yii::app()->meta->addModels($models);
138
139
    $productList = new ProductList($criteria, $this->getSorting(), true, $this->getFilter());
140
    $dataProvider = $productList->getDataProvider();
141
142
    $this->getFilter()->setSelectedModels($models);
143
144
    $data = array(
145
      'model' => Arr::reset($models),
146
      'dataProvider' => $dataProvider,
147
      'filter' => $this->getFilter(),
148
      'menus' => array()
149
    );
150
151
    if( Yii::app()->request->isAjaxRequest )
152
    {
153
      $this->renderPartial('content', $data);
154
    }
155
    else
156
    {
157
      $this->render('content', $data);
158
    }
159
  }
160
}