Prechádzať zdrojové kódy

:octocat: make QROutputInterface::moduleValueIsValid() public static

smiley 2 rokov pred
rodič
commit
76e90986e7

+ 1 - 1
examples/custom_output.php

@@ -23,7 +23,7 @@ class MyCustomOutput extends QROutputAbstract{
 	/**
 	 * @inheritDoc
 	 */
-	protected function moduleValueIsValid($value):bool{
+	public static function moduleValueIsValid($value):bool{
 		// TODO: Implement moduleValueIsValid() method. (abstract)
 		return false;
 	}

+ 1 - 1
src/Output/QREps.php

@@ -25,7 +25,7 @@ class QREps extends QROutputAbstract{
 	/**
 	 * @inheritDoc
 	 */
-	protected function moduleValueIsValid($value):bool{
+	public static function moduleValueIsValid($value):bool{
 
 		if(!is_array($value) || count($value) < 3){
 			return false;

+ 2 - 2
src/Output/QRFpdf.php

@@ -47,7 +47,7 @@ class QRFpdf extends QROutputAbstract{
 	/**
 	 * @inheritDoc
 	 */
-	protected function moduleValueIsValid($value):bool{
+	public static function moduleValueIsValid($value):bool{
 
 		if(!is_array($value) || count($value) < 3){
 			return false;
@@ -94,7 +94,7 @@ class QRFpdf extends QROutputAbstract{
 		$fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, [$this->length, $this->length]);
 		$fpdf->AddPage();
 
-		if($this->moduleValueIsValid($this->options->bgColor)){
+		if($this::moduleValueIsValid($this->options->bgColor)){
 			$bgColor = $this->getModuleValue($this->options->bgColor);
 			/** @phan-suppress-next-line PhanParamTooFewUnpack */
 			$fpdf->SetFillColor(...$bgColor);

+ 3 - 3
src/Output/QRGdImage.php

@@ -82,7 +82,7 @@ class QRGdImage extends QROutputAbstract{
 	/**
 	 * @inheritDoc
 	 */
-	protected function moduleValueIsValid($value):bool{
+	public static function moduleValueIsValid($value):bool{
 
 		if(!is_array($value) || count($value) < 3){
 			return false;
@@ -185,7 +185,7 @@ class QRGdImage extends QROutputAbstract{
 			return;
 		}
 
-		if($this->moduleValueIsValid($this->options->bgColor)){
+		if($this::moduleValueIsValid($this->options->bgColor)){
 			$this->background = $this->getModuleValue($this->options->bgColor);
 
 			return;
@@ -205,7 +205,7 @@ class QRGdImage extends QROutputAbstract{
 
 		$transparencyColor = $this->background;
 
-		if($this->moduleValueIsValid($this->options->transparencyColor)){
+		if($this::moduleValueIsValid($this->options->transparencyColor)){
 			$transparencyColor = $this->getModuleValue($this->options->transparencyColor);
 		}
 

+ 3 - 3
src/Output/QRImagick.php

@@ -64,7 +64,7 @@ class QRImagick extends QROutputAbstract{
 	 * @see https://www.php.net/manual/imagickpixel.construct.php
 	 * @inheritDoc
 	 */
-	protected function moduleValueIsValid($value):bool{
+	public static function moduleValueIsValid($value):bool{
 		return is_string($value);
 	}
 
@@ -124,7 +124,7 @@ class QRImagick extends QROutputAbstract{
 			return;
 		}
 
-		if($this->moduleValueIsValid($this->options->bgColor)){
+		if($this::moduleValueIsValid($this->options->bgColor)){
 			$this->background = $this->getModuleValue($this->options->bgColor);
 
 			return;
@@ -144,7 +144,7 @@ class QRImagick extends QROutputAbstract{
 
 		$transparencyColor = $this->background;
 
-		if($this->moduleValueIsValid($this->options->transparencyColor)){
+		if($this::moduleValueIsValid($this->options->transparencyColor)){
 			$transparencyColor = $this->getModuleValue($this->options->transparencyColor);
 		}
 

+ 1 - 1
src/Output/QRMarkup.php

@@ -20,7 +20,7 @@ abstract class QRMarkup extends QROutputAbstract{
 	/**
 	 * @inheritDoc
 	 */
-	protected function moduleValueIsValid($value):bool{
+	public static function moduleValueIsValid($value):bool{
 		return is_string($value);
 	}
 

+ 1 - 8
src/Output/QROutputAbstract.php

@@ -84,20 +84,13 @@ abstract class QROutputAbstract implements QROutputInterface{
 		foreach($this::DEFAULT_MODULE_VALUES as $M_TYPE => $defaultValue){
 			$value = ($this->options->moduleValues[$M_TYPE] ?? null);
 
-			$this->moduleValues[$M_TYPE] = $this->moduleValueIsValid($value)
+			$this->moduleValues[$M_TYPE] = $this::moduleValueIsValid($value)
 				? $this->getModuleValue($value)
 				: $this->getDefaultModuleValue($defaultValue);
 		}
 
 	}
 
-	/**
-	 * Determines whether the given value is valid
-	 *
-	 * @param mixed|null $value
-	 */
-	abstract protected function moduleValueIsValid($value):bool;
-
 	/**
 	 * Returns the final value for the given input (return value depends on the output module)
 	 *

+ 7 - 0
src/Output/QROutputInterface.php

@@ -86,6 +86,13 @@ interface QROutputInterface{
 		QRMatrix::M_TEST_DARK      => true,
 	];
 
+	/**
+	 * Determines whether the given value is valid
+	 *
+	 * @param mixed|null $value
+	 */
+	public static function moduleValueIsValid($value):bool;
+
 	/**
 	 * generates the output, optionally dumps it to a file, and returns it
 	 *

+ 1 - 1
src/Output/QRString.php

@@ -23,7 +23,7 @@ class QRString extends QROutputAbstract{
 	/**
 	 * @inheritDoc
 	 */
-	protected function moduleValueIsValid($value):bool{
+	public static function moduleValueIsValid($value):bool{
 		return is_string($value);
 	}