typed properties!

This commit is contained in:
codemasher
2019-07-31 01:31:33 +02:00
parent 6750b7225c
commit edf885823d
32 changed files with 122 additions and 299 deletions
+2 -8
View File
@@ -19,15 +19,9 @@ use chillerlan\QRCode\QRCode;
*/
class AlphaNum extends QRDataAbstract{
/**
* @inheritdoc
*/
protected $datamode = QRCode::DATA_ALPHANUM;
protected int $datamode = QRCode::DATA_ALPHANUM;
/**
* @inheritdoc
*/
protected $lengthBits = [9, 11, 13];
protected array $lengthBits = [9, 11, 13];
/**
* @inheritdoc
+2 -8
View File
@@ -19,15 +19,9 @@ use chillerlan\QRCode\QRCode;
*/
class Byte extends QRDataAbstract{
/**
* @inheritdoc
*/
protected $datamode = QRCode::DATA_BYTE;
protected int $datamode = QRCode::DATA_BYTE;
/**
* @inheritdoc
*/
protected $lengthBits = [8, 16, 16];
protected array $lengthBits = [8, 16, 16];
/**
* @inheritdoc
+2 -8
View File
@@ -19,15 +19,9 @@ use chillerlan\QRCode\QRCode;
*/
class Kanji extends QRDataAbstract{
/**
* @inheritdoc
*/
protected $datamode = QRCode::DATA_KANJI;
protected int $datamode = QRCode::DATA_KANJI;
/**
* @inheritdoc
*/
protected $lengthBits = [8, 10, 12];
protected array $lengthBits = [8, 10, 12];
/**
* @inheritdoc
+2 -8
View File
@@ -19,15 +19,9 @@ namespace chillerlan\QRCode\Data;
*/
class MaskPatternTester{
/**
* @var \chillerlan\QRCode\Data\QRMatrix
*/
protected $matrix;
protected QRMatrix $matrix;
/**
* @var int
*/
protected $moduleCount;
protected int $moduleCount;
/**
* Receives the matrix an sets the module count
+2 -8
View File
@@ -19,15 +19,9 @@ use chillerlan\QRCode\QRCode;
*/
class Number extends QRDataAbstract{
/**
* @inheritdoc
*/
protected $datamode = QRCode::DATA_NUMBER;
protected int $datamode = QRCode::DATA_NUMBER;
/**
* @inheritdoc
*/
protected $lengthBits = [10, 12, 14];
protected array $lengthBits = [10, 12, 14];
/**
* @inheritdoc
+10 -29
View File
@@ -23,62 +23,43 @@ abstract class QRDataAbstract implements QRDataInterface{
/**
* the string byte count
*
* @var int
*/
protected $strlen;
protected ?int $strlen = null;
/**
* the current data mode: Num, Alphanum, Kanji, Byte
*
* @var int
*/
protected $datamode;
protected int $datamode;
/**
* mode length bits for the version breakpoints 1-9, 10-26 and 27-40
*
* @var array
*/
protected $lengthBits = [0, 0, 0];
protected array $lengthBits = [0, 0, 0];
/**
* current QR Code version
*
* @var int
*/
protected $version;
protected int $version;
/**
* the raw data that's being passed to QRMatrix::mapData()
*
* @var array
*/
protected $matrixdata;
protected array $matrixdata;
/**
* ECC temp data
*
* @var array
*/
protected $ecdata;
protected array $ecdata;
/**
* ECC temp data
*
* @var array
*/
protected $dcdata;
protected array $dcdata;
/**
* @var \chillerlan\QRCode\QROptions
*/
protected $options;
/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions */
protected SettingsContainerInterface $options;
/**
* @var \chillerlan\QRCode\Helpers\BitBuffer
*/
protected $bitBuffer;
protected BitBuffer $bitBuffer;
/**
* QRDataInterface constructor.
+6 -21
View File
@@ -167,30 +167,15 @@ class QRMatrix{
],
];
/**
* @var int
*/
protected $version;
protected int $version;
/**
* @var int
*/
protected $eclevel;
protected int $eclevel;
/**
* @var int
*/
protected $maskPattern = QRCode::MASK_PATTERN_AUTO;
protected int $maskPattern = QRCode::MASK_PATTERN_AUTO;
/**
* @var int
*/
protected $moduleCount;
/**
* @var mixed[]
*/
protected $matrix;
protected int $moduleCount;
/** @var mixed[] */
protected array $matrix;
/**
* QRMatrix constructor.
+3 -8
View File
@@ -14,15 +14,10 @@ namespace chillerlan\QRCode\Helpers;
class BitBuffer{
/**
* @var int[]
*/
public $buffer = [];
/** @var int[] */
public array $buffer = [];
/**
* @var int
*/
public $length = 0;
public int $length = 0;
/**
* @return \chillerlan\QRCode\Helpers\BitBuffer
+1 -4
View File
@@ -57,10 +57,7 @@ class Polynomial{
[ 27, 116], [ 54, 214], [108, 244], [216, 234], [173, 168], [ 71, 80], [142, 88], [ 1, 175],
];
/**
* @var array
*/
protected $num = [];
protected array $num = [];
/**
* Polynomial constructor.
+1 -4
View File
@@ -26,10 +26,7 @@ class QRImage extends QROutputAbstract{
QRCode::OUTPUT_IMAGE_GIF,
];
/**
* @var string
*/
protected $defaultMode = QRCode::OUTPUT_IMAGE_PNG;
protected string $defaultMode = QRCode::OUTPUT_IMAGE_PNG;
/**
* @see imagecreatetruecolor()
+1 -4
View File
@@ -19,10 +19,7 @@ use chillerlan\QRCode\QRCode;
*/
class QRMarkup extends QROutputAbstract{
/**
* @var string
*/
protected $defaultMode = QRCode::OUTPUT_MARKUP_SVG;
protected string $defaultMode = QRCode::OUTPUT_MARKUP_SVG;
/**
* @see \sprintf()
+9 -33
View File
@@ -20,45 +20,21 @@ use chillerlan\Settings\SettingsContainerInterface;
*/
abstract class QROutputAbstract implements QROutputInterface{
/**
* @var int
*/
protected $moduleCount;
protected int $moduleCount;
/**
* @param \chillerlan\QRCode\Data\QRMatrix $matrix
*/
protected $matrix;
protected QRMatrix $matrix;
/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions */
protected SettingsContainerInterface $options;
/**
* @var \chillerlan\QRCode\QROptions
*/
protected $options;
protected string $outputMode;
/**
* @var string
*/
protected $outputMode;
protected string $defaultMode;
/**
* @var string;
*/
protected $defaultMode;
protected int $scale;
/**
* @var int
*/
protected $scale;
protected int $length;
/**
* @var int
*/
protected $length;
/**
* @var array
*/
protected $moduleValues;
protected array $moduleValues;
/**
* QROutputAbstract constructor.
+1 -4
View File
@@ -19,10 +19,7 @@ use chillerlan\QRCode\QRCode;
*/
class QRString extends QROutputAbstract{
/**
* @var string
*/
protected $defaultMode = QRCode::OUTPUT_STRING_TEXT;
protected string $defaultMode = QRCode::OUTPUT_STRING_TEXT;
/**
* @return void
+3 -3
View File
@@ -91,18 +91,18 @@ class QRCode{
/**
* @var \chillerlan\QRCode\QROptions
*/
protected $options;
protected QROptions $options;
/**
* @var \chillerlan\QRCode\Data\QRDataInterface
*/
protected $dataInterface;
protected QRDataInterface $dataInterface;
/**
* @see http://php.net/manual/function.mb-internal-encoding.php
* @var string
*/
protected $mbCurrentEncoding;
protected string $mbCurrentEncoding;
/**
* QRCode constructor.
+30 -84
View File
@@ -17,25 +17,19 @@ trait QROptionsTrait{
/**
* QR Code version number
*
* [1 ... 40] or QRCode::VERSION_AUTO
*
* @var int
* [1 ... 40] or QRCode::VERSION_AUTO
*/
protected $version = QRCode::VERSION_AUTO;
protected int $version = QRCode::VERSION_AUTO;
/**
* Minimum QR version (if $version = QRCode::VERSION_AUTO)
*
* @var int
*/
protected $versionMin = 1;
protected int $versionMin = 1;
/**
* Maximum QR version
*
* @var int
*/
protected $versionMax = 40;
protected int $versionMax = 40;
/**
* Error correct level
@@ -45,97 +39,73 @@ trait QROptionsTrait{
* M => 15%
* Q => 25%
* H => 30%
*
* @var int
*/
protected $eccLevel = QRCode::ECC_L;
protected int $eccLevel = QRCode::ECC_L;
/**
* Mask Pattern to use
*
* [0...7] or QRCode::MASK_PATTERN_AUTO
*
* @var int
*/
protected $maskPattern = QRCode::MASK_PATTERN_AUTO;
protected int $maskPattern = QRCode::MASK_PATTERN_AUTO;
/**
* Add a "quiet zone" (margin) according to the QR code spec
*
* @var bool
*/
protected $addQuietzone = true;
protected bool $addQuietzone = true;
/**
* Size of the quiet zone
*
* internally clamped to [0 ... $moduleCount / 2], defaults to 4 modules
*
* @var int
*/
protected $quietzoneSize = 4;
protected int $quietzoneSize = 4;
/**
* QRCode::OUTPUT_MARKUP_XXXX where XXXX = HTML, SVG
* QRCode::OUTPUT_IMAGE_XXX where XXX = PNG, GIF, JPG
* QRCode::OUTPUT_STRING_XXXX where XXXX = TEXT, JSON
* QRCode::OUTPUT_CUSTOM
*
* @var string
*/
protected $outputType = QRCode::OUTPUT_IMAGE_PNG;
protected string $outputType = QRCode::OUTPUT_IMAGE_PNG;
/**
* the FQCN of the custom QROutputInterface if $outputType is set to QRCode::OUTPUT_CUSTOM
*
* @var string
*/
protected $outputInterface;
protected string $outputInterface;
/**
* /path/to/cache.file
*
* @var string
*/
protected $cachefile;
protected string $cachefile;
/**
* newline string [HTML, SVG, TEXT]
*
* @var string
*/
protected $eol = PHP_EOL;
protected string $eol = PHP_EOL;
/**
* size of a QR code pixel [SVG, IMAGE_*]
* HTML -> via CSS
*
* @var int
*/
protected $scale = 5;
protected int $scale = 5;
/**
* a common css class
*
* @var string
*/
protected $cssClass;
protected string $cssClass;
/**
* SVG opacity
*
* @var float
*/
protected $svgOpacity = 1.0;
protected float $svgOpacity = 1.0;
/**
* anything between <defs>
*
* @see https://developer.mozilla.org/docs/Web/SVG/Element/defs
*
* @var string
*/
protected $svgDefs = '<style>rect{shape-rendering:crispEdges}</style>';
protected string $svgDefs = '<style>rect{shape-rendering:crispEdges}</style>';
/**
* SVG viewBox size. a single integer number which defines width/height of the viewBox attribute.
@@ -143,101 +113,77 @@ trait QROptionsTrait{
* viewBox="0 0 x x"
*
* @see https://css-tricks.com/scale-svg/#article-header-id-3
*
* @var int
*/
protected $svgViewBoxSize;
protected int $svgViewBoxSize;
/**
* string substitute for dark
*
* @var string
*/
protected $textDark = '🔴';
protected string $textDark = '🔴';
/**
* string substitute for light
*
* @var string
*/
protected $textLight = '⭕';
protected string $textLight = '⭕';
/**
* markup substitute for dark (CSS value)
*
* @var string
*/
protected $markupDark = '#000';
protected string $markupDark = '#000';
/**
* markup substitute for light (CSS value)
*
* @var string
*/
protected $markupLight = '#fff';
protected string $markupLight = '#fff';
/**
* toggle base64 or raw image data
*
* @var bool
*/
protected $imageBase64 = true;
protected bool $imageBase64 = true;
/**
* toggle transparency, not supported by jpg
*
* @var bool
*/
protected $imageTransparent = true;
protected bool $imageTransparent = true;
/**
* @see imagecolortransparent()
*
* @var array [R, G, B]
* [R, G, B]
*/
protected $imageTransparencyBG = [255, 255, 255];
protected array $imageTransparencyBG = [255, 255, 255];
/**
* @see imagepng()
*
* @var int
*/
protected $pngCompression = -1;
protected int $pngCompression = -1;
/**
* @see imagejpeg()
*
* @var int
*/
protected $jpegQuality = 85;
protected int $jpegQuality = 85;
/**
* Imagick output format
*
* @see Imagick::setType()
*
* @var string
*/
protected $imagickFormat = 'png';
protected string $imagickFormat = 'png';
/**
* Imagick background color (defaults to "transparent")
*
* @see \ImagickPixel::__construct()
*
* @var string
*/
protected $imagickBG;
protected string $imagickBG;
/**
* Module values map
*
* HTML, IMAGICK: #ABCDEF, cssname, rgb(), rgba()...
* IMAGE: [63, 127, 255] // R, G, B
*
* @var array
*/
protected $moduleValues;
protected array $moduleValues;
/**
* set/clamp some special values, call the parent setter otherwise
+5 -3
View File
@@ -16,9 +16,11 @@ use chillerlan\QRCode\Data\{AlphaNum, QRCodeDataException};
class AlphaNumTest extends DatainterfaceTestAbstract{
protected $FQCN = AlphaNum::class;
protected $testdata = '0 $%*+-./:';
protected $expected = [
protected string $FQCN = AlphaNum::class;
protected string $testdata = '0 $%*+-./:';
protected array $expected = [
32, 80, 36, 212, 252, 15, 175, 251,
176, 236, 17, 236, 17, 236, 17, 236,
17, 236, 17, 236, 17, 236, 17, 236,
+5 -3
View File
@@ -16,9 +16,11 @@ use chillerlan\QRCode\Data\Byte;
class ByteTest extends DatainterfaceTestAbstract{
protected $FQCN = Byte::class;
protected $testdata = '[¯\_(ツ)_/¯]';
protected $expected = [
protected string $FQCN = Byte::class;
protected string $testdata = '[¯\_(ツ)_/¯]';
protected array $expected = [
64, 245, 188, 42, 245, 197, 242, 142,
56, 56, 66, 149, 242, 252, 42, 245,
208, 236, 17, 236, 17, 236, 17, 236,
+4 -6
View File
@@ -18,13 +18,11 @@ use chillerlan\QRCodeTest\QRTestAbstract;
abstract class DatainterfaceTestAbstract extends QRTestAbstract{
/**
* @var \chillerlan\QRCode\Data\QRDataAbstract
*/
protected $dataInterface;
protected QRDataInterface $dataInterface;
protected $testdata;
protected $expected;
protected string $testdata;
protected array $expected;
protected function setUp():void{
parent::setUp();
+5 -3
View File
@@ -16,9 +16,11 @@ use chillerlan\QRCode\Data\{Kanji, QRCodeDataException};
class KanjiTest extends DatainterfaceTestAbstract{
protected $FQCN = Kanji::class;
protected $testdata = '茗荷茗荷茗荷茗荷茗荷';
protected $expected = [
protected string $FQCN = Kanji::class;
protected string $testdata = '茗荷茗荷茗荷茗荷茗荷';
protected array $expected = [
128, 173, 85, 26, 95, 85, 70, 151,
213, 81, 165, 245, 84, 105, 125, 85,
26, 92, 0, 236, 17, 236, 17, 236,
+1 -1
View File
@@ -17,7 +17,7 @@ use chillerlan\QRCodeTest\QRTestAbstract;
class MaskPatternTesterTest extends QRTestAbstract{
protected $FQCN = MaskPatternTester::class;
protected string $FQCN = MaskPatternTester::class;
// coverage
public function testMaskpattern(){
+5 -3
View File
@@ -16,9 +16,11 @@ use chillerlan\QRCode\Data\{Number, QRCodeDataException};
class NumberTest extends DatainterfaceTestAbstract{
protected $FQCN = Number::class;
protected $testdata = '0123456789';
protected $expected = [
protected string $FQCN = Number::class;
protected string $testdata = '0123456789';
protected array $expected = [
16, 40, 12, 86, 106, 105, 0, 236,
17, 236, 17, 236, 17, 236, 17, 236,
17, 236, 17, 236, 17, 236, 17, 236,
+3 -6
View File
@@ -19,14 +19,11 @@ use ReflectionClass;
class QRMatrixTest extends QRTestAbstract{
protected $FQCN = QRMatrix::class;
protected string $FQCN = QRMatrix::class;
protected $version = 7;
protected int $version = 7;
/**
* @var \chillerlan\QRCode\Data\QRMatrix
*/
protected $matrix;
protected QRMatrix $matrix;
protected function setUp():void{
parent::setUp();
+1 -4
View File
@@ -17,10 +17,7 @@ use chillerlan\QRCodeTest\QRTestAbstract;
class BitBufferTest extends QRTestAbstract{
/**
* @var \chillerlan\QRCode\Helpers\BitBuffer
*/
protected $bitBuffer;
protected BitBuffer $bitBuffer;
protected function setUp():void{
$this->bitBuffer = new BitBuffer;
+1 -4
View File
@@ -18,10 +18,7 @@ use chillerlan\QRCodeTest\QRTestAbstract;
class PolynomialTest extends QRTestAbstract{
/**
* @var \chillerlan\QRCode\Helpers\Polynomial
*/
protected $polynomial;
protected Polynomial $polynomial;
protected function setUp():void{
$this->polynomial = new Polynomial;
+1 -1
View File
@@ -16,7 +16,7 @@ use chillerlan\QRCode\{QRCode, Output\QRImage};
class QRImageTest extends QROutputTestAbstract{
protected $FQCN = QRImage::class;
protected string $FQCN = QRImage::class;
public function types(){
return [
+1 -1
View File
@@ -16,7 +16,7 @@ use chillerlan\QRCode\{QRCode, Output\QRImagick};
class QRImagickTest extends QROutputTestAbstract{
protected $FQCN = QRImagick::class;
protected string $FQCN = QRImagick::class;
public function setUp():void{
+1 -1
View File
@@ -16,7 +16,7 @@ use chillerlan\QRCode\{QRCode, Output\QRMarkup};
class QRMarkupTest extends QROutputTestAbstract{
protected $FQCN = QRMarkup::class;
protected string $FQCN = QRMarkup::class;
public function types(){
return [
+7 -15
View File
@@ -13,30 +13,22 @@
namespace chillerlan\QRCodeTest\Output;
use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Data\Byte;
use chillerlan\QRCode\Data\{Byte, QRMatrix};
use chillerlan\QRCode\Output\{QRCodeOutputException, QROutputInterface};
use chillerlan\QRCodeTest\QRTestAbstract;
use chillerlan\Settings\SettingsContainerInterface;
/**
*/
abstract class QROutputTestAbstract extends QRTestAbstract{
const cachefile = __DIR__.'/output_test.';
protected const cachefile = __DIR__.'/output_test.';
/**
* @var \chillerlan\QRCode\Output\QROutputInterface
*/
protected $outputInterface;
protected QROutputInterface $outputInterface;
/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions */
protected SettingsContainerInterface $options;
/**
* @var \chillerlan\QRCode\QROptions
*/
protected $options;
/**
* @var \chillerlan\QRCode\Data\QRMatrix
*/
protected $matrix;
protected QRMatrix $matrix;
protected function setUp():void{
parent::setUp();
+1 -1
View File
@@ -16,7 +16,7 @@ use chillerlan\QRCode\{QRCode, Output\QRString};
class QRStringTest extends QROutputTestAbstract{
protected $FQCN = QRString::class;
protected string $FQCN = QRString::class;
public function types(){
return [
+1 -1
View File
@@ -19,7 +19,7 @@ use chillerlan\QRCodeExamples\MyCustomOutput;
class QRCodeTest extends QRTestAbstract{
protected $FQCN = QRCode::class;
protected string $FQCN = QRCode::class;
/**
* @var \chillerlan\QRCode\QRCode
+3 -4
View File
@@ -12,15 +12,14 @@
namespace chillerlan\QRCodeTest;
use chillerlan\Settings\SettingsContainerInterface;
use chillerlan\QRCode\{QRCode, QRCodeException, QROptions};
use PHPUnit\Framework\TestCase;
class QROptionsTest extends TestCase{
/**
* @var \chillerlan\QRCode\QROptions
*/
protected $options;
/** @var \chillerlan\Settings\SettingsContainerInterface|\chillerlan\QRCode\QROptions */
protected SettingsContainerInterface $options;
public function testVersionClamp(){
$this->assertSame(40, (new QROptions(['version' => 42]))->version);
+2 -8
View File
@@ -17,15 +17,9 @@ use ReflectionClass, ReflectionMethod, ReflectionProperty;
abstract class QRTestAbstract extends TestCase{
/**
* @var \ReflectionClass
*/
protected $reflection;
protected ReflectionClass $reflection;
/**
* @var string
*/
protected $FQCN;
protected string $FQCN;
protected function setUp():void{
$this->reflection = new ReflectionClass($this->FQCN);