diff options
author | Chih-Hsuan Yen <[email protected]> | 2022-07-02 22:01:51 +0800 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2022-07-12 22:23:48 +0300 |
commit | 4b6161892000cb2b8392dce92a9cf2cabdf2d20e (patch) | |
tree | 5cad602010e4d13e1a48d6b922d4768c0893ac8b /vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php | |
parent | d9861038bcc3cb2f38c7153bdca7d5ab89597afa (diff) |
Update php-qrcode and php-settings-container for PHP 8.1
By running the following command after updating composer.json
```
composer update chillerlan/php-qrcode chillerlan/php-settings-container
```
This change fixes a deprecation warning from Preferences ->
Personal data / Authentication -> Authenticator (OTP).
```
Return type of chillerlan\Settings\SettingsContainerAbstract::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
1. vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php(19): ttrss_error_handler(Return type of chillerlan\Settings\SettingsContainerAbstract::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice, vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php)
2. vendor/composer/ClassLoader.php(571): include(/usr/share/webapps/tt-rss/vendor/chillerlan/php-settings-container/src/SettingsContainerAbstract.php)
3. vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile(/usr/share/webapps/tt-rss/vendor/composer/../chillerlan/php-settings-container/src/SettingsContainerAbstract.php)
4. vendor/chillerlan/php-qrcode/src/QROptions.php(59): loadClass(chillerlan\Settings\SettingsContainerAbstract)
5. vendor/composer/ClassLoader.php(571): include(/usr/share/webapps/tt-rss/vendor/chillerlan/php-qrcode/src/QROptions.php)
6. vendor/composer/ClassLoader.php(428): Composer\Autoload\includeFile(/usr/share/webapps/tt-rss/vendor/composer/../chillerlan/php-qrcode/src/QROptions.php)
7. vendor/chillerlan/php-qrcode/src/QRCode.php(113): loadClass(chillerlan\QRCode\QROptions)
8. classes/pref/prefs.php(958): __construct()
9. classes/pref/prefs.php(469): _get_otp_qrcode_img()
10. classes/pref/prefs.php(541): index_auth_2fa()
11. backend.php(136): index_auth()
```
The issue is fixed in php-settings-container 2.1.1 [1] Here I use the
latest php-qrcode version for another PHP 8.1 fix [2].
[1] https://github.com/chillerlan/php-settings-container/commit/68bc5019c8b38956c83906431ef879668366b036#diff-359c7f7a6d32d9935951e1b0742eb116fb654f4a932c8d40328bb5dcab2fa111L162
[2] https://github.com/chillerlan/php-qrcode/issues/97
Diffstat (limited to 'vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php')
-rw-r--r-- | vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php b/vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php index 8dfd24180..7874cb53d 100644 --- a/vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php +++ b/vendor/chillerlan/php-qrcode/src/Data/MaskPatternTester.php @@ -8,41 +8,51 @@ * @author Smiley <[email protected]> * @copyright 2017 Smiley * @license MIT + * + * @noinspection PhpUnused */ namespace chillerlan\QRCode\Data; -use function abs, call_user_func_array; +use function abs, array_search, call_user_func_array, min; /** - * The sole purpose of this class is to receive a QRMatrix object and run the pattern tests on it. + * Receives a QRDataInterface object and runs the mask pattern tests on it. + * + * ISO/IEC 18004:2000 Section 8.8.2 - Evaluation of masking results * - * @link http://www.thonky.com/qr-code-tutorial/data-masking + * @see http://www.thonky.com/qr-code-tutorial/data-masking */ -class MaskPatternTester{ - - /** - * @var \chillerlan\QRCode\Data\QRMatrix - */ - protected $matrix; +final class MaskPatternTester{ /** - * @var int + * The data interface that contains the data matrix to test */ - protected $moduleCount; + protected QRDataInterface $dataInterface; /** - * Receives the matrix an sets the module count + * Receives the QRDataInterface * * @see \chillerlan\QRCode\QROptions::$maskPattern * @see \chillerlan\QRCode\Data\QRMatrix::$maskPattern - * @see \chillerlan\QRCode\QRCode::getBestMaskPattern() + */ + public function __construct(QRDataInterface $dataInterface){ + $this->dataInterface = $dataInterface; + } + + /** + * shoves a QRMatrix through the MaskPatternTester to find the lowest penalty mask pattern * - * @param \chillerlan\QRCode\Data\QRMatrix $matrix + * @see \chillerlan\QRCode\Data\MaskPatternTester */ - public function __construct(QRMatrix $matrix){ - $this->matrix = $matrix; - $this->moduleCount = $this->matrix->size(); + public function getBestMaskPattern():int{ + $penalties = []; + + for($pattern = 0; $pattern < 8; $pattern++){ + $penalties[$pattern] = $this->testPattern($pattern); + } + + return array_search(min($penalties), $penalties, true); } /** @@ -50,15 +60,13 @@ class MaskPatternTester{ * * @see \chillerlan\QRCode\QROptions::$maskPattern * @see \chillerlan\QRCode\Data\QRMatrix::$maskPattern - * @see \chillerlan\QRCode\QRCode::getBestMaskPattern() - * - * @return int */ - public function testPattern():int{ - $penalty = 0; + public function testPattern(int $pattern):int{ + $matrix = $this->dataInterface->initMatrix($pattern, true); + $penalty = 0; for($level = 1; $level <= 4; $level++){ - $penalty += call_user_func_array([$this, 'testLevel'.$level], [$this->matrix->matrix(true)]); + $penalty += call_user_func_array([$this, 'testLevel'.$level], [$matrix->matrix(true), $matrix->size()]); } return (int)$penalty; @@ -66,10 +74,8 @@ class MaskPatternTester{ /** * Checks for each group of five or more same-colored modules in a row (or column) - * - * @return int */ - protected function testLevel1(array $m):int{ + protected function testLevel1(array $m, int $size):int{ $penalty = 0; foreach($m as $y => $row){ @@ -78,13 +84,13 @@ class MaskPatternTester{ for($ry = -1; $ry <= 1; $ry++){ - if($y + $ry < 0 || $this->moduleCount <= $y + $ry){ + if($y + $ry < 0 || $size <= $y + $ry){ continue; } for($rx = -1; $rx <= 1; $rx++){ - if(($ry === 0 && $rx === 0) || (($x + $rx) < 0 || $this->moduleCount <= ($x + $rx))){ + if(($ry === 0 && $rx === 0) || (($x + $rx) < 0 || $size <= ($x + $rx))){ continue; } @@ -107,21 +113,19 @@ class MaskPatternTester{ /** * Checks for each 2x2 area of same-colored modules in the matrix - * - * @return int */ - protected function testLevel2(array $m):int{ + protected function testLevel2(array $m, int $size):int{ $penalty = 0; foreach($m as $y => $row){ - if($y > ($this->moduleCount - 2)){ + if($y > $size - 2){ break; } foreach($row as $x => $val){ - if($x > ($this->moduleCount - 2)){ + if($x > $size - 2){ break; } @@ -140,17 +144,15 @@ class MaskPatternTester{ /** * Checks if there are patterns that look similar to the finder patterns (1:1:3:1:1 ratio) - * - * @return int */ - protected function testLevel3(array $m):int{ + protected function testLevel3(array $m, int $size):int{ $penalties = 0; foreach($m as $y => $row){ foreach($row as $x => $val){ if( - ($x + 6) < $this->moduleCount + $x + 6 < $size && $val && !$m[$y][$x + 1] && $m[$y][$x + 2] @@ -163,7 +165,7 @@ class MaskPatternTester{ } if( - ($y + 6) < $this->moduleCount + $y + 6 < $size && $val && !$m[$y + 1][$x] && $m[$y + 2][$x] @@ -183,10 +185,8 @@ class MaskPatternTester{ /** * Checks if more than half of the modules are dark or light, with a larger penalty for a larger difference - * - * @return float */ - protected function testLevel4(array $m):float{ + protected function testLevel4(array $m, int $size):float{ $count = 0; foreach($m as $y => $row){ @@ -197,7 +197,7 @@ class MaskPatternTester{ } } - return (abs(100 * $count / $this->moduleCount / $this->moduleCount - 50) / 5) * 10; + return (abs(100 * $count / $size / $size - 50) / 5) * 10; } } |