Skip to content

Commit 69c49a5

Browse files
authored
Merge pull request #128 from GenieTim/master
Add 2 more tests and many more typehints
2 parents 45326fb + ce350f7 commit 69c49a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1300
-861
lines changed

.github/workflows/static_tests.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Static Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
static_tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: shivammathur/setup-php@v2
15+
with:
16+
php-version: 8.1
17+
coverage: none # disable xdebug, pcov
18+
- run: composer install --no-progress --no-interaction --no-suggest
19+
- run: composer static-tests

.github/workflows/tests.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
php:
15+
- "8.1"
16+
dependency-version:
17+
# - prefer-lowest
18+
- prefer-stable
19+
20+
name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} - tests
21+
steps:
22+
# basically git clone
23+
- uses: actions/checkout@v2
24+
25+
- name: Setup Git
26+
run: |
27+
git --version
28+
git config --global user.email "[email protected]"
29+
git config --global user.name "GitHub Action"
30+
git --version
31+
32+
- name: Setup PHP
33+
# use PHP of specific version
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: ${{ matrix.php }}
37+
coverage: none # disable xdebug, pcov
38+
tools: composer
39+
40+
- name: Install Composer Dependencies
41+
run: |
42+
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
43+
44+
- name: Run PHPUnit Tests
45+
run: composer tests

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ $text = $qrcode->text(); //return decoded text from QR Code
2222
```
2323

2424
## Requirements
25-
* PHP >= 5.6
25+
* PHP >= 8.1
2626
* GD Library
2727

2828

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121
}
2222
],
2323
"require": {
24-
"php": ">=5.6"
24+
"php": ">=8.1"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^5.7 | ^7.5 | ^8.0 | ^9.0",
27+
"phpunit/phpunit": "^7.5 | ^8.0 | ^9.0",
2828
"rector/rector": "^0.13.6",
29-
"symplify/easy-coding-standard": "^11.0"
29+
"symplify/easy-coding-standard": "^11.0",
30+
"vimeo/psalm": "^4.24"
3031
},
3132
"autoload": {
3233
"psr-4": {
@@ -39,7 +40,8 @@
3940
"scripts": {
4041
"check-cs": "./vendor/bin/ecs check",
4142
"fix-cs": "./vendor/bin/ecs check --fix",
42-
"tests": "./vendor/bin/phpunit"
43+
"tests": "./vendor/bin/phpunit",
44+
"static-tests": "./vendor/bin/psalm --php-version=8.1"
4345
},
4446
"autoload-dev": {
4547
"psr-4": {

lib/Binarizer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
abstract class Binarizer
3232
{
3333
protected function __construct(private $source)
34-
{
35-
}
34+
{
35+
}
3636

3737
/**
3838
* @return LuminanceSource
@@ -50,14 +50,14 @@ final public function getLuminanceSource()
5050
* and passed in with each call for performance. However it is legal to keep more than one row
5151
* at a time if needed.
5252
*
53-
* @param $y The row to fetch, which must be in [0, bitmap height)
54-
* @param An $row optional preallocated array. If null or too small, it will be ignored.
53+
* @param int $y The row to fetch, which must be in [0, bitmap height)
54+
* @param BitArray|null $row An optional preallocated array. If null or too small, it will be ignored.
5555
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
5656
*
57-
* @return array The array of bits for this row (true means black).
57+
* @return BitArray The array of bits for this row (true means black).
5858
* @throws NotFoundException if row can't be binarized
5959
*/
60-
abstract public function getBlackRow($y, $row);
60+
abstract public function getBlackRow(int $y, ?BitArray $row = null): BitArray;
6161

6262
/**
6363
* Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive

lib/BinaryBitmap.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ public function getHeight()
6060
* This method is intended for decoding 1D barcodes and may choose to apply sharpening.
6161
*
6262
* @param $y The row to fetch, which must be in [0, bitmap height)
63-
* @param An $row optional preallocated array. If null or too small, it will be ignored.
63+
* @param array|null $row An optional preallocated array. If null or too small, it will be ignored.
6464
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
6565
*
66-
* @return array The array of bits for this row (true means black).
66+
* @return Common\BitArray The array of bits for this row (true means black).
67+
*
6768
* @throws NotFoundException if row can't be binarized
6869
*/
69-
public function getBlackRow($y, $row)
70+
public function getBlackRow($y, $row): Common\BitArray
7071
{
7172
return $this->binarizer->getBlackRow($y, $row);
7273
}
@@ -98,7 +99,7 @@ public function crop($left, $top, $width, $height): \Zxing\BinaryBitmap
9899
}
99100

100101
/**
101-
* @return Whether this bitmap supports counter-clockwise rotation.
102+
* @return bool this Whether bitmap supports counter-clockwise rotation.
102103
*/
103104
public function isRotateSupported()
104105
{
@@ -131,7 +132,7 @@ public function rotateCounterClockwise45(): \Zxing\BinaryBitmap
131132
return new BinaryBitmap($this->binarizer->createBinarizer($newSource));
132133
}
133134

134-
public function toString()
135+
public function toString(): string
135136
{
136137
try {
137138
return $this->getBlackMatrix()->toString();

lib/ChecksumException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class ChecksumException extends ReaderException
2727
{
2828
private static ?\Zxing\ChecksumException $instance = null;
2929

30-
public static function getChecksumInstance($cause = null)
30+
public static function getChecksumInstance($cause = null): self
3131
{
3232
if (self::$isStackTrace) {
3333
return new ChecksumException($cause);

lib/Common/AbstractEnum.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010
final class AbstractEnum implements \Stringable
1111
{
1212
/**
13-
* Default value.
14-
*/
13+
* Default value.
14+
* @var null
15+
*/
1516
public const __default = null;
1617
/**
1718
* Current value.
@@ -24,7 +25,7 @@ final class AbstractEnum implements \Stringable
2425
*
2526
* @var array<string, mixed>|null
2627
*/
27-
private ?array $constants = null;
28+
private ?array $constants = null;
2829

2930
/**
3031
* Creates a new enum.
@@ -53,14 +54,14 @@ public function change($value)
5354
}
5455

5556
/**
56-
* Gets all constants (possible values) as an array.
57-
*
58-
* @param boolean $includeDefault
59-
*
60-
* @return array
61-
*/
62-
public function getConstList($includeDefault = true)
57+
* Gets all constants (possible values) as an array.
58+
*
59+
*
60+
* @return array
61+
*/
62+
public function getConstList(bool $includeDefault = true)
6363
{
64+
$constants = [];
6465
if ($this->constants === null) {
6566
$reflection = new ReflectionClass($this);
6667
$this->constants = $reflection->getConstants();

0 commit comments

Comments
 (0)