1 | <?php |
||
14 | class FiniteGroup extends Combinatorics implements \Iterator, \Countable |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * The group size. |
||
19 | * |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $size; |
||
23 | |||
24 | /** |
||
25 | * The group. |
||
26 | * |
||
27 | * @var int[] |
||
28 | */ |
||
29 | protected $group; |
||
30 | |||
31 | /** |
||
32 | * The key. |
||
33 | * |
||
34 | * @var int |
||
35 | */ |
||
36 | protected $key; |
||
37 | |||
38 | /** |
||
39 | * Combinatorics constructor. |
||
40 | */ |
||
41 | 2 | public function __construct() |
|
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | 2 | public function current() |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 2 | public function next() |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 2 | public function key() |
|
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | 2 | public function valid() |
|
78 | |||
79 | /** |
||
80 | * {@inheritdoc} |
||
81 | */ |
||
82 | 2 | public function rewind() |
|
86 | |||
87 | /** |
||
88 | * Count elements of an object. |
||
89 | * |
||
90 | * @return int |
||
91 | * The number of element. |
||
92 | */ |
||
93 | 2 | public function count() |
|
97 | |||
98 | /** |
||
99 | * Convert the iterator into an array. |
||
100 | * |
||
101 | * @return array |
||
102 | * The elements. |
||
103 | */ |
||
104 | 2 | public function toArray() |
|
105 | { |
||
106 | 2 | $data = array(); |
|
107 | |||
108 | 2 | for ($this->rewind(); $this->valid(); $this->next()) { |
|
109 | 2 | $data[] = $this->current(); |
|
110 | } |
||
111 | |||
112 | 2 | return $data; |
|
113 | } |
||
114 | |||
115 | /** |
||
116 | * Set the group size. |
||
117 | * |
||
118 | * @param int $size |
||
119 | * The size. |
||
120 | */ |
||
121 | 2 | public function setSize($size) |
|
126 | |||
127 | /** |
||
128 | * Get the group size. |
||
129 | * |
||
130 | * @return int |
||
131 | * The size. |
||
132 | */ |
||
133 | 2 | public function getSize() |
|
137 | |||
138 | /** |
||
139 | * Clean out the group from unwanted values. |
||
140 | */ |
||
141 | 2 | private function computeGroup() |
|
142 | { |
||
143 | 2 | $this->group = array(); |
|
144 | |||
145 | 2 | foreach (range(1, $this->getSize() - 1) as $number) { |
|
146 | 2 | if ($this->gcd($number, $this->getSize() - 1) == 1) { |
|
147 | 2 | $this->group[] = $number; |
|
148 | } |
||
149 | } |
||
150 | 2 | } |
|
151 | |||
152 | /** |
||
153 | * Get the greater common divisor between two numbers. |
||
154 | * |
||
155 | * @param int $a |
||
156 | * The first number. |
||
157 | * @param int $b |
||
158 | * The second number. |
||
159 | * |
||
160 | * @return int |
||
161 | * The greater common divisor between $a and $b. |
||
162 | */ |
||
163 | 2 | private function gcd($a, $b) |
|
167 | |||
168 | /** |
||
169 | * Get the order. |
||
170 | * |
||
171 | * @param int $generator |
||
172 | * The generator. |
||
173 | * |
||
174 | * @return int |
||
175 | * The order. |
||
176 | */ |
||
177 | public function order($generator) |
||
188 | } |
||
189 |
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.