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 | * {@inheritdoc} |
||
39 | */ |
||
40 | 2 | public function current() { |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 2 | public function next() { |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 2 | public function key() { |
|
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 2 | public function valid() { |
|
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | 2 | public function rewind() { |
|
72 | |||
73 | /** |
||
74 | * Count elements of an object. |
||
75 | * |
||
76 | * @return int |
||
77 | * The number of element. |
||
78 | */ |
||
79 | 2 | public function count() { |
|
82 | |||
83 | /** |
||
84 | * Convert the iterator into an array. |
||
85 | * |
||
86 | * @return array |
||
87 | * The elements. |
||
88 | */ |
||
89 | 2 | public function toArray() { |
|
90 | 2 | $data = array(); |
|
91 | |||
92 | 2 | for ($this->rewind(); $this->valid(); $this->next()) { |
|
93 | 2 | $data[] = $this->current(); |
|
94 | } |
||
95 | |||
96 | 2 | return $data; |
|
97 | } |
||
98 | |||
99 | /** |
||
100 | * Set the group size. |
||
101 | * |
||
102 | * @param int $size |
||
103 | * The size. |
||
104 | */ |
||
105 | 2 | public function setSize($size) { |
|
109 | |||
110 | /** |
||
111 | * Get the group size. |
||
112 | * |
||
113 | * @return int |
||
114 | * The size. |
||
115 | */ |
||
116 | 2 | public function getSize() { |
|
119 | |||
120 | /** |
||
121 | * Clean out the group from unwanted values. |
||
122 | */ |
||
123 | 2 | private function computeGroup() { |
|
124 | 2 | $this->group = array(); |
|
125 | |||
126 | 2 | foreach (range(1, $this->getSize() - 1) as $number) { |
|
127 | 2 | if ($this->gcd($number, $this->getSize() - 1) == 1) { |
|
128 | 2 | $this->group[] = $number; |
|
129 | } |
||
130 | } |
||
131 | 2 | } |
|
132 | |||
133 | /** |
||
134 | * Get the greater common divisor between two numbers. |
||
135 | * |
||
136 | * @param int $a |
||
137 | * The first number. |
||
138 | * @param int $b |
||
139 | * The second number. |
||
140 | * |
||
141 | * @return int |
||
142 | * The greater common divisor between $a and $b. |
||
143 | */ |
||
144 | 2 | private function gcd($a, $b) { |
|
147 | |||
148 | /** |
||
149 | * Get the order. |
||
150 | * |
||
151 | * @param int $generator |
||
152 | * The generator. |
||
153 | * |
||
154 | * @return int |
||
155 | * The order. |
||
156 | */ |
||
157 | public function order($generator) { |
||
167 | |||
168 | } |
||
169 |
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.