From cb7c53499356fea6f14f4e087db0a8c7eaf99636 Mon Sep 17 00:00:00 2001 From: nicolaasuni Date: Wed, 22 Nov 2023 10:35:30 +0000 Subject: [PATCH] complete php8 refactoring --- src/Type/Square/QrCode/ByteStream.php | 60 +++++---------------------- src/Type/Square/QrCode/Estimate.php | 21 ++++------ src/Type/Square/QrCode/Init.php | 2 +- src/Type/Square/QrCode/InputItem.php | 23 +++------- src/Type/Square/QrCode/Mask.php | 19 ++++++--- src/Type/Square/QrCode/MaskNum.php | 8 ++-- src/Type/Square/QrCode/Spec.php | 18 ++++++-- src/Type/Square/QrCode/SpecRs.php | 36 ++++++++++++---- src/Type/Square/QrCode/Split.php | 6 ++- 9 files changed, 91 insertions(+), 102 deletions(-) diff --git a/src/Type/Square/QrCode/ByteStream.php b/src/Type/Square/QrCode/ByteStream.php index a78edec..cef62a2 100644 --- a/src/Type/Square/QrCode/ByteStream.php +++ b/src/Type/Square/QrCode/ByteStream.php @@ -28,6 +28,8 @@ * @copyright 2010-2023 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode + * + * @phpstan-import-type Item from \Com\Tecnick\Barcode\Type\Square\QrCode\Estimate */ class ByteStream extends \Com\Tecnick\Barcode\Type\Square\QrCode\Encode { @@ -48,12 +50,7 @@ public function __construct(int $hint, int $version, int $level) /** * Pack all bit streams padding bits into a byte array * - * @param array, - * 'bstream': array, - * }> $items Items + * @param array $items Items * * @return array padded merged byte stream */ @@ -69,12 +66,7 @@ public function getByteStream(array $items): array /** * merge the bit stream * - * @param array, - * 'bstream': array, - * }> $items Items + * @param array $items Items * * @return array bitstream */ @@ -177,19 +169,9 @@ protected function bitstreamToByte(array $bstream): array /** * convertData * - * @param array, - * 'bstream': array, - * }> $items Items + * @param array $items Items * - * @return array, - * 'bstream': array, - * }> + * @return array */ protected function convertData(array $items): array { @@ -220,21 +202,11 @@ protected function convertData(array $items): array /** * Create BitStream * - * @param array, - * 'bstream': array, - * }> $items Items + * @param array $items Items * * @return array{ - * 0: array, - * 'bstream': array, - * }>, - * 1: int, + * 0: array, + * 1: int, * } */ protected function createBitStream(array $items): array @@ -252,20 +224,10 @@ protected function createBitStream(array $items): array /** * Encode BitStream * - * @param array{ - * 'mode': int, - * 'size': int, - * 'data': array, - * 'bstream'?: array, - * } $inputitem Input item + * @param Item $inputitem Input item * @param int $version Code version * - * @return array{ - * 'mode': int, - * 'size': int, - * 'data': array, - * 'bstream': array, - * } + * @return Item */ public function encodeBitStream(array $inputitem, int $version): array { diff --git a/src/Type/Square/QrCode/Estimate.php b/src/Type/Square/QrCode/Estimate.php index e3f418a..8e0129a 100644 --- a/src/Type/Square/QrCode/Estimate.php +++ b/src/Type/Square/QrCode/Estimate.php @@ -28,6 +28,13 @@ * @copyright 2010-2023 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode + * + * @phpstan-type Item array{ + * 'mode': int, + * 'size': int, + * 'data': array, + * 'bstream': array, + * } */ abstract class Estimate { @@ -129,12 +136,7 @@ public function estimateBitsModeKanji(int $size): int /** * Estimate version * - * @param array, - * 'bstream': array, - * }> $items Items + * @param array $items Items * @param int $level Error correction level * * @return int version @@ -182,12 +184,7 @@ protected function getMinimumVersion(int $size, int $level): int /** * estimateBitStreamSize * - * @param array, - * 'bstream': array, - * }> $items Items + * @param array $items Items * @param int $version Code version * * @return int bits diff --git a/src/Type/Square/QrCode/Init.php b/src/Type/Square/QrCode/Init.php index 925d22a..e407403 100644 --- a/src/Type/Square/QrCode/Init.php +++ b/src/Type/Square/QrCode/Init.php @@ -106,7 +106,7 @@ abstract class Init extends \Com\Tecnick\Barcode\Type\Square\QrCode\Mask /** * Frame * - * @var array> + * @var array */ protected array $frame = []; diff --git a/src/Type/Square/QrCode/InputItem.php b/src/Type/Square/QrCode/InputItem.php index 7a202df..17090d6 100644 --- a/src/Type/Square/QrCode/InputItem.php +++ b/src/Type/Square/QrCode/InputItem.php @@ -28,6 +28,8 @@ * @copyright 2010-2023 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode + * + * @phpstan-import-type Item from \Com\Tecnick\Barcode\Type\Square\QrCode\Estimate */ abstract class InputItem extends \Com\Tecnick\Barcode\Type\Square\QrCode\Estimate { @@ -45,22 +47,12 @@ public function lookAnTable(int $chr): int * Append data to an input object. * The data is copied and appended to the input object. * - * @param array, - * 'bstream': array, - * }> $items Input items + * @param array $items Input items * @param int $mode Encoding mode. * @param int $size Size of data (byte). * @param array $data Array of input data. * - * @return array, - * 'bstream': array, - * }> items + * @return array items */ public function appendNewInputItem( array $items, @@ -84,12 +76,7 @@ public function appendNewInputItem( * @param array $data Array of input data. * @param array $bstream Binary stream * - * @return array{ - * 'mode': int, - * 'size': int, - * 'data': array, - * 'bstream': array, - * } input item + * @return Item input item */ protected function newInputItem( int $mode, diff --git a/src/Type/Square/QrCode/Mask.php b/src/Type/Square/QrCode/Mask.php index 4ea25c0..d037745 100644 --- a/src/Type/Square/QrCode/Mask.php +++ b/src/Type/Square/QrCode/Mask.php @@ -31,6 +31,8 @@ abstract class Mask extends \Com\Tecnick\Barcode\Type\Square\QrCode\MaskNum { /** * Run length + * + * @var array */ protected array $runLength = []; @@ -73,10 +75,10 @@ public function __construct( * Get the best mask * * @param int $width Width - * @param array $frame Frame + * @param array $frame Frame * @param int $level Error Correction lLevel * - * @return array best mask + * @return array best mask */ protected function mask( int $width, @@ -118,11 +120,11 @@ protected function mask( * Make a mask * * @param int $width Mask width - * @param array $frame Frame + * @param array $frame Frame * @param int $maskNo Mask number * @param int $level Error Correction level * - * @return array mask + * @return array mask */ protected function makeMask( int $width, @@ -139,7 +141,7 @@ protected function makeMask( * Write Format Information on the frame and returns the number of black bits * * @param int $width Mask width - * @param array $frame Frame + * @param array $frame Frame * @param int $maskNo Mask number * @param int $level Error Correction level * @@ -197,7 +199,7 @@ protected function writeFormatInformation( * Evaluate Symbol and returns demerit value. * * @param int $width Width - * @param array $frame Frame + * @param array $frame Frame */ protected function evaluateSymbol(int $width, array $frame): int { @@ -285,6 +287,8 @@ protected function evaluateSymbolB( /** * Calc N1 N3 * + * @param int $length Length + * * @return int demerit */ protected function calcN1N3(int $length): int @@ -306,6 +310,9 @@ protected function calcN1N3(int $length): int /** * Calc N1 N3 delta * + * @param int $length Length + * @param int $idx Index + * * @return int demerit delta */ protected function calcN1N3delta(int $length, int $idx): int diff --git a/src/Type/Square/QrCode/MaskNum.php b/src/Type/Square/QrCode/MaskNum.php index 52aff1a..8cfde0d 100644 --- a/src/Type/Square/QrCode/MaskNum.php +++ b/src/Type/Square/QrCode/MaskNum.php @@ -34,8 +34,8 @@ abstract class MaskNum * * @param int $maskNo Mask number * @param int $width Width - * @param array $frame Frame - * @param array $mask Mask + * @param array $frame Frame + * @param array $mask Mask * * @return int mask number */ @@ -66,9 +66,9 @@ protected function makeMaskNo( * * @param int $maskNo Mask number * @param int $width Width - * @param array $frame Frame + * @param array $frame Frame * - * @return array bit mask + * @return array> bit mask */ protected function generateMaskNo( int $maskNo, diff --git a/src/Type/Square/QrCode/Spec.php b/src/Type/Square/QrCode/Spec.php index f11f831..cc578f0 100644 --- a/src/Type/Square/QrCode/Spec.php +++ b/src/Type/Square/QrCode/Spec.php @@ -26,6 +26,14 @@ * @copyright 2010-2023 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode + * + * @phpstan-type EccSpec array{ + * 0: int, + * 1: int, + * 2: int, + * 3: int, + * 4: int, + * } */ class Spec extends \Com\Tecnick\Barcode\Type\Square\QrCode\SpecRs { @@ -115,10 +123,14 @@ public function maximumWords(int $mode, int $version): int * * @param int $version Version * @param int $level Error correction level - * @param array $spec Array of ECC specification contains as following: - * {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code} + * @param EccSpec $spec Array of ECC specification * - * @return array spec + * @return EccSpec spec: + * 0 = # of type1 blocks + * 1 = # of data code + * 2 = # of ecc code + * 3 = # of type2 blocks + * 4 = # of data code */ public function getEccSpec(int $version, int $level, array $spec): array { diff --git a/src/Type/Square/QrCode/SpecRs.php b/src/Type/Square/QrCode/SpecRs.php index 57cbb5e..5d569d8 100644 --- a/src/Type/Square/QrCode/SpecRs.php +++ b/src/Type/Square/QrCode/SpecRs.php @@ -34,6 +34,8 @@ abstract class SpecRs /** * Return block number 0 * + * @param array $spec Spec + * * @return int value */ public function rsBlockNum(array $spec): int @@ -44,6 +46,8 @@ public function rsBlockNum(array $spec): int /** * Return block number 1 * + * @param array $spec Spec + * * @return int value */ public function rsBlockNum1(array $spec): int @@ -54,6 +58,8 @@ public function rsBlockNum1(array $spec): int /** * Return data codes 1 * + * @param array $spec Spec + * * @return int value */ public function rsDataCodes1(array $spec): int @@ -64,6 +70,8 @@ public function rsDataCodes1(array $spec): int /** * Return ecc codes 1 * + * @param array $spec Spec + * * @return int value */ public function rsEccCodes1(array $spec): int @@ -74,6 +82,8 @@ public function rsEccCodes1(array $spec): int /** * Return block number 2 * + * @param array $spec Spec + * * @return int value */ public function rsBlockNum2(array $spec): int @@ -84,6 +94,8 @@ public function rsBlockNum2(array $spec): int /** * Return data codes 2 * + * @param array $spec Spec + * * @return int value */ public function rsDataCodes2(array $spec): int @@ -94,6 +106,8 @@ public function rsDataCodes2(array $spec): int /** * Return ecc codes 2 * + * @param array $spec Spec + * * @return int value */ public function rsEccCodes2(array $spec): int @@ -104,6 +118,8 @@ public function rsEccCodes2(array $spec): int /** * Return data length * + * @param array $spec Spec + * * @return int value */ public function rsDataLength(array $spec): int @@ -114,6 +130,8 @@ public function rsDataLength(array $spec): int /** * Return ecc length * + * @param array $spec Spec + * * @return int value */ public function rsEccLength(array $spec): int @@ -126,7 +144,7 @@ public function rsEccLength(array $spec): int * * @param int $version Version * - * @return array of unsigned char. + * @return array of unsigned char. */ public function createFrame(int $version): array { @@ -198,11 +216,13 @@ public function createFrame(int $version): array /** * Replace a value on the array at the specified position * + * @param array $srctab Source table * @param int $xpos X position * @param int $ypos Y position * @param string $repl Value to replace * @param int $replLen Length of the repl string - * @return array srctab + * + * @return array srctab */ public function qrstrset( array $srctab, @@ -223,11 +243,11 @@ public function qrstrset( /** * Put an alignment marker. * - * @param array $frame Frame + * @param array $frame Frame * @param int $pox X center coordinate of the pattern * @param int $poy Y center coordinate of the pattern * - * @return array frame + * @return array frame */ public function putAlignmentMarker( array $frame, @@ -253,11 +273,11 @@ public function putAlignmentMarker( /** * Put a finder pattern. * - * @param array $frame Frame + * @param array $frame Frame * @param int $pox X center coordinate of the pattern * @param int $poy Y center coordinate of the pattern * - * @return array frame + * @return array frame */ public function putFinderPattern( array $frame, @@ -299,10 +319,10 @@ public function getVersionPattern(int $version): int * Put an alignment pattern. * * @param int $version Version - * @param array $frame Frame + * @param array $frame Frame * @param int $width Width * - * @return array frame + * @return array frame */ public function putAlignmentPattern( int $version, diff --git a/src/Type/Square/QrCode/Split.php b/src/Type/Square/QrCode/Split.php index 3809c34..df5179c 100644 --- a/src/Type/Square/QrCode/Split.php +++ b/src/Type/Square/QrCode/Split.php @@ -28,11 +28,15 @@ * @copyright 2010-2023 Nicola Asuni - Tecnick.com LTD * @license http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT) * @link https://github.com/tecnickcom/tc-lib-barcode + * + * @phpstan-import-type Item from \Com\Tecnick\Barcode\Type\Square\QrCode\Estimate */ class Split { /** * Input items + * + * @var array */ protected array $items = []; @@ -67,7 +71,7 @@ public function __construct( * * @param string $data Data * - * @return array items + * @return array items */ public function getSplittedString(string $data): array {