Skip to content

Commit 964f37b

Browse files
committed
:octocat: QRMatrix: added several isset() checks to get/set methods
1 parent da7af75 commit 964f37b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/Data/QRMatrix.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,14 @@ public function size():int{
158158
}
159159

160160
/**
161-
* Returns the value of the module at position [$x, $y]
161+
* Returns the value of the module at position [$x, $y] or -1 if the coordinate is outside of the matrix
162162
*/
163163
public function get(int $x, int $y):int{
164+
165+
if(!isset($this->matrix[$y][$x])){
166+
return -1;
167+
}
168+
164169
return $this->matrix[$y][$x];
165170
}
166171

@@ -171,7 +176,10 @@ public function get(int $x, int $y):int{
171176
* false => $M_TYPE
172177
*/
173178
public function set(int $x, int $y, bool $value, int $M_TYPE):self{
174-
$this->matrix[$y][$x] = $M_TYPE | ($value ? $this::IS_DARK : 0);
179+
180+
if(isset($this->matrix[$y][$x])){
181+
$this->matrix[$y][$x] = $M_TYPE | ($value ? $this::IS_DARK : 0);
182+
}
175183

176184
return $this;
177185
}
@@ -180,7 +188,10 @@ public function set(int $x, int $y, bool $value, int $M_TYPE):self{
180188
* Flips the value of the module
181189
*/
182190
public function flip(int $x, int $y):self{
183-
$this->matrix[$y][$x] ^= $this::IS_DARK;
191+
192+
if(isset($this->matrix[$y][$x])){
193+
$this->matrix[$y][$x] ^= $this::IS_DARK;
194+
}
184195

185196
return $this;
186197
}
@@ -191,6 +202,11 @@ public function flip(int $x, int $y):self{
191202
* true => $value & $M_TYPE === $M_TYPE
192203
*/
193204
public function checkType(int $x, int $y, int $M_TYPE):bool{
205+
206+
if(!isset($this->matrix[$y][$x])){
207+
return false;
208+
}
209+
194210
return ($this->matrix[$y][$x] & $M_TYPE) === $M_TYPE;
195211
}
196212

0 commit comments

Comments
 (0)