Skip to content

Commit

Permalink
:octocat: QRMatrix: added several isset() checks to get/set methods
Browse files Browse the repository at this point in the history
  • Loading branch information
codemasher committed Jun 5, 2022
1 parent da7af75 commit 964f37b
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Data/QRMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,14 @@ public function size():int{
}

/**
* Returns the value of the module at position [$x, $y]
* Returns the value of the module at position [$x, $y] or -1 if the coordinate is outside of the matrix
*/
public function get(int $x, int $y):int{

if(!isset($this->matrix[$y][$x])){
return -1;
}

return $this->matrix[$y][$x];
}

Expand All @@ -171,7 +176,10 @@ public function get(int $x, int $y):int{
* false => $M_TYPE
*/
public function set(int $x, int $y, bool $value, int $M_TYPE):self{
$this->matrix[$y][$x] = $M_TYPE | ($value ? $this::IS_DARK : 0);

if(isset($this->matrix[$y][$x])){
$this->matrix[$y][$x] = $M_TYPE | ($value ? $this::IS_DARK : 0);
}

return $this;
}
Expand All @@ -180,7 +188,10 @@ public function set(int $x, int $y, bool $value, int $M_TYPE):self{
* Flips the value of the module
*/
public function flip(int $x, int $y):self{
$this->matrix[$y][$x] ^= $this::IS_DARK;

if(isset($this->matrix[$y][$x])){
$this->matrix[$y][$x] ^= $this::IS_DARK;
}

return $this;
}
Expand All @@ -191,6 +202,11 @@ public function flip(int $x, int $y):self{
* true => $value & $M_TYPE === $M_TYPE
*/
public function checkType(int $x, int $y, int $M_TYPE):bool{

if(!isset($this->matrix[$y][$x])){
return false;
}

return ($this->matrix[$y][$x] & $M_TYPE) === $M_TYPE;
}

Expand Down

0 comments on commit 964f37b

Please sign in to comment.