1 | <?php |
||
14 | class FiniteGroup extends Combinatorics implements \Iterator, \Countable |
||
15 | { |
||
16 | /** |
||
17 | * The group size. |
||
18 | * |
||
19 | * @var int |
||
20 | */ |
||
21 | protected $size; |
||
22 | |||
23 | /** |
||
24 | * The group. |
||
25 | * |
||
26 | * @var int[] |
||
27 | */ |
||
28 | protected $group; |
||
29 | |||
30 | /** |
||
31 | * The key. |
||
32 | * |
||
33 | * @var int |
||
34 | */ |
||
35 | protected $key; |
||
36 | |||
37 | /** |
||
38 | * Combinatorics constructor. |
||
39 | */ |
||
40 | 2 | public function __construct() |
|
41 | { |
||
42 | 2 | parent::__construct([], null); |
|
43 | 2 | } |
|
44 | |||
45 | /** |
||
46 | * {@inheritdoc} |
||
47 | */ |
||
48 | 2 | public function current() |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | 2 | public function next() |
|
57 | { |
||
58 | 2 | $this->key++; |
|
59 | 2 | next($this->group); |
|
60 | 2 | } |
|
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | 2 | public function key() |
|
69 | |||
70 | /** |
||
71 | * {@inheritdoc} |
||
72 | */ |
||
73 | 2 | public function valid() |
|
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | 2 | public function rewind() |
|
82 | { |
||
83 | 2 | $this->key = 0; |
|
84 | 2 | } |
|
85 | |||
86 | /** |
||
87 | * Count elements of an object. |
||
88 | * |
||
89 | * @return int |
||
90 | * The number of element. |
||
91 | */ |
||
92 | 2 | public function count() |
|
96 | |||
97 | /** |
||
98 | * Convert the iterator into an array. |
||
99 | * |
||
100 | * @return array |
||
101 | * The elements. |
||
102 | */ |
||
103 | 2 | public function toArray() |
|
113 | |||
114 | /** |
||
115 | * Set the group size. |
||
116 | * |
||
117 | * @param int $size |
||
118 | * The size. |
||
119 | */ |
||
120 | 2 | public function setSize($size) |
|
121 | { |
||
122 | 2 | $this->size = $size; |
|
123 | 2 | $this->computeGroup(); |
|
124 | 2 | } |
|
125 | |||
126 | /** |
||
127 | * Get the group size. |
||
128 | * |
||
129 | * @return int |
||
130 | * The size. |
||
131 | */ |
||
132 | 2 | public function getSize() |
|
136 | |||
137 | /** |
||
138 | * Get the order. |
||
139 | * |
||
140 | * @param int $generator |
||
141 | * The generator. |
||
142 | * |
||
143 | * @return int |
||
144 | * The order. |
||
145 | */ |
||
146 | public function order($generator) |
||
157 | |||
158 | /** |
||
159 | * Clean out the group from unwanted values. |
||
160 | */ |
||
161 | 2 | private function computeGroup() |
|
171 | |||
172 | /** |
||
173 | * Get the greater common divisor between two numbers. |
||
174 | * |
||
175 | * @param int $a |
||
176 | * The first number. |
||
177 | * @param int $b |
||
178 | * The second number. |
||
179 | * |
||
180 | * @return int |
||
181 | * The greater common divisor between $a and $b. |
||
182 | */ |
||
183 | 2 | private function gcd($a, $b) |
|
187 | } |
||
188 |
Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.