From 964f37ba9601030aae8c3bcb331cee908be9b0eb Mon Sep 17 00:00:00 2001 From: smiley Date: Sun, 5 Jun 2022 21:08:04 +0200 Subject: [PATCH] :octocat: QRMatrix: added several isset() checks to get/set methods --- src/Data/QRMatrix.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Data/QRMatrix.php b/src/Data/QRMatrix.php index f9509c46d..bd93f7fec 100755 --- a/src/Data/QRMatrix.php +++ b/src/Data/QRMatrix.php @@ -158,9 +158,14 @@ class QRMatrix{ } /** - * 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]; } @@ -171,7 +176,10 @@ class QRMatrix{ * 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; } @@ -180,7 +188,10 @@ class QRMatrix{ * 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; } @@ -191,6 +202,11 @@ class QRMatrix{ * 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; }