Explorar o código

:octocat: simplified mask pattern tester call

codemasher %!s(int64=7) %!d(string=hai) anos
pai
achega
aac41883d0
Modificáronse 3 ficheiros con 3 adicións e 11 borrados
  1. 1 5
      src/Data/MaskPatternTester.php
  2. 1 5
      src/QRCode.php
  3. 1 1
      tests/Data/MaskPatternTesterTest.php

+ 1 - 5
src/Data/MaskPatternTester.php

@@ -37,14 +37,10 @@ class MaskPatternTester{
 	 * @see \chillerlan\QRCode\QRCode::getBestMaskPattern()
 	 * @see \chillerlan\QRCode\QRCode::getBestMaskPattern()
 	 *
 	 *
 	 * @param \chillerlan\QRCode\Data\QRMatrix $matrix
 	 * @param \chillerlan\QRCode\Data\QRMatrix $matrix
-	 *
-	 * @return \chillerlan\QRCode\Data\MaskPatternTester
 	 */
 	 */
-	public function setMatrix(QRMatrix $matrix):MaskPatternTester{
+	public function __construct(QRMatrix $matrix){
 		$this->matrix      = $matrix;
 		$this->matrix      = $matrix;
 		$this->moduleCount = $this->matrix->size();
 		$this->moduleCount = $this->matrix->size();
-
-		return $this;
 	}
 	}
 
 
 	/**
 	/**

+ 1 - 5
src/QRCode.php

@@ -197,16 +197,12 @@ class QRCode{
 	protected function getBestMaskPattern():int{
 	protected function getBestMaskPattern():int{
 		$penalties = [];
 		$penalties = [];
 
 
-		$tester = new MaskPatternTester;
-
 		for($testPattern = 0; $testPattern < 8; $testPattern++){
 		for($testPattern = 0; $testPattern < 8; $testPattern++){
 			$matrix = $this
 			$matrix = $this
 				->dataInterface
 				->dataInterface
 				->initMatrix($testPattern, true);
 				->initMatrix($testPattern, true);
 
 
-			$tester->setMatrix($matrix);
-
-			$penalties[$testPattern] = $tester->testPattern();
+			$penalties[$testPattern] = (new MaskPatternTester($matrix))->testPattern();
 		}
 		}
 
 
 		return array_search(min($penalties), $penalties, true);
 		return array_search(min($penalties), $penalties, true);

+ 1 - 1
tests/Data/MaskPatternTesterTest.php

@@ -25,7 +25,7 @@ class MaskPatternTesterTest extends QRTestAbstract{
 	public function testMaskpattern(){
 	public function testMaskpattern(){
 		$matrix = (new Byte(new QROptions(['version' => 10]), 'test'))->initMatrix(0, true);
 		$matrix = (new Byte(new QROptions(['version' => 10]), 'test'))->initMatrix(0, true);
 
 
-		$this->assertSame(6178, (new MaskPatternTester)->setMatrix($matrix)->testPattern());
+		$this->assertSame(6178, (new MaskPatternTester($matrix))->testPattern());
 	}
 	}