@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $this->cells = array_fill(0, $this->gridSize * $this->gridSize, null); |
71 | 71 | |
72 | 72 | for ($i = 0; $i < (2 * $this->gridSize * $this->gridSize); $i++) { |
73 | - $this->columnArray[$i]=$this->getColumnDefault($i); |
|
73 | + $this->columnArray[$i] = $this->getColumnDefault($i); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | return $this; |
@@ -79,15 +79,15 @@ discard block |
||
79 | 79 | public function generate(): self |
80 | 80 | { |
81 | 81 | $blocks = $this->gridSize * $this->gridSize; |
82 | - $i=rand(0, $blocks-1); |
|
82 | + $i = rand(0, $blocks - 1); |
|
83 | 83 | |
84 | - $complete=0; |
|
84 | + $complete = 0; |
|
85 | 85 | while ($complete < $blocks) { |
86 | 86 | $this->placeWord($i); |
87 | 87 | $complete++; |
88 | 88 | $i++; |
89 | - if ($i==$blocks) { |
|
90 | - $i=0; |
|
89 | + if ($i == $blocks) { |
|
90 | + $i = 0; |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | |
@@ -97,25 +97,25 @@ discard block |
||
97 | 97 | protected function addPlacedWord(Word $word, int $increment, int $len): void |
98 | 98 | { |
99 | 99 | $string = ''; |
100 | - $flag=false; |
|
100 | + $flag = false; |
|
101 | 101 | |
102 | - for ($i=$word->getStart(); $i<=$word->getEnd(); $i+=$increment) { |
|
102 | + for ($i = $word->getStart(); $i <= $word->getEnd(); $i += $increment) { |
|
103 | 103 | if ($this->cells[$i] === null) { |
104 | 104 | $string .= '_'; |
105 | 105 | } else { |
106 | 106 | $string .= $this->cells[$i]; |
107 | - $flag=true; |
|
107 | + $flag = true; |
|
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | - if (! $flag) { |
|
111 | + if (!$flag) { |
|
112 | 112 | $randomWord = $this->getRandomWord($len); |
113 | 113 | $word->setLabel($word->getInversed() ? strrev($randomWord) : $randomWord); |
114 | 114 | $this->addWord($word); |
115 | 115 | return; |
116 | 116 | } |
117 | 117 | |
118 | - if (strpos($string, '_')===false) { |
|
118 | + if (strpos($string, '_') === false) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 | |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | protected function placeWordHorizontally(Word $word, int $len): void |
127 | 127 | { |
128 | 128 | $inc = 1; |
129 | - $word->setEnd($word->getStart()+$len-1); |
|
129 | + $word->setEnd($word->getStart() + $len - 1); |
|
130 | 130 | while ($this->columnArray[$word->getEnd()] < $this->columnArray[$word->getStart()]) { |
131 | - $word->setStart($word->getStart()-1); |
|
132 | - $word->setEnd($word->getStart()+$len-1); |
|
131 | + $word->setStart($word->getStart() - 1); |
|
132 | + $word->setEnd($word->getStart() + $len - 1); |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | $this->addPlacedWord($word, $inc, $len); |
@@ -137,11 +137,11 @@ discard block |
||
137 | 137 | |
138 | 138 | protected function placeWordVertical(Word $word, int $len): void |
139 | 139 | { |
140 | - $inc=$this->gridSize; |
|
141 | - $word->setEnd($word->getStart()+($len*$this->gridSize)-$this->gridSize); |
|
142 | - while ($word->getEnd()>($this->gridSize*$this->gridSize)-1) { |
|
143 | - $word->setStart($word->getStart()-$this->gridSize); |
|
144 | - $word->setEnd($word->getStart()+($len*$this->gridSize)-$this->gridSize); |
|
140 | + $inc = $this->gridSize; |
|
141 | + $word->setEnd($word->getStart() + ($len * $this->gridSize) - $this->gridSize); |
|
142 | + while ($word->getEnd() > ($this->gridSize * $this->gridSize) - 1) { |
|
143 | + $word->setStart($word->getStart() - $this->gridSize); |
|
144 | + $word->setEnd($word->getStart() + ($len * $this->gridSize) - $this->gridSize); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | $this->addPlacedWord($word, $inc, $len); |
@@ -149,30 +149,30 @@ discard block |
||
149 | 149 | |
150 | 150 | protected function placeWordDiagonallyLtr(Word $word, int $len): void |
151 | 151 | { |
152 | - $inc=$this->gridSize+1; |
|
153 | - $word->setEnd($word->getStart()+($len*($this->gridSize+1))-($this->gridSize+1)); |
|
152 | + $inc = $this->gridSize + 1; |
|
153 | + $word->setEnd($word->getStart() + ($len * ($this->gridSize + 1)) - ($this->gridSize + 1)); |
|
154 | 154 | while ($this->columnArray[$word->getEnd()] < $this->columnArray[$word->getStart()]) { |
155 | - $word->setStart($word->getStart()-1); |
|
156 | - $word->setEnd($word->getStart()+($len*($this->gridSize+1))-($this->gridSize+1)); |
|
155 | + $word->setStart($word->getStart() - 1); |
|
156 | + $word->setEnd($word->getStart() + ($len * ($this->gridSize + 1)) - ($this->gridSize + 1)); |
|
157 | 157 | } |
158 | - while ($word->getEnd()>($this->gridSize*$this->gridSize)-1) { |
|
159 | - $word->setStart($word->getStart()-$this->gridSize); |
|
160 | - $word->setEnd($word->getStart()+($len*($this->gridSize+1))-($this->gridSize+1)); |
|
158 | + while ($word->getEnd() > ($this->gridSize * $this->gridSize) - 1) { |
|
159 | + $word->setStart($word->getStart() - $this->gridSize); |
|
160 | + $word->setEnd($word->getStart() + ($len * ($this->gridSize + 1)) - ($this->gridSize + 1)); |
|
161 | 161 | } |
162 | 162 | $this->addPlacedWord($word, $inc, $len); |
163 | 163 | } |
164 | 164 | |
165 | 165 | protected function placeWordDiagonallyRtl(Word $word, int $len): void |
166 | 166 | { |
167 | - $inc=$this->gridSize-1; |
|
168 | - $word->setEnd($word->getStart()+(($len-1)*($this->gridSize-1))); |
|
167 | + $inc = $this->gridSize - 1; |
|
168 | + $word->setEnd($word->getStart() + (($len - 1) * ($this->gridSize - 1))); |
|
169 | 169 | while ($this->columnArray[$word->getEnd()] > $this->columnArray[$word->getStart()]) { |
170 | - $word->setStart($word->getStart()+1); |
|
171 | - $word->setEnd($word->getStart()+(($len-1)*($this->gridSize-1))); |
|
170 | + $word->setStart($word->getStart() + 1); |
|
171 | + $word->setEnd($word->getStart() + (($len - 1) * ($this->gridSize - 1))); |
|
172 | 172 | } |
173 | - while ($word->getEnd()>($this->gridSize*$this->gridSize)-1) { |
|
174 | - $word->setStart($word->getStart()-$this->gridSize); |
|
175 | - $word->setEnd($word->getStart()+(($len-1)*($this->gridSize-1))); |
|
173 | + while ($word->getEnd() > ($this->gridSize * $this->gridSize) - 1) { |
|
174 | + $word->setStart($word->getStart() - $this->gridSize); |
|
175 | + $word->setEnd($word->getStart() + (($len - 1) * ($this->gridSize - 1))); |
|
176 | 176 | } |
177 | 177 | $this->addPlacedWord($word, $inc, $len); |
178 | 178 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | |
204 | 204 | protected function getColumnDefault(int $x): int |
205 | 205 | { |
206 | - return ($x % $this->gridSize)+1; |
|
206 | + return ($x % $this->gridSize) + 1; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | protected function addWord(Word $word): void |
@@ -212,23 +212,23 @@ discard block |
||
212 | 212 | return; |
213 | 213 | } |
214 | 214 | |
215 | - $j=0; |
|
215 | + $j = 0; |
|
216 | 216 | $incrementBy = 1; |
217 | 217 | switch ($word->getOrientation()) { |
218 | 218 | case Word::HORIZONTAL: |
219 | - $incrementBy=1; |
|
219 | + $incrementBy = 1; |
|
220 | 220 | break; |
221 | 221 | |
222 | 222 | case Word::VERTICAL: |
223 | - $incrementBy=$this->gridSize; |
|
223 | + $incrementBy = $this->gridSize; |
|
224 | 224 | break; |
225 | 225 | |
226 | 226 | case Word::DIAGONAL_LEFT_TO_RIGHT: |
227 | - $incrementBy=$this->gridSize+1; |
|
227 | + $incrementBy = $this->gridSize + 1; |
|
228 | 228 | break; |
229 | 229 | |
230 | 230 | case Word::DIAGONAL_RIGHT_TO_LEFT: |
231 | - $incrementBy=$this->gridSize-1; |
|
231 | + $incrementBy = $this->gridSize - 1; |
|
232 | 232 | break; |
233 | 233 | } |
234 | 234 | |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $j++; |
238 | 238 | } |
239 | 239 | |
240 | - $this->wordsList[]=$word; |
|
240 | + $this->wordsList[] = $word; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | public function getTextGrid() |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | |
272 | 272 | public function getPuzzleWords() |
273 | 273 | { |
274 | - return collect($this->wordsList)->map(function (Word $word) { |
|
274 | + return collect($this->wordsList)->map(function(Word $word) { |
|
275 | 275 | $label = $word->getLabel(); |
276 | 276 | if ($word->getInversed()) { |
277 | 277 | $label = strrev(/** @scrutinizer ignore-type */$label); |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | protected function setWordsCollection(Collection $wordsCollection): self |
18 | 18 | { |
19 | 19 | $this->wordsCollection = $wordsCollection->filter( |
20 | - fn ($word) => strlen($word) >= $this->minWordLen && strlen($word) <= $this->maxWordLen |
|
20 | + fn($word) => strlen($word) >= $this->minWordLen && strlen($word) <= $this->maxWordLen |
|
21 | 21 | ) |
22 | 22 | ->map(fn($word) => strtoupper($word)); |
23 | 23 | |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $len = rand($this->minWordLen, $this->gridSize); |
35 | 35 | } while (in_array($len, $exclude)); |
36 | 36 | |
37 | - $available = $this->wordsCollection->filter(fn ($word) => strlen($word) === $len)->count(); |
|
37 | + $available = $this->wordsCollection->filter(fn($word) => strlen($word) === $len)->count(); |
|
38 | 38 | |
39 | 39 | $exclude[] = $len; |
40 | 40 | |
@@ -43,14 +43,14 @@ discard block |
||
43 | 43 | |
44 | 44 | protected function markWordUsed($word): void |
45 | 45 | { |
46 | - $this->wordsCollection = $this->wordsCollection->reject(function ($current) use ($word) { |
|
46 | + $this->wordsCollection = $this->wordsCollection->reject(function($current) use ($word) { |
|
47 | 47 | return $current === $word; |
48 | 48 | }); |
49 | 49 | } |
50 | 50 | |
51 | 51 | protected function getRandomWord(int $len): string |
52 | 52 | { |
53 | - $word = $this->wordsCollection->filter(function ($word) use ($len) { |
|
53 | + $word = $this->wordsCollection->filter(function($word) use ($len) { |
|
54 | 54 | return strlen($word) === $len; |
55 | 55 | })->random(1)->first(); |
56 | 56 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | protected function getWordLike(string $pattern): ?string |
63 | 63 | { |
64 | 64 | $pattern = str_replace("_", ".", $pattern); |
65 | - $words = $this->wordsCollection->filter(function ($word) use ($pattern) { |
|
65 | + $words = $this->wordsCollection->filter(function($word) use ($pattern) { |
|
66 | 66 | return preg_match("/^$pattern\$/i", $word); |
67 | 67 | }); |
68 | 68 |