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 ( 61aacd...05f06e )
by Alexey
18:53
created

RetailCrmDataProvider::getCategories()   C

Complexity

Conditions 7
Paths 3

Size

Total Lines 45
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 45
rs 6.7272
cc 7
eloc 25
nc 3
nop 0
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 14 and the first side effect is on line 9.

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 frontend.models.xml
8
 */
9
Yii::import('ext.retailcrm.components.product.RetailCrmProductList');
10
11
/**
12
 * Class RetailCrmDataProvider
13
 */
14
class RetailCrmDataProvider
15
{
16
  public $catalogStructure = array('section');
17
18
  protected $productCounter;
19
20
  protected $offersIterator;
21
22
  public function __construct(CDbCriteria $criteria)
23
  {
24
    $this->criteria = $criteria;
0 ignored issues
show
Bug introduced by
The property criteria 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...
25
  }
26
27
  /**
28
   * @return array
29
   */
30
  public function getShop()
31
  {
32
    return array(
33
      'name' => 'relax-market.ru',
34
      'company' => 'Relax market',
35
      'url' => 'http://www.relax-market.ru/'
36
    );
37
  }
38
39
  /**
40
   * @return array
41
   */
42
  public function getCategories()
43
  {
44
    $criteria = new CDbCriteria();
45
    $criteria->addCondition('product.parent IS NULL OR product.parent=0');
46
    $criteria->mergeWith($this->criteria);
47
48
    $baseStructureElement = Arr::get($this->catalogStructure, 0);
49
50
    $categories = array();
51
    foreach(ProductAssignment::model()->getAssignments($criteria) as $assignment)
52
    {
53
      if( empty($assignment[$baseStructureElement.'_id']) )
54
        continue;
55
56
      $idElements = array();
57
      foreach($this->catalogStructure as $structureElement)
58
      {
59
        $idIndex = $structureElement.'_id';
60
        $nameIndex = $structureElement.'_name';
61
62
        if( !empty($assignment[$idIndex]) )
63
        {
64
          $idElements[] = $assignment[$idIndex];
65
          $id = implode('_', $idElements);
66
67
          if( !isset($categories[$id]) )
68
          {
69
            $categories[$id] = array(
70
              'id' => $id,
71
              'name' => XmlHelper::escape($assignment[$nameIndex])
72
            );
73
74
            $parentIdElements = $idElements;
75
            array_pop($parentIdElements);
76
            if( !empty($parentIdElements) )
77
            {
78
              $categories[$id]['parent'] = $id = implode('_', $parentIdElements);
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
79
            }
80
          }
81
        }
82
      }
83
    }
84
85
    return $categories;
86
  }
87
88
  public function getOffers()
89
  {
90
    if( is_null($this->offersIterator) )
91
    {
92
      $productList = $this->getProductList();
93
      $this->offersIterator = new OfferIterator($productList->getDataProvider(), 100);
94
      $this->offersIterator->productList = $productList;
95
      $this->offersIterator->buildCategoryCallback = array($this, 'buildCategory');
96
    }
97
98
    return $this->offersIterator;
99
  }
100
101
  public function buildCategory(Product $product)
102
  {
103
    $idElements = array();
104
    foreach($this->catalogStructure as $structureElement)
105
    {
106
      if( !empty($product->{$structureElement}) )
107
        $idElements[] = $product->{$structureElement}->id;
108
    }
109
110
    $categoryIds = array(implode('_', $idElements));
111
112
    return $categoryIds;
113
  }
114
115
  /**
116
   * @return RetailCrmProductList
117
   */
118
  protected function getProductList()
119
  {
120
    $criteria = new CDbCriteria();
121
    $criteria->mergeWith($this->criteria);
122
123
    $productList = new ProductList($criteria, null, false, null);
124
125
    return $productList;
126
  }
127
}