From 9e26f05b0f7f46f9df37a78316cf1443f626ae4e Mon Sep 17 00:00:00 2001 From: Christopher Georg Date: Tue, 5 Mar 2024 17:20:35 +0100 Subject: [PATCH] feat: drop support for PHP < 8.1 allow PHPUnit 10/11, allow "spatie/phpunit-snapshot-assertions" 5 --- .github/workflows/ci.yml | 2 +- .gitignore | 1 + CHANGELOG.md | 9 +++ composer.json | 18 ++++-- phpunit.xml.dist | 18 ++++-- src/Common/BitArray.php | 16 ++---- src/Common/BitMatrix.php | 14 ++--- src/Common/CharacterSetEci.php | 14 ++--- src/Common/EcBlock.php | 18 +----- src/Common/EcBlocks.php | 12 +--- src/Common/ErrorCorrectionLevel.php | 8 +-- src/Common/FormatInformation.php | 11 +--- src/Common/Mode.php | 18 ++---- src/Common/ReedSolomonCodec.php | 34 ++++------- src/Common/Version.php | 16 ++---- src/Encoder/BlockPair.php | 26 ++------- src/Encoder/ByteMatrix.php | 20 +------ src/Encoder/Encoder.php | 11 ++-- src/Encoder/MaskUtil.php | 8 +-- src/Encoder/QrCode.php | 49 +++------------- src/Renderer/Color/Alpha.php | 15 +---- src/Renderer/Color/Cmyk.php | 33 ++--------- src/Renderer/Color/Gray.php | 9 +-- src/Renderer/Color/Rgb.php | 21 +------ src/Renderer/Eye/CompositeEye.php | 14 +---- src/Renderer/Eye/ModuleEye.php | 8 +-- src/Renderer/Eye/SimpleCircleEye.php | 5 +- src/Renderer/Eye/SquareEye.php | 5 +- src/Renderer/Image/EpsImageBackEnd.php | 5 +- src/Renderer/Image/ImagickImageBackEnd.php | 32 +++-------- src/Renderer/Image/SvgImageBackEnd.php | 26 +++------ src/Renderer/Image/TransformationMatrix.php | 2 +- src/Renderer/ImageRenderer.php | 18 ++---- src/Renderer/Module/DotsModule.php | 9 +-- src/Renderer/Module/EdgeIterator/Edge.php | 32 +++-------- .../Module/EdgeIterator/EdgeIterator.php | 17 ++---- src/Renderer/Module/RoundnessModule.php | 7 +-- src/Renderer/Module/SquareModule.php | 5 +- src/Renderer/Path/Close.php | 5 +- src/Renderer/Path/Curve.php | 46 +++------------ src/Renderer/Path/EllipticArc.php | 57 ++++--------------- src/Renderer/Path/Line.php | 14 +---- src/Renderer/Path/Move.php | 14 +---- src/Renderer/Path/Path.php | 4 +- src/Renderer/PlainTextRenderer.php | 8 +-- src/Renderer/RendererStyle/EyeFill.php | 23 ++------ src/Renderer/RendererStyle/Fill.php | 53 +++-------------- src/Renderer/RendererStyle/Gradient.php | 25 ++------ src/Renderer/RendererStyle/RendererStyle.php | 31 ++-------- src/Writer.php | 14 +---- test/Common/BitArrayTest.php | 42 ++------------ test/Common/ReedSolomonCodecTest.php | 7 +-- test/Common/VersionTest.php | 17 ++---- test/Encoder/EncoderTest.php | 17 +++--- test/Encoder/MaskUtilTest.php | 4 +- test/Encoder/MatrixUtilTest.php | 3 +- test/Integration/ImagickRenderingTest.php | 14 ++--- 57 files changed, 229 insertions(+), 755 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8679a6..726737c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -27,7 +27,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.4', '8.0', '8.1', '8.2'] + php-versions: ['8.1', '8.2', '8.3'] runs-on: ${{ matrix.operating-system }} steps: - uses: actions/checkout@v4 diff --git a/.gitignore b/.gitignore index eb0a8e7..9d5cbb4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /composer.lock /vendor /.phpunit.result.cache +/.phpunit.cache diff --git a/CHANGELOG.md b/CHANGELOG.md index 1139fee..26ce4c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 3.0.0 - 2022-03-14 + +### Changed + +- Add strong php Types +- Fix spelling of DEFAULT_BYTE_MODE_ENCODING => DEFAULT_BYTE_MODE_ENCODING +- Constructor names of BlockPair +- Drop support for PHP < 8.1 + ## 2.0.7 - 2022-03-14 ### Fixed diff --git a/composer.json b/composer.json index 7f193da..8c57a0f 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license" : "BSD-2-Clause", "homepage": "https://github.com/Bacon/BaconQrCode", "require": { - "php": "^7.1 || ^8.0", + "php": "^8.1", "ext-iconv": "*", "dasprid/enum": "^1.0.3" }, @@ -24,15 +24,21 @@ "BaconQrCode\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "BaconQrCodeTest\\": "test/" + } + }, "require-dev": { - "phpunit/phpunit": "^7 | ^8 | ^9", - "spatie/phpunit-snapshot-assertions": "^4.2.9", - "squizlabs/php_codesniffer": "^3.4", - "phly/keep-a-changelog": "^2.1" + "phpunit/phpunit": "^10.5.11 || 11.0.4", + "spatie/phpunit-snapshot-assertions": "^5.1.5", + "squizlabs/php_codesniffer": "^3.9", + "phly/keep-a-changelog": "^2.12" }, "config": { "allow-plugins": { - "ocramius/package-versions": true + "ocramius/package-versions": true, + "php-http/discovery": true } }, "archive": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index d9e4d57..4165b9d 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,19 @@ - - - - src - - + ./test + + + + src + + + diff --git a/src/Common/BitArray.php b/src/Common/BitArray.php index 158384f..9ec8629 100644 --- a/src/Common/BitArray.php +++ b/src/Common/BitArray.php @@ -16,21 +16,13 @@ final class BitArray * * @var SplFixedArray */ - private $bits; - - /** - * Size of the bit array in bits. - * - * @var int - */ - private $size; + private SplFixedArray $bits; /** * Creates a new bit array with a given size. */ - public function __construct(int $size = 0) + public function __construct(private int $size = 0) { - $this->size = $size; $this->bits = SplFixedArray::fromArray(array_fill(0, ($this->size + 31) >> 3, 0)); } @@ -107,7 +99,7 @@ public function getNextSet(int $from) : int } $result = ($bitsOffset << 5) + BitUtils::numberOfTrailingZeros($currentBits); - return $result > $this->size ? $this->size : $result; + return min($result, $this->size); } /** @@ -133,7 +125,7 @@ public function getNextUnset(int $from) : int } $result = ($bitsOffset << 5) + BitUtils::numberOfTrailingZeros($currentBits); - return $result > $this->size ? $this->size : $result; + return min($result, $this->size); } /** diff --git a/src/Common/BitMatrix.php b/src/Common/BitMatrix.php index 10bf8fe..fc0d1f1 100644 --- a/src/Common/BitMatrix.php +++ b/src/Common/BitMatrix.php @@ -17,31 +17,25 @@ class BitMatrix { /** * Width of the bit matrix. - * - * @var int */ - private $width; + private int $width; /** * Height of the bit matrix. - * - * @var int */ - private $height; + private ?int $height; /** * Size in bits of each individual row. - * - * @var int */ - private $rowSize; + private int $rowSize; /** * Bits representation. * * @var SplFixedArray */ - private $bits; + private SplFixedArray $bits; /** * @throws InvalidArgumentException if a dimension is smaller than zero diff --git a/src/Common/CharacterSetEci.php b/src/Common/CharacterSetEci.php index 9049ccb..8b62b8c 100644 --- a/src/Common/CharacterSetEci.php +++ b/src/Common/CharacterSetEci.php @@ -69,32 +69,26 @@ final class CharacterSetEci extends AbstractEnum protected const GB18030 = [[29], 'GB2312', 'EUC_CN', 'GBK']; protected const EUC_KR = [[30], 'EUC-KR']; - /** - * @var int[] - */ - private $values; - /** * @var string[] */ - private $otherEncodingNames; + private array $otherEncodingNames; /** * @var array|null */ - private static $valueToEci; + private static ?array $valueToEci; /** * @var array|null */ - private static $nameToEci; + private static ?array $nameToEci = null; /** * @param int[] $values */ - public function __construct(array $values, string ...$otherEncodingNames) + public function __construct(private readonly array $values, string ...$otherEncodingNames) { - $this->values = $values; $this->otherEncodingNames = $otherEncodingNames; } diff --git a/src/Common/EcBlock.php b/src/Common/EcBlock.php index a9a1d07..bc9e865 100644 --- a/src/Common/EcBlock.php +++ b/src/Common/EcBlock.php @@ -11,24 +11,8 @@ */ final class EcBlock { - /** - * How many times the block is used. - * - * @var int - */ - private $count; - - /** - * Number of data codewords. - * - * @var int - */ - private $dataCodewords; - - public function __construct(int $count, int $dataCodewords) + public function __construct(private readonly int $count, private readonly int $dataCodewords) { - $this->count = $count; - $this->dataCodewords = $dataCodewords; } /** diff --git a/src/Common/EcBlocks.php b/src/Common/EcBlocks.php index 172b5f2..63c52a9 100644 --- a/src/Common/EcBlocks.php +++ b/src/Common/EcBlocks.php @@ -12,23 +12,15 @@ */ final class EcBlocks { - /** - * Number of EC codewords per block. - * - * @var int - */ - private $ecCodewordsPerBlock; - /** * List of EC blocks. * * @var EcBlock[] */ - private $ecBlocks; + private array $ecBlocks; - public function __construct(int $ecCodewordsPerBlock, EcBlock ...$ecBlocks) + public function __construct(private readonly int $ecCodewordsPerBlock, EcBlock ...$ecBlocks) { - $this->ecCodewordsPerBlock = $ecCodewordsPerBlock; $this->ecBlocks = $ecBlocks; } diff --git a/src/Common/ErrorCorrectionLevel.php b/src/Common/ErrorCorrectionLevel.php index 9bbf440..ac84d66 100644 --- a/src/Common/ErrorCorrectionLevel.php +++ b/src/Common/ErrorCorrectionLevel.php @@ -21,14 +21,8 @@ final class ErrorCorrectionLevel extends AbstractEnum protected const Q = [0x03]; protected const H = [0x02]; - /** - * @var int - */ - private $bits; - - protected function __construct(int $bits) + protected function __construct(private readonly int $bits) { - $this->bits = $bits; } /** diff --git a/src/Common/FormatInformation.php b/src/Common/FormatInformation.php index 38295fc..6a5da0b 100644 --- a/src/Common/FormatInformation.php +++ b/src/Common/FormatInformation.php @@ -68,17 +68,10 @@ class FormatInformation /** * Error correction level. - * - * @var ErrorCorrectionLevel */ - private $ecLevel; + private ErrorCorrectionLevel $ecLevel; - /** - * Data mask. - * - * @var int - */ - private $dataMask; + private int $dataMask; protected function __construct(int $formatInfo) { diff --git a/src/Common/Mode.php b/src/Common/Mode.php index af5a113..f5fb153 100644 --- a/src/Common/Mode.php +++ b/src/Common/Mode.php @@ -32,23 +32,13 @@ final class Mode extends AbstractEnum protected const FNC1_SECOND_POSITION = [[0, 0, 0], 0x09]; protected const HANZI = [[8, 10, 12], 0x0d]; - /** - * @var int[] - */ - private $characterCountBitsForVersions; - - /** - * @var int - */ - private $bits; - /** * @param int[] $characterCountBitsForVersions */ - protected function __construct(array $characterCountBitsForVersions, int $bits) - { - $this->characterCountBitsForVersions = $characterCountBitsForVersions; - $this->bits = $bits; + protected function __construct( + private readonly array $characterCountBitsForVersions, + private readonly int $bits + ) { } /** diff --git a/src/Common/ReedSolomonCodec.php b/src/Common/ReedSolomonCodec.php index a5aad0b..31d8030 100644 --- a/src/Common/ReedSolomonCodec.php +++ b/src/Common/ReedSolomonCodec.php @@ -16,73 +16,59 @@ final class ReedSolomonCodec { /** * Symbol size in bits. - * - * @var int */ - private $symbolSize; + private int $symbolSize; /** * Block size in symbols. - * - * @var int */ - private $blockSize; + private int $blockSize; /** * First root of RS code generator polynomial, index form. - * - * @var int */ - private $firstRoot; + private int $firstRoot; /** * Primitive element to generate polynomial roots, index form. - * - * @var int */ - private $primitive; + private int $primitive; /** * Prim-th root of 1, index form. - * - * @var int */ - private $iPrimitive; + private int $iPrimitive; /** * RS code generator polynomial degree (number of roots). - * - * @var int */ - private $numRoots; + private int $numRoots; /** * Padding bytes at front of shortened block. - * - * @var int */ - private $padding; + private int $padding; /** * Log lookup table. * * @var SplFixedArray */ - private $alphaTo; + private SplFixedArray $alphaTo; /** * Anti-Log lookup table. * * @var SplFixedArray */ - private $indexOf; + private SplFixedArray $indexOf; /** * Generator polynomial. * * @var SplFixedArray */ - private $generatorPoly; + private SplFixedArray $generatorPoly; /** * @throws InvalidArgumentException if symbol size ist not between 0 and 8 diff --git a/src/Common/Version.php b/src/Common/Version.php index 4e9d7c6..68d3d16 100644 --- a/src/Common/Version.php +++ b/src/Common/Version.php @@ -50,38 +50,34 @@ final class Version /** * Version number of this version. - * - * @var int */ - private $versionNumber; + private int $versionNumber; /** * Alignment pattern centers. * - * @var SplFixedArray + * @var SplFixedArray|array */ - private $alignmentPatternCenters; + private SplFixedArray|array $alignmentPatternCenters; /** * Error correction blocks. * * @var EcBlocks[] */ - private $ecBlocks; + private array $ecBlocks; /** * Total number of codewords. - * - * @var int */ - private $totalCodewords; + private null|int|float $totalCodewords; /** * Cached version instances. * * @var array|null */ - private static $versions; + private static ?array $versions = null; /** * @param int[] $alignmentPatternCenters diff --git a/src/Encoder/BlockPair.php b/src/Encoder/BlockPair.php index be54afa..b1dc5c4 100644 --- a/src/Encoder/BlockPair.php +++ b/src/Encoder/BlockPair.php @@ -10,30 +10,16 @@ */ final class BlockPair { - /** - * Data bytes in the block. - * - * @var SplFixedArray - */ - private $dataBytes; - - /** - * Error correction bytes in the block. - * - * @var SplFixedArray - */ - private $errorCorrectionBytes; - /** * Creates a new block pair. * - * @param SplFixedArray $data - * @param SplFixedArray $errorCorrection + * @param SplFixedArray $dataBytes Data bytes in the block. + * @param SplFixedArray $errorCorrectionBytes Error correction bytes in the block. */ - public function __construct(SplFixedArray $data, SplFixedArray $errorCorrection) - { - $this->dataBytes = $data; - $this->errorCorrectionBytes = $errorCorrection; + public function __construct( + private readonly SplFixedArray $dataBytes, + private readonly SplFixedArray $errorCorrectionBytes + ) { } /** diff --git a/src/Encoder/ByteMatrix.php b/src/Encoder/ByteMatrix.php index b58cc0a..eefcf1c 100644 --- a/src/Encoder/ByteMatrix.php +++ b/src/Encoder/ByteMatrix.php @@ -16,26 +16,10 @@ final class ByteMatrix * * @var SplFixedArray> */ - private $bytes; + private SplFixedArray $bytes; - /** - * Width of the matrix. - * - * @var int - */ - private $width; - - /** - * Height of the matrix. - * - * @var int - */ - private $height; - - public function __construct(int $width, int $height) + public function __construct(private readonly int $width, private readonly int $height) { - $this->height = $height; - $this->width = $width; $this->bytes = new SplFixedArray($height); for ($y = 0; $y < $height; ++$y) { diff --git a/src/Encoder/Encoder.php b/src/Encoder/Encoder.php index ff535d0..97369fc 100644 --- a/src/Encoder/Encoder.php +++ b/src/Encoder/Encoder.php @@ -20,7 +20,10 @@ final class Encoder /** * Default byte encoding. */ - public const DEFAULT_BYTE_MODE_ECODING = 'ISO-8859-1'; + public const DEFAULT_BYTE_MODE_ENCODING = 'ISO-8859-1'; + + /** @deprecated use DEFAULT_BYTE_MODE_ENCODING */ + public const DEFAULT_BYTE_MODE_ECODING = self::DEFAULT_BYTE_MODE_ENCODING; /** * The original table is defined in the table 5 of JISX0510:2004 (p.19). @@ -39,7 +42,7 @@ final class Encoder * * @var array */ - private static $codecs = []; + private static array $codecs = []; /** * Encodes "content" with the error correction level "ecLevel". @@ -47,7 +50,7 @@ final class Encoder public static function encode( string $content, ErrorCorrectionLevel $ecLevel, - string $encoding = self::DEFAULT_BYTE_MODE_ECODING, + string $encoding = self::DEFAULT_BYTE_MODE_ENCODING, ?Version $forcedVersion = null, // Barcode scanner might not be able to read the encoded message of the QR code with the prefix ECI of UTF-8 bool $prefixEci = true @@ -62,7 +65,7 @@ public static function encode( $headerBits = new BitArray(); // Append ECI segment if applicable - if ($prefixEci && Mode::BYTE() === $mode && self::DEFAULT_BYTE_MODE_ECODING !== $encoding) { + if ($prefixEci && Mode::BYTE() === $mode && self::DEFAULT_BYTE_MODE_ENCODING !== $encoding) { $eci = CharacterSetEci::getCharacterSetEciByName($encoding); if (null !== $eci) { diff --git a/src/Encoder/MaskUtil.php b/src/Encoder/MaskUtil.php index ba97dfb..54a07ba 100644 --- a/src/Encoder/MaskUtil.php +++ b/src/Encoder/MaskUtil.php @@ -14,10 +14,10 @@ final class MaskUtil /**#@+ * Penalty weights from section 6.8.2.1 */ - const N1 = 3; - const N2 = 3; - const N3 = 40; - const N4 = 10; + public const N1 = 3; + public const N2 = 3; + public const N3 = 40; + public const N4 = 10; /**#@-*/ private function __construct() diff --git a/src/Encoder/QrCode.php b/src/Encoder/QrCode.php index f568e88..c3398f4 100644 --- a/src/Encoder/QrCode.php +++ b/src/Encoder/QrCode.php @@ -17,51 +17,23 @@ final class QrCode */ public const NUM_MASK_PATTERNS = 8; - /** - * Mode of the QR code. - * - * @var Mode - */ - private $mode; - - /** - * EC level of the QR code. - * - * @var ErrorCorrectionLevel - */ - private $errorCorrectionLevel; - - /** - * Version of the QR code. - * - * @var Version - */ - private $version; - /** * Mask pattern of the QR code. - * - * @var int */ - private $maskPattern = -1; + private int $maskPattern = -1; /** * Matrix of the QR code. - * - * @var ByteMatrix */ - private $matrix; + private ByteMatrix $matrix; public function __construct( - Mode $mode, - ErrorCorrectionLevel $errorCorrectionLevel, - Version $version, - int $maskPattern, - ByteMatrix $matrix + private readonly Mode $mode, + private readonly ErrorCorrectionLevel $errorCorrectionLevel, + private readonly Version $version, + int $maskPattern, + ByteMatrix $matrix ) { - $this->mode = $mode; - $this->errorCorrectionLevel = $errorCorrectionLevel; - $this->version = $version; $this->maskPattern = $maskPattern; $this->matrix = $matrix; } @@ -98,12 +70,7 @@ public function getMaskPattern() : int return $this->maskPattern; } - /** - * Gets the matrix. - * - * @return ByteMatrix - */ - public function getMatrix() + public function getMatrix(): ByteMatrix { return $this->matrix; } diff --git a/src/Renderer/Color/Alpha.php b/src/Renderer/Color/Alpha.php index 3490252..067a554 100644 --- a/src/Renderer/Color/Alpha.php +++ b/src/Renderer/Color/Alpha.php @@ -7,27 +7,14 @@ final class Alpha implements ColorInterface { - /** - * @var int - */ - private $alpha; - - /** - * @var ColorInterface - */ - private $baseColor; - /** * @param int $alpha the alpha value, 0 to 100 */ - public function __construct(int $alpha, ColorInterface $baseColor) + public function __construct(private readonly int $alpha, private readonly ColorInterface $baseColor) { if ($alpha < 0 || $alpha > 100) { throw new Exception\InvalidArgumentException('Alpha must be between 0 and 100'); } - - $this->alpha = $alpha; - $this->baseColor = $baseColor; } public function getAlpha() : int diff --git a/src/Renderer/Color/Cmyk.php b/src/Renderer/Color/Cmyk.php index d6de390..d028210 100644 --- a/src/Renderer/Color/Cmyk.php +++ b/src/Renderer/Color/Cmyk.php @@ -7,34 +7,18 @@ final class Cmyk implements ColorInterface { - /** - * @var int - */ - private $cyan; - - /** - * @var int - */ - private $magenta; - - /** - * @var int - */ - private $yellow; - - /** - * @var int - */ - private $black; - /** * @param int $cyan the cyan amount, 0 to 100 * @param int $magenta the magenta amount, 0 to 100 * @param int $yellow the yellow amount, 0 to 100 * @param int $black the black amount, 0 to 100 */ - public function __construct(int $cyan, int $magenta, int $yellow, int $black) - { + public function __construct( + private readonly int $cyan, + private readonly int $magenta, + private readonly int $yellow, + private readonly int $black + ) { if ($cyan < 0 || $cyan > 100) { throw new Exception\InvalidArgumentException('Cyan must be between 0 and 100'); } @@ -50,11 +34,6 @@ public function __construct(int $cyan, int $magenta, int $yellow, int $black) if ($black < 0 || $black > 100) { throw new Exception\InvalidArgumentException('Black must be between 0 and 100'); } - - $this->cyan = $cyan; - $this->magenta = $magenta; - $this->yellow = $yellow; - $this->black = $black; } public function getCyan() : int diff --git a/src/Renderer/Color/Gray.php b/src/Renderer/Color/Gray.php index acb986d..76603e4 100644 --- a/src/Renderer/Color/Gray.php +++ b/src/Renderer/Color/Gray.php @@ -7,21 +7,14 @@ final class Gray implements ColorInterface { - /** - * @var int - */ - private $gray; - /** * @param int $gray the gray value between 0 (black) and 100 (white) */ - public function __construct(int $gray) + public function __construct(private readonly int $gray) { if ($gray < 0 || $gray > 100) { throw new Exception\InvalidArgumentException('Gray must be between 0 and 100'); } - - $this->gray = (int) $gray; } public function getGray() : int diff --git a/src/Renderer/Color/Rgb.php b/src/Renderer/Color/Rgb.php index 7935406..6dcb632 100644 --- a/src/Renderer/Color/Rgb.php +++ b/src/Renderer/Color/Rgb.php @@ -7,27 +7,12 @@ final class Rgb implements ColorInterface { - /** - * @var int - */ - private $red; - - /** - * @var int - */ - private $green; - - /** - * @var int - */ - private $blue; - /** * @param int $red the red amount of the color, 0 to 255 * @param int $green the green amount of the color, 0 to 255 * @param int $blue the blue amount of the color, 0 to 255 */ - public function __construct(int $red, int $green, int $blue) + public function __construct(private readonly int $red, private readonly int $green, private readonly int $blue) { if ($red < 0 || $red > 255) { throw new Exception\InvalidArgumentException('Red must be between 0 and 255'); @@ -40,10 +25,6 @@ public function __construct(int $red, int $green, int $blue) if ($blue < 0 || $blue > 255) { throw new Exception\InvalidArgumentException('Blue must be between 0 and 255'); } - - $this->red = $red; - $this->green = $green; - $this->blue = $blue; } public function getRed() : int diff --git a/src/Renderer/Eye/CompositeEye.php b/src/Renderer/Eye/CompositeEye.php index 0d03125..379e5c7 100644 --- a/src/Renderer/Eye/CompositeEye.php +++ b/src/Renderer/Eye/CompositeEye.php @@ -10,20 +10,8 @@ */ final class CompositeEye implements EyeInterface { - /** - * @var EyeInterface - */ - private $externalEye; - - /** - * @var EyeInterface - */ - private $internalEye; - - public function __construct(EyeInterface $externalEye, EyeInterface $internalEye) + public function __construct(private readonly EyeInterface $externalEye, private readonly EyeInterface $internalEye) { - $this->externalEye = $externalEye; - $this->internalEye = $internalEye; } public function getExternalPath() : Path diff --git a/src/Renderer/Eye/ModuleEye.php b/src/Renderer/Eye/ModuleEye.php index 84f7d12..a8a3489 100644 --- a/src/Renderer/Eye/ModuleEye.php +++ b/src/Renderer/Eye/ModuleEye.php @@ -12,14 +12,8 @@ */ final class ModuleEye implements EyeInterface { - /** - * @var ModuleInterface - */ - private $module; - - public function __construct(ModuleInterface $module) + public function __construct(private readonly ModuleInterface $module) { - $this->module = $module; } public function getExternalPath() : Path diff --git a/src/Renderer/Eye/SimpleCircleEye.php b/src/Renderer/Eye/SimpleCircleEye.php index 64d54ee..735d326 100644 --- a/src/Renderer/Eye/SimpleCircleEye.php +++ b/src/Renderer/Eye/SimpleCircleEye.php @@ -10,10 +10,7 @@ */ final class SimpleCircleEye implements EyeInterface { - /** - * @var self|null - */ - private static $instance; + private static ?SimpleCircleEye $instance = null; private function __construct() { diff --git a/src/Renderer/Eye/SquareEye.php b/src/Renderer/Eye/SquareEye.php index a3892b4..09bedfe 100644 --- a/src/Renderer/Eye/SquareEye.php +++ b/src/Renderer/Eye/SquareEye.php @@ -10,10 +10,7 @@ */ final class SquareEye implements EyeInterface { - /** - * @var self|null - */ - private static $instance; + private static ?SquareEye $instance = null; private function __construct() { diff --git a/src/Renderer/Image/EpsImageBackEnd.php b/src/Renderer/Image/EpsImageBackEnd.php index b581b54..4269456 100644 --- a/src/Renderer/Image/EpsImageBackEnd.php +++ b/src/Renderer/Image/EpsImageBackEnd.php @@ -22,10 +22,7 @@ final class EpsImageBackEnd implements ImageBackEndInterface { private const PRECISION = 3; - /** - * @var string|null - */ - private $eps; + private ?string $eps; public function new(int $size, ColorInterface $backgroundColor) : void { diff --git a/src/Renderer/Image/ImagickImageBackEnd.php b/src/Renderer/Image/ImagickImageBackEnd.php index adec85e..a16a663 100644 --- a/src/Renderer/Image/ImagickImageBackEnd.php +++ b/src/Renderer/Image/ImagickImageBackEnd.php @@ -23,40 +23,22 @@ final class ImagickImageBackEnd implements ImageBackEndInterface { - /** - * @var string - */ - private $imageFormat; + private string $imageFormat; - /** - * @var int - */ - private $compressionQuality; + private int $compressionQuality; - /** - * @var Imagick|null - */ - private $image; + private ?Imagick $image; - /** - * @var ImagickDraw|null - */ - private $draw; + private ?ImagickDraw $draw; - /** - * @var int|null - */ - private $gradientCount; + private ?int $gradientCount; /** * @var TransformationMatrix[]|null */ - private $matrices; + private ?array $matrices; - /** - * @var int|null - */ - private $matrixIndex; + private ?int $matrixIndex; public function __construct(string $imageFormat = 'png', int $compressionQuality = 100) { diff --git a/src/Renderer/Image/SvgImageBackEnd.php b/src/Renderer/Image/SvgImageBackEnd.php index cb37a9f..9fb4bcb 100644 --- a/src/Renderer/Image/SvgImageBackEnd.php +++ b/src/Renderer/Image/SvgImageBackEnd.php @@ -20,25 +20,13 @@ final class SvgImageBackEnd implements ImageBackEndInterface { private const PRECISION = 3; - /** - * @var XMLWriter|null - */ - private $xmlWriter; - - /** - * @var int[]|null - */ - private $stack; - - /** - * @var int|null - */ - private $currentStack; - - /** - * @var int|null - */ - private $gradientCount; + private ?XMLWriter $xmlWriter; + + private ?array $stack; + + private ?int $currentStack; + + private ?int $gradientCount; public function __construct() { diff --git a/src/Renderer/Image/TransformationMatrix.php b/src/Renderer/Image/TransformationMatrix.php index 7e88da6..9b435a0 100644 --- a/src/Renderer/Image/TransformationMatrix.php +++ b/src/Renderer/Image/TransformationMatrix.php @@ -8,7 +8,7 @@ final class TransformationMatrix /** * @var float[] */ - private $values; + private array $values; public function __construct() { diff --git a/src/Renderer/ImageRenderer.php b/src/Renderer/ImageRenderer.php index ab16276..b77be50 100644 --- a/src/Renderer/ImageRenderer.php +++ b/src/Renderer/ImageRenderer.php @@ -13,20 +13,10 @@ final class ImageRenderer implements RendererInterface { - /** - * @var RendererStyle - */ - private $rendererStyle; - - /** - * @var ImageBackEndInterface - */ - private $imageBackEnd; - - public function __construct(RendererStyle $rendererStyle, ImageBackEndInterface $imageBackEnd) - { - $this->rendererStyle = $rendererStyle; - $this->imageBackEnd = $imageBackEnd; + public function __construct( + private readonly RendererStyle $rendererStyle, + private readonly ImageBackEndInterface $imageBackEnd + ) { } /** diff --git a/src/Renderer/Module/DotsModule.php b/src/Renderer/Module/DotsModule.php index f536e5a..c5d5c6f 100644 --- a/src/Renderer/Module/DotsModule.php +++ b/src/Renderer/Module/DotsModule.php @@ -16,18 +16,11 @@ final class DotsModule implements ModuleInterface public const MEDIUM = .8; public const SMALL = .6; - /** - * @var float - */ - private $size; - - public function __construct(float $size) + public function __construct(private readonly float $size) { if ($size <= 0 || $size > 1) { throw new InvalidArgumentException('Size must between 0 (exclusive) and 1 (inclusive)'); } - - $this->size = $size; } public function createPath(ByteMatrix $matrix) : Path diff --git a/src/Renderer/Module/EdgeIterator/Edge.php b/src/Renderer/Module/EdgeIterator/Edge.php index 90482f2..141d66c 100644 --- a/src/Renderer/Module/EdgeIterator/Edge.php +++ b/src/Renderer/Module/EdgeIterator/Edge.php @@ -5,44 +5,26 @@ final class Edge { - /** - * @var bool - */ - private $positive; - /** * @var array */ - private $points = []; + private array $points = []; /** * @var array|null */ - private $simplifiedPoints; + private ?array $simplifiedPoints = null; - /** - * @var int - */ - private $minX = PHP_INT_MAX; + private int $minX = PHP_INT_MAX; - /** - * @var int - */ - private $minY = PHP_INT_MAX; + private int $minY = PHP_INT_MAX; - /** - * @var int - */ - private $maxX = -1; + private int $maxX = -1; - /** - * @var int - */ - private $maxY = -1; + private int $maxY = -1; - public function __construct(bool $positive) + public function __construct(private readonly bool $positive) { - $this->positive = $positive; } public function addPoint(int $x, int $y) : void diff --git a/src/Renderer/Module/EdgeIterator/EdgeIterator.php b/src/Renderer/Module/EdgeIterator/EdgeIterator.php index eb29dc6..01f692c 100644 --- a/src/Renderer/Module/EdgeIterator/EdgeIterator.php +++ b/src/Renderer/Module/EdgeIterator/EdgeIterator.php @@ -15,22 +15,13 @@ final class EdgeIterator implements IteratorAggregate /** * @var int[] */ - private $bytes = []; + private array $bytes = []; - /** - * @var int - */ - private $size; + private ?int $size; - /** - * @var int - */ - private $width; + private int $width; - /** - * @var int - */ - private $height; + private int $height; public function __construct(ByteMatrix $matrix) { diff --git a/src/Renderer/Module/RoundnessModule.php b/src/Renderer/Module/RoundnessModule.php index 01b83c6..c730b37 100644 --- a/src/Renderer/Module/RoundnessModule.php +++ b/src/Renderer/Module/RoundnessModule.php @@ -17,12 +17,7 @@ final class RoundnessModule implements ModuleInterface public const MEDIUM = .5; public const SOFT = .25; - /** - * @var float - */ - private $intensity; - - public function __construct(float $intensity) + public function __construct(private float $intensity) { if ($intensity <= 0 || $intensity > 1) { throw new InvalidArgumentException('Intensity must between 0 (exclusive) and 1 (inclusive)'); diff --git a/src/Renderer/Module/SquareModule.php b/src/Renderer/Module/SquareModule.php index 9ab4607..8cf1d0b 100644 --- a/src/Renderer/Module/SquareModule.php +++ b/src/Renderer/Module/SquareModule.php @@ -12,10 +12,7 @@ */ final class SquareModule implements ModuleInterface { - /** - * @var self|null - */ - private static $instance; + private static ?SquareModule $instance = null; private function __construct() { diff --git a/src/Renderer/Path/Close.php b/src/Renderer/Path/Close.php index b07feb0..2fc71c4 100644 --- a/src/Renderer/Path/Close.php +++ b/src/Renderer/Path/Close.php @@ -5,10 +5,7 @@ final class Close implements OperationInterface { - /** - * @var self|null - */ - private static $instance; + private static ?Close $instance = null; private function __construct() { diff --git a/src/Renderer/Path/Curve.php b/src/Renderer/Path/Curve.php index c067c74..9dc13bd 100644 --- a/src/Renderer/Path/Curve.php +++ b/src/Renderer/Path/Curve.php @@ -5,44 +5,14 @@ final class Curve implements OperationInterface { - /** - * @var float - */ - private $x1; - - /** - * @var float - */ - private $y1; - - /** - * @var float - */ - private $x2; - - /** - * @var float - */ - private $y2; - - /** - * @var float - */ - private $x3; - - /** - * @var float - */ - private $y3; - - public function __construct(float $x1, float $y1, float $x2, float $y2, float $x3, float $y3) - { - $this->x1 = $x1; - $this->y1 = $y1; - $this->x2 = $x2; - $this->y2 = $y2; - $this->x3 = $x3; - $this->y3 = $y3; + public function __construct( + private readonly float $x1, + private readonly float $y1, + private readonly float $x2, + private readonly float $y2, + private readonly float $x3, + private readonly float $y3 + ) { } public function getX1() : float diff --git a/src/Renderer/Path/EllipticArc.php b/src/Renderer/Path/EllipticArc.php index 9f2385a..f64b5f9 100644 --- a/src/Renderer/Path/EllipticArc.php +++ b/src/Renderer/Path/EllipticArc.php @@ -7,57 +7,22 @@ final class EllipticArc implements OperationInterface { private const ZERO_TOLERANCE = 1e-05; - /** - * @var float - */ - private $xRadius; - - /** - * @var float - */ - private $yRadius; - - /** - * @var float - */ - private $xAxisAngle; - - /** - * @var bool - */ - private $largeArc; - - /** - * @var bool - */ - private $sweep; - - /** - * @var float - */ - private $x; - - /** - * @var float - */ - private $y; + private float $xRadius; + private float $yRadius; + private float $xAxisAngle; public function __construct( - float $xRadius, - float $yRadius, - float $xAxisAngle, - bool $largeArc, - bool $sweep, - float $x, - float $y + float $xRadius, + float $yRadius, + float $xAxisAngle, + private readonly bool $largeArc, + private readonly bool $sweep, + private readonly float $x, + private readonly float $y ) { $this->xRadius = abs($xRadius); $this->yRadius = abs($yRadius); $this->xAxisAngle = $xAxisAngle % 360; - $this->largeArc = $largeArc; - $this->sweep = $sweep; - $this->x = $x; - $this->y = $y; } public function getXRadius() : float @@ -179,7 +144,7 @@ private function createCurves(float $fromX, float $fromY) : array /** * @return float[] */ - private function calculateCenterPointParameters(float $fromX, float $fromY, float $xAngle) + private function calculateCenterPointParameters(float $fromX, float $fromY, float $xAngle): array { $rX = $this->xRadius; $rY = $this->yRadius; diff --git a/src/Renderer/Path/Line.php b/src/Renderer/Path/Line.php index 3149a39..c9b04fe 100644 --- a/src/Renderer/Path/Line.php +++ b/src/Renderer/Path/Line.php @@ -5,20 +5,8 @@ final class Line implements OperationInterface { - /** - * @var float - */ - private $x; - - /** - * @var float - */ - private $y; - - public function __construct(float $x, float $y) + public function __construct(private readonly float $x, private readonly float $y) { - $this->x = $x; - $this->y = $y; } public function getX() : float diff --git a/src/Renderer/Path/Move.php b/src/Renderer/Path/Move.php index 481d0dd..e396c2c 100644 --- a/src/Renderer/Path/Move.php +++ b/src/Renderer/Path/Move.php @@ -5,20 +5,8 @@ final class Move implements OperationInterface { - /** - * @var float - */ - private $x; - - /** - * @var float - */ - private $y; - - public function __construct(float $x, float $y) + public function __construct(private readonly float $x, private readonly float $y) { - $this->x = $x; - $this->y = $y; } public function getX() : float diff --git a/src/Renderer/Path/Path.php b/src/Renderer/Path/Path.php index 8e5e298..335b9e5 100644 --- a/src/Renderer/Path/Path.php +++ b/src/Renderer/Path/Path.php @@ -14,7 +14,7 @@ final class Path implements IteratorAggregate /** * @var OperationInterface[] */ - private $operations = []; + private array $operations = []; /** * Moves the drawing operation to a certain position. @@ -95,7 +95,7 @@ public function translate(float $x, float $y) : self } /** - * @return OperationInterface[]|Traversable + * @return Traversable */ public function getIterator() : Traversable { diff --git a/src/Renderer/PlainTextRenderer.php b/src/Renderer/PlainTextRenderer.php index 8aa7652..219bbf3 100644 --- a/src/Renderer/PlainTextRenderer.php +++ b/src/Renderer/PlainTextRenderer.php @@ -28,14 +28,8 @@ final class PlainTextRenderer implements RendererInterface */ private const EMPTY_BLOCK = "\xc2\xa0"; - /** - * @var int - */ - private $margin; - - public function __construct(int $margin = 2) + public function __construct(private readonly int $margin = 2) { - $this->margin = $margin; } /** diff --git a/src/Renderer/RendererStyle/EyeFill.php b/src/Renderer/RendererStyle/EyeFill.php index 46abc22..9953b55 100644 --- a/src/Renderer/RendererStyle/EyeFill.php +++ b/src/Renderer/RendererStyle/EyeFill.php @@ -8,25 +8,12 @@ final class EyeFill { - /** - * @var ColorInterface|null - */ - private $externalColor; + private static ?EyeFill $inherit = null; - /** - * @var ColorInterface|null - */ - private $internalColor; - - /** - * @var self|null - */ - private static $inherit; - - public function __construct(?ColorInterface $externalColor, ?ColorInterface $internalColor) - { - $this->externalColor = $externalColor; - $this->internalColor = $internalColor; + public function __construct( + private readonly ?ColorInterface $externalColor, + private readonly ?ColorInterface $internalColor + ) { } public static function uniform(ColorInterface $color) : self diff --git a/src/Renderer/RendererStyle/Fill.php b/src/Renderer/RendererStyle/Fill.php index d54268e..19de25d 100644 --- a/src/Renderer/RendererStyle/Fill.php +++ b/src/Renderer/RendererStyle/Fill.php @@ -9,55 +9,16 @@ final class Fill { - /** - * @var ColorInterface - */ - private $backgroundColor; - - /** - * @var ColorInterface|null - */ - private $foregroundColor; - - /** - * @var Gradient|null - */ - private $foregroundGradient; - - /** - * @var EyeFill - */ - private $topLeftEyeFill; - - /** - * @var EyeFill - */ - private $topRightEyeFill; - - /** - * @var EyeFill - */ - private $bottomLeftEyeFill; - - /** - * @var self|null - */ - private static $default; + private static ?Fill $default = null; private function __construct( - ColorInterface $backgroundColor, - ?ColorInterface $foregroundColor, - ?Gradient $foregroundGradient, - EyeFill $topLeftEyeFill, - EyeFill $topRightEyeFill, - EyeFill $bottomLeftEyeFill + private readonly ColorInterface $backgroundColor, + private readonly ?ColorInterface $foregroundColor, + private readonly ?Gradient $foregroundGradient, + private readonly EyeFill $topLeftEyeFill, + private readonly EyeFill $topRightEyeFill, + private readonly EyeFill $bottomLeftEyeFill ) { - $this->backgroundColor = $backgroundColor; - $this->foregroundColor = $foregroundColor; - $this->foregroundGradient = $foregroundGradient; - $this->topLeftEyeFill = $topLeftEyeFill; - $this->topRightEyeFill = $topRightEyeFill; - $this->bottomLeftEyeFill = $bottomLeftEyeFill; } public static function default() : self diff --git a/src/Renderer/RendererStyle/Gradient.php b/src/Renderer/RendererStyle/Gradient.php index 3813dfd..eea4031 100644 --- a/src/Renderer/RendererStyle/Gradient.php +++ b/src/Renderer/RendererStyle/Gradient.php @@ -7,26 +7,11 @@ final class Gradient { - /** - * @var ColorInterface - */ - private $startColor; - - /** - * @var ColorInterface - */ - private $endColor; - - /** - * @var GradientType - */ - private $type; - - public function __construct(ColorInterface $startColor, ColorInterface $endColor, GradientType $type) - { - $this->startColor = $startColor; - $this->endColor = $endColor; - $this->type = $type; + public function __construct( + private readonly ColorInterface $startColor, + private readonly ColorInterface $endColor, + private readonly GradientType $type + ) { } public function getStartColor() : ColorInterface diff --git a/src/Renderer/RendererStyle/RendererStyle.php b/src/Renderer/RendererStyle/RendererStyle.php index e03e099..aa963ff 100644 --- a/src/Renderer/RendererStyle/RendererStyle.php +++ b/src/Renderer/RendererStyle/RendererStyle.php @@ -10,40 +10,19 @@ final class RendererStyle { - /** - * @var int - */ - private $size; + private ModuleInterface $module; - /** - * @var int - */ - private $margin; + private EyeInterface|null $eye; - /** - * @var ModuleInterface - */ - private $module; - - /** - * @var EyeInterface|null - */ - private $eye; - - /** - * @var Fill - */ - private $fill; + private Fill $fill; public function __construct( - int $size, - int $margin = 4, + private int $size, + private int $margin = 4, ?ModuleInterface $module = null, ?EyeInterface $eye = null, ?Fill $fill = null ) { - $this->margin = $margin; - $this->size = $size; $this->module = $module ?: SquareModule::instance(); $this->eye = $eye ?: new ModuleEye($this->module); $this->fill = $fill ?: Fill::default(); diff --git a/src/Writer.php b/src/Writer.php index d5bdc5c..d7f7ebb 100644 --- a/src/Writer.php +++ b/src/Writer.php @@ -14,19 +14,11 @@ */ final class Writer { - /** - * Renderer instance. - * - * @var RendererInterface - */ - private $renderer; - /** * Creates a new writer with a specific renderer. */ - public function __construct(RendererInterface $renderer) + public function __construct(private readonly RendererInterface $renderer) { - $this->renderer = $renderer; } /** @@ -39,7 +31,7 @@ public function __construct(RendererInterface $renderer) */ public function writeString( string $content, - string $encoding = Encoder::DEFAULT_BYTE_MODE_ECODING, + string $encoding = Encoder::DEFAULT_BYTE_MODE_ENCODING, ?ErrorCorrectionLevel $ecLevel = null, ?Version $forcedVersion = null ) : string { @@ -62,7 +54,7 @@ public function writeString( public function writeFile( string $content, string $filename, - string $encoding = Encoder::DEFAULT_BYTE_MODE_ECODING, + string $encoding = Encoder::DEFAULT_BYTE_MODE_ENCODING, ?ErrorCorrectionLevel $ecLevel = null, ?Version $forcedVersion = null ) : void { diff --git a/test/Common/BitArrayTest.php b/test/Common/BitArrayTest.php index add798b..84aefc2 100644 --- a/test/Common/BitArrayTest.php +++ b/test/Common/BitArrayTest.php @@ -5,15 +5,9 @@ use BaconQrCode\Common\BitArray; use PHPUnit\Framework\TestCase; -use PHPUnit\Runner\Version as PHPUnitVersion; final class BitArrayTest extends TestCase { - private function getPhpUnitMajorVersion(): int - { - return (int) explode('.', PHPUnitVersion::id())[0]; - } - public function testGetSet() : void { $array = new BitArray(33); @@ -30,21 +24,13 @@ public function testGetNextSet1() : void $array = new BitArray(32); for ($i = 0; $i < $array->getSize(); ++$i) { - if ($this->getPhpUnitMajorVersion() === 7) { - $this->assertEquals($i, 32, '', $array->getNextSet($i)); - } else { - $this->assertEqualsWithDelta($i, 32, $array->getNextSet($i)); - } + $this->assertEqualsWithDelta(32, $i, $array->getNextSet($i)); } $array = new BitArray(33); for ($i = 0; $i < $array->getSize(); ++$i) { - if ($this->getPhpUnitMajorVersion() === 7) { - $this->assertEquals($i, 33, '', $array->getNextSet($i)); - } else { - $this->assertEqualsWithDelta($i, 33, $array->getNextSet($i)); - } + $this->assertEqualsWithDelta(33, $i, $array->getNextSet($i)); } } @@ -53,21 +39,13 @@ public function testGetNextSet2() : void $array = new BitArray(33); for ($i = 0; $i < $array->getSize(); ++$i) { - if ($this->getPhpUnitMajorVersion() === 7) { - $this->assertEquals($i, $i <= 31 ? 31 : 33, '', $array->getNextSet($i)); - } else { - $this->assertEqualsWithDelta($i, $i <= 31 ? 31 : 33, $array->getNextSet($i)); - } + $this->assertEqualsWithDelta($i, $i <= 31 ? 31 : 33, $array->getNextSet($i)); } $array = new BitArray(33); for ($i = 0; $i < $array->getSize(); ++$i) { - if ($this->getPhpUnitMajorVersion() === 7) { - $this->assertEquals($i, 32, '', $array->getNextSet($i)); - } else { - $this->assertEqualsWithDelta($i, 32, $array->getNextSet($i)); - } + $this->assertEqualsWithDelta(32, $i, $array->getNextSet($i)); } } @@ -86,11 +64,7 @@ public function testGetNextSet3() : void $expected = 63; } - if ($this->getPhpUnitMajorVersion() === 7) { - $this->assertEquals($i, $expected, '', $array->getNextSet($i)); - } else { - $this->assertEqualsWithDelta($i, $expected, $array->getNextSet($i)); - } + $this->assertEqualsWithDelta($expected, $i, $array->getNextSet($i)); } } @@ -109,11 +83,7 @@ public function testGetNextSet4() : void $expected = 63; } - if ($this->getPhpUnitMajorVersion() === 7) { - $this->assertEquals($i, $expected, '', $array->getNextSet($i)); - } else { - $this->assertEqualsWithDelta($i, $expected, $array->getNextSet($i)); - } + $this->assertEqualsWithDelta($expected, $i, $array->getNextSet($i)); } } diff --git a/test/Common/ReedSolomonCodecTest.php b/test/Common/ReedSolomonCodecTest.php index bc7c33c..1c1b699 100644 --- a/test/Common/ReedSolomonCodecTest.php +++ b/test/Common/ReedSolomonCodecTest.php @@ -4,12 +4,13 @@ namespace BaconQrCodeTest\Common; use BaconQrCode\Common\ReedSolomonCodec; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use SplFixedArray; class ReedSolomonCodecTest extends TestCase { - public function tabs() : array + public static function tabs() : array { return [ [2, 0x7, 1, 1, 1], @@ -22,9 +23,7 @@ public function tabs() : array ]; } - /** - * @dataProvider tabs - */ + #[DataProvider('tabs')] public function testCodec(int $symbolSize, int $generatorPoly, int $firstRoot, int $primitive, int $numRoots) : void { mt_srand(0xdeadbeef, MT_RAND_PHP); diff --git a/test/Common/VersionTest.php b/test/Common/VersionTest.php index f6f038b..23e0370 100644 --- a/test/Common/VersionTest.php +++ b/test/Common/VersionTest.php @@ -5,11 +5,12 @@ use BaconQrCode\Common\ErrorCorrectionLevel; use BaconQrCode\Common\Version; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class VersionTest extends TestCase { - public function versions() : array + public static function versions() : array { $array = []; @@ -20,7 +21,7 @@ public function versions() : array return $array; } - public function decodeInformation() : array + public static function decodeInformation() : array { return [ [7, 0x07c94], @@ -32,9 +33,7 @@ public function decodeInformation() : array ]; } - /** - * @dataProvider versions - */ + #[DataProvider('versions')] public function testVersionForNumber(int $versionNumber, int $dimension) : void { $version = Version::getVersionForNumber($versionNumber); @@ -55,9 +54,7 @@ public function testVersionForNumber(int $versionNumber, int $dimension) : void $this->assertNotNull($version->buildFunctionPattern()); } - /** - * @dataProvider versions - */ + #[DataProvider('versions')] public function testGetProvisionalVersionForDimension(int $versionNumber, int $dimension) : void { $this->assertSame( @@ -66,9 +63,7 @@ public function testGetProvisionalVersionForDimension(int $versionNumber, int $d ); } - /** - * @dataProvider decodeInformation - */ + #[DataProvider('decodeInformation')] public function testDecodeVersionInformation(int $expectedVersion, int $mask) : void { $version = Version::decodeVersionInformation($mask); diff --git a/test/Encoder/EncoderTest.php b/test/Encoder/EncoderTest.php index ae21e43..d0839b7 100644 --- a/test/Encoder/EncoderTest.php +++ b/test/Encoder/EncoderTest.php @@ -19,7 +19,7 @@ final class EncoderTest extends TestCase /** * @var ReflectionMethod[] */ - protected $methods = []; + protected array $methods = []; public function setUp() : void { @@ -27,7 +27,6 @@ public function setUp() : void $reflection = new ReflectionClass(Encoder::class); foreach ($reflection->getMethods(ReflectionMethod::IS_STATIC) as $method) { - $method->setAccessible(true); $this->methods[$method->getName()] = $method; } } @@ -259,7 +258,7 @@ public function testAppendBytes() : void '1', Mode::NUMERIC(), $bits, - Encoder::DEFAULT_BYTE_MODE_ECODING + Encoder::DEFAULT_BYTE_MODE_ENCODING ); $this->assertSame(' ...X', (string) $bits); @@ -271,7 +270,7 @@ public function testAppendBytes() : void 'A', Mode::ALPHANUMERIC(), $bits, - Encoder::DEFAULT_BYTE_MODE_ECODING + Encoder::DEFAULT_BYTE_MODE_ENCODING ); $this->assertSame(' ..X.X.', (string) $bits); @@ -283,7 +282,7 @@ public function testAppendBytes() : void 'abc', Mode::BYTE(), $bits, - Encoder::DEFAULT_BYTE_MODE_ECODING + Encoder::DEFAULT_BYTE_MODE_ENCODING ); $this->assertSame(' .XX....X .XX...X. .XX...XX', (string) $bits); @@ -295,7 +294,7 @@ public function testAppendBytes() : void "\x93\x5f", Mode::KANJI(), $bits, - Encoder::DEFAULT_BYTE_MODE_ECODING + Encoder::DEFAULT_BYTE_MODE_ENCODING ); $this->assertSame(' .XX.XX.. XXXXX', (string) $bits); @@ -306,7 +305,7 @@ public function testAppendBytes() : void 'a', Mode::ALPHANUMERIC(), $bits, - Encoder::DEFAULT_BYTE_MODE_ECODING + Encoder::DEFAULT_BYTE_MODE_ENCODING ); } @@ -467,12 +466,12 @@ public function testAppend8BitBytes() : void { // 0x61, 0x62, 0x63 $bits = new BitArray(); - $this->methods['append8BitBytes']->invoke(null, 'abc', $bits, Encoder::DEFAULT_BYTE_MODE_ECODING); + $this->methods['append8BitBytes']->invoke(null, 'abc', $bits, Encoder::DEFAULT_BYTE_MODE_ENCODING); $this->assertSame(' .XX....X .XX...X. .XX...XX', (string) $bits); // Empty $bits = new BitArray(); - $this->methods['append8BitBytes']->invoke(null, '', $bits, Encoder::DEFAULT_BYTE_MODE_ECODING); + $this->methods['append8BitBytes']->invoke(null, '', $bits, Encoder::DEFAULT_BYTE_MODE_ENCODING); $this->assertSame('', (string) $bits); } diff --git a/test/Encoder/MaskUtilTest.php b/test/Encoder/MaskUtilTest.php index 46670fc..7ab0857 100644 --- a/test/Encoder/MaskUtilTest.php +++ b/test/Encoder/MaskUtilTest.php @@ -5,11 +5,12 @@ use BaconQrCode\Encoder\ByteMatrix; use BaconQrCode\Encoder\MaskUtil; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; class MaskUtilTest extends TestCase { - public function dataMaskBits() : array + public static function dataMaskBits() : array { return [ [0, [ @@ -82,6 +83,7 @@ public function dataMaskBits() : array /** * @dataProvider dataMaskBits */ + #[DataProvider('dataMaskBits')] public function testGetDatMaskBit(int $maskPattern, array $expected) : void { for ($x = 0; $x < 6; ++$x) { diff --git a/test/Encoder/MatrixUtilTest.php b/test/Encoder/MatrixUtilTest.php index 106ceaa..a0fcc63 100644 --- a/test/Encoder/MatrixUtilTest.php +++ b/test/Encoder/MatrixUtilTest.php @@ -17,7 +17,7 @@ class MatrixUtilTest extends TestCase /** * @var ReflectionMethod[] */ - protected $methods = []; + protected array $methods = []; public function setUp() : void { @@ -25,7 +25,6 @@ public function setUp() : void $reflection = new ReflectionClass(MatrixUtil::class); foreach ($reflection->getMethods(ReflectionMethod::IS_STATIC) as $method) { - $method->setAccessible(true); $this->methods[$method->getName()] = $method; } } diff --git a/test/Integration/ImagickRenderingTest.php b/test/Integration/ImagickRenderingTest.php index 3df8687..bc01cf4 100644 --- a/test/Integration/ImagickRenderingTest.php +++ b/test/Integration/ImagickRenderingTest.php @@ -14,19 +14,17 @@ use BaconQrCode\Renderer\RendererStyle\GradientType; use BaconQrCode\Renderer\RendererStyle\RendererStyle; use BaconQrCode\Writer; +use PHPUnit\Framework\Attributes\Group; +use PHPUnit\Framework\Attributes\RequiresPhpExtension; use PHPUnit\Framework\TestCase; use Spatie\Snapshots\MatchesSnapshots; -/** - * @group integration - */ +#[Group('integration')] final class ImagickRenderingTest extends TestCase { use MatchesSnapshots; - /** - * @requires extension imagick - */ + #[RequiresPhpExtension('imagick')] public function testGenericQrCode() : void { $renderer = new ImageRenderer( @@ -41,9 +39,7 @@ public function testGenericQrCode() : void unlink($tempName); } - /** - * @requires extension imagick - */ + #[RequiresPhpExtension('imagick')] public function testIssue79() : void { $eye = SquareEye::instance();