Skip to content

Commit

Permalink
complete php8 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Nov 22, 2023
1 parent a5e4b9c commit cb7c534
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 102 deletions.
60 changes: 11 additions & 49 deletions src/Type/Square/QrCode/ByteStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> $items Items
* @param array<int, Item> $items Items
*
* @return array<int, int> padded merged byte stream
*/
Expand All @@ -69,12 +66,7 @@ public function getByteStream(array $items): array
/**
* merge the bit stream
*
* @param array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> $items Items
* @param array<int, Item> $items Items
*
* @return array<int, int> bitstream
*/
Expand Down Expand Up @@ -177,19 +169,9 @@ protected function bitstreamToByte(array $bstream): array
/**
* convertData
*
* @param array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> $items Items
* @param array<int, Item> $items Items
*
* @return array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }>
* @return array<int, Item>
*/
protected function convertData(array $items): array
{
Expand Down Expand Up @@ -220,21 +202,11 @@ protected function convertData(array $items): array
/**
* Create BitStream
*
* @param array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> $items Items
* @param array<int, Item> $items Items
*
* @return array{
* 0: array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }>,
* 1: int,
* 0: array<int, Item>,
* 1: int,
* }
*/
protected function createBitStream(array $items): array
Expand All @@ -252,20 +224,10 @@ protected function createBitStream(array $items): array
/**
* Encode BitStream
*
* @param array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream'?: array<int, int>,
* } $inputitem Input item
* @param Item $inputitem Input item
* @param int $version Code version
*
* @return array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }
* @return Item
*/
public function encodeBitStream(array $inputitem, int $version): array
{
Expand Down
21 changes: 9 additions & 12 deletions src/Type/Square/QrCode/Estimate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string>,
* 'bstream': array<int, int>,
* }
*/
abstract class Estimate
{
Expand Down Expand Up @@ -129,12 +136,7 @@ public function estimateBitsModeKanji(int $size): int
/**
* Estimate version
*
* @param array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> $items Items
* @param array<int, Item> $items Items
* @param int $level Error correction level
*
* @return int version
Expand Down Expand Up @@ -182,12 +184,7 @@ protected function getMinimumVersion(int $size, int $level): int
/**
* estimateBitStreamSize
*
* @param array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> $items Items
* @param array<int, Item> $items Items
* @param int $version Code version
*
* @return int bits
Expand Down
2 changes: 1 addition & 1 deletion src/Type/Square/QrCode/Init.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ abstract class Init extends \Com\Tecnick\Barcode\Type\Square\QrCode\Mask
/**
* Frame
*
* @var array<int, array<int, string>>
* @var array<int, string>
*/
protected array $frame = [];

Expand Down
23 changes: 5 additions & 18 deletions src/Type/Square/QrCode/InputItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> $items Input items
* @param array<int, Item> $items Input items
* @param int $mode Encoding mode.
* @param int $size Size of data (byte).
* @param array<int, string> $data Array of input data.
*
* @return array<int, array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* }> items
* @return array<int, Item> items
*/
public function appendNewInputItem(
array $items,
Expand All @@ -84,12 +76,7 @@ public function appendNewInputItem(
* @param array<int, string> $data Array of input data.
* @param array<int, int> $bstream Binary stream
*
* @return array{
* 'mode': int,
* 'size': int,
* 'data': array<int, string>,
* 'bstream': array<int, int>,
* } input item
* @return Item input item
*/
protected function newInputItem(
int $mode,
Expand Down
19 changes: 13 additions & 6 deletions src/Type/Square/QrCode/Mask.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ abstract class Mask extends \Com\Tecnick\Barcode\Type\Square\QrCode\MaskNum
{
/**
* Run length
*
* @var array<int, int>
*/
protected array $runLength = [];

Expand Down Expand Up @@ -73,10 +75,10 @@ public function __construct(
* Get the best mask
*
* @param int $width Width
* @param array $frame Frame
* @param array<int, string> $frame Frame
* @param int $level Error Correction lLevel
*
* @return array best mask
* @return array<int, string> best mask
*/
protected function mask(
int $width,
Expand Down Expand Up @@ -118,11 +120,11 @@ protected function mask(
* Make a mask
*
* @param int $width Mask width
* @param array $frame Frame
* @param array<int, string> $frame Frame
* @param int $maskNo Mask number
* @param int $level Error Correction level
*
* @return array mask
* @return array<int, string> mask
*/
protected function makeMask(
int $width,
Expand All @@ -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<int, string> $frame Frame
* @param int $maskNo Mask number
* @param int $level Error Correction level
*
Expand Down Expand Up @@ -197,7 +199,7 @@ protected function writeFormatInformation(
* Evaluate Symbol and returns demerit value.
*
* @param int $width Width
* @param array $frame Frame
* @param array<int, string> $frame Frame
*/
protected function evaluateSymbol(int $width, array $frame): int
{
Expand Down Expand Up @@ -285,6 +287,8 @@ protected function evaluateSymbolB(
/**
* Calc N1 N3
*
* @param int $length Length
*
* @return int demerit
*/
protected function calcN1N3(int $length): int
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/Type/Square/QrCode/MaskNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, string> $frame Frame
* @param array<int, string> $mask Mask
*
* @return int mask number
*/
Expand Down Expand Up @@ -66,9 +66,9 @@ protected function makeMaskNo(
*
* @param int $maskNo Mask number
* @param int $width Width
* @param array $frame Frame
* @param array<int, string> $frame Frame
*
* @return array bit mask
* @return array<int, array<int, int>> bit mask
*/
protected function generateMaskNo(
int $maskNo,
Expand Down
18 changes: 15 additions & 3 deletions src/Type/Square/QrCode/Spec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
{
Expand Down
Loading

0 comments on commit cb7c534

Please sign in to comment.