mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-12 02:36:28 +00:00
:octocat: simplified mask pattern tester call
This commit is contained in:
@@ -37,14 +37,10 @@ class MaskPatternTester{
|
||||
* @see \chillerlan\QRCode\QRCode::getBestMaskPattern()
|
||||
*
|
||||
* @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->moduleCount = $this->matrix->size();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-5
@@ -197,16 +197,12 @@ class QRCode{
|
||||
protected function getBestMaskPattern():int{
|
||||
$penalties = [];
|
||||
|
||||
$tester = new MaskPatternTester;
|
||||
|
||||
for($testPattern = 0; $testPattern < 8; $testPattern++){
|
||||
$matrix = $this
|
||||
->dataInterface
|
||||
->initMatrix($testPattern, true);
|
||||
|
||||
$tester->setMatrix($matrix);
|
||||
|
||||
$penalties[$testPattern] = $tester->testPattern();
|
||||
$penalties[$testPattern] = (new MaskPatternTester($matrix))->testPattern();
|
||||
}
|
||||
|
||||
return array_search(min($penalties), $penalties, true);
|
||||
|
||||
@@ -25,7 +25,7 @@ class MaskPatternTesterTest extends QRTestAbstract{
|
||||
public function testMaskpattern(){
|
||||
$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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user