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 ( 764334...261594 )
by Alexey
33:15
created

Statistics::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @author Sergey Glagolev <[email protected]>
4
 * @link https://github.com/shogodev/argilla/
5
 * @copyright Copyright &copy; 2003-2013 Shogo
6
 * @license http://argilla.ru/LICENSE
7
 * @package frontend.share
8
 */
9
class Statistics
10
{
11
  protected $lengths = array();
12
13
  protected $elements;
14
15
  /**
16
   * @param array $elements
17
   */
18
  public function __construct(array $elements)
19
  {
20
    foreach($elements as $element)
21
      $this->lengths[] = count($element);
22
23
    $this->elements = $elements;
24
  }
25
26
  /**
27
   * Получаем возможные сочетания элементов массива
28
   *
29
   * @return array
30
   */
31
  public function getCombinations()
32
  {
33
    if( empty($this->elements) )
34
      return array();
35
36
    $combinations = array();
37
38
    foreach($this->getCounter() as $i => $combination)
39
    {
40
      foreach($combination as $j => $value)
41
      {
42
        $combinations[$i][] = $this->getElement($j, $value);
43
      }
44
    }
45
46
    return $combinations;
47
  }
48
49
  protected function getElement($i, $j)
50
  {
51
    return $this->elements[array_keys($this->elements)[$i]][$j];
52
  }
53
54
  /**
55
   * @return array
56
   */
57
  protected function getCounter()
58
  {
59
    $counter = array();
60
    $element = array_fill(0, count($this->lengths), 0);
61
62
    for($i = 0; $i < $this->getCounterLimit(); $i++)
63
    {
64
      $combination = $element;
65
66
      for($j = count($this->lengths), $number = $i; $j > 0, $number > 0; $j--, $number = $integer)
67
        list($integer, $combination[$j - 1]) = $this->divQr($number, $this->lengths[$j - 1]);
0 ignored issues
show
Unused Code introduced by
The assignment to $integer is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
68
69
      $counter[] = $combination;
70
    }
71
72
    return $counter;
73
  }
74
75
  /**
76
   * @return integer
77
   */
78
  protected function getCounterLimit()
79
  {
80
    $limit = 1;
81
82
    foreach($this->lengths as $length)
83
      $limit *= $length;
84
85
    return $limit;
86
  }
87
88
  /**
89
   * Получение частного и остатка от деления
90
   *
91
   * @param integer $n
92
   * @param integer $d
93
   *
94
   * @return array
95
   */
96
  protected function divQr($n, $d)
97
  {
98
    return array(intval($n / $d), $n % $d);
99
  }
100
}