Ver código fonte

:octocat: QRMatrix: allow retruning a pure boolean representation

codemasher 5 anos atrás
pai
commit
0f21c91802
1 arquivos alterados com 19 adições e 4 exclusões
  1. 19 4
      src/Data/QRMatrix.php

+ 19 - 4
src/Data/QRMatrix.php

@@ -258,12 +258,27 @@ final class QRMatrix{
 	}
 
 	/**
-	 * Returns the data matrix
+	 * Returns the data matrix, returns a pure boolean representation if $boolean is set to true
 	 *
 	 * @return int[][]
 	 */
-	public function matrix():array{
-		return $this->matrix;
+	public function matrix(bool $boolean = false):array{
+
+		if(!$boolean){
+			return $this->matrix;
+		}
+
+		$matrix = [];
+
+		foreach($this->matrix as $y => $row){
+			$matrix[$y] = [];
+
+			foreach($row as $x => $val){
+				$matrix[$y][$x] = ($val >> 8) > 0;
+			}
+		}
+
+		return $matrix;
 	}
 
 	/**
@@ -325,7 +340,7 @@ final class QRMatrix{
 	 *            $value >> 8 === 0
 	 */
 	public function check(int $x, int $y):bool{
-		return $this->matrix[$y][$x] >> 8 > 0;
+		return ($this->matrix[$y][$x] >> 8) > 0;
 	}