Skip to content

Commit

Permalink
Merge pull request #128 from GenieTim/master
Browse files Browse the repository at this point in the history
Add 2 more tests and many more typehints
  • Loading branch information
khanamiryan authored Jul 5, 2022
2 parents 45326fb + ce350f7 commit 69c49a5
Show file tree
Hide file tree
Showing 57 changed files with 1,300 additions and 861 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/static_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Static Tests

on:
pull_request:
push:
branches:
- master

jobs:
static_tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none # disable xdebug, pcov
- run: composer install --no-progress --no-interaction --no-suggest
- run: composer static-tests
45 changes: 45 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Tests

on:
pull_request:
push:
branches:
- master

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
php:
- "8.1"
dependency-version:
# - prefer-lowest
- prefer-stable

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} - tests
steps:
# basically git clone
- uses: actions/checkout@v2

- name: Setup Git
run: |
git --version
git config --global user.email "[email protected]"
git config --global user.name "GitHub Action"
git --version
- name: Setup PHP
# use PHP of specific version
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none # disable xdebug, pcov
tools: composer

- name: Install Composer Dependencies
run: |
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Run PHPUnit Tests
run: composer tests
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ $text = $qrcode->text(); //return decoded text from QR Code
```

## Requirements
* PHP >= 5.6
* PHP >= 8.1
* GD Library


Expand Down
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
}
],
"require": {
"php": ">=5.6"
"php": ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^5.7 | ^7.5 | ^8.0 | ^9.0",
"phpunit/phpunit": "^7.5 | ^8.0 | ^9.0",
"rector/rector": "^0.13.6",
"symplify/easy-coding-standard": "^11.0"
"symplify/easy-coding-standard": "^11.0",
"vimeo/psalm": "^4.24"
},
"autoload": {
"psr-4": {
Expand All @@ -39,7 +40,8 @@
"scripts": {
"check-cs": "./vendor/bin/ecs check",
"fix-cs": "./vendor/bin/ecs check --fix",
"tests": "./vendor/bin/phpunit"
"tests": "./vendor/bin/phpunit",
"static-tests": "./vendor/bin/psalm --php-version=8.1"
},
"autoload-dev": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions lib/Binarizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
abstract class Binarizer
{
protected function __construct(private $source)
{
}
{
}

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

/**
* Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
Expand Down
11 changes: 6 additions & 5 deletions lib/BinaryBitmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,14 @@ public function getHeight()
* This method is intended for decoding 1D barcodes and may choose to apply sharpening.
*
* @param $y The row to fetch, which must be in [0, bitmap height)
* @param An $row optional preallocated array. If null or too small, it will be ignored.
* @param array|null $row An optional preallocated array. If null or too small, it will be ignored.
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
*
* @return array The array of bits for this row (true means black).
* @return Common\BitArray The array of bits for this row (true means black).
*
* @throws NotFoundException if row can't be binarized
*/
public function getBlackRow($y, $row)
public function getBlackRow($y, $row): Common\BitArray
{
return $this->binarizer->getBlackRow($y, $row);
}
Expand Down Expand Up @@ -98,7 +99,7 @@ public function crop($left, $top, $width, $height): \Zxing\BinaryBitmap
}

/**
* @return Whether this bitmap supports counter-clockwise rotation.
* @return bool this Whether bitmap supports counter-clockwise rotation.
*/
public function isRotateSupported()
{
Expand Down Expand Up @@ -131,7 +132,7 @@ public function rotateCounterClockwise45(): \Zxing\BinaryBitmap
return new BinaryBitmap($this->binarizer->createBinarizer($newSource));
}

public function toString()
public function toString(): string
{
try {
return $this->getBlackMatrix()->toString();
Expand Down
2 changes: 1 addition & 1 deletion lib/ChecksumException.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ final class ChecksumException extends ReaderException
{
private static ?\Zxing\ChecksumException $instance = null;

public static function getChecksumInstance($cause = null)
public static function getChecksumInstance($cause = null): self
{
if (self::$isStackTrace) {
return new ChecksumException($cause);
Expand Down
21 changes: 11 additions & 10 deletions lib/Common/AbstractEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
final class AbstractEnum implements \Stringable
{
/**
* Default value.
*/
* Default value.
* @var null
*/
public const __default = null;
/**
* Current value.
Expand All @@ -24,7 +25,7 @@ final class AbstractEnum implements \Stringable
*
* @var array<string, mixed>|null
*/
private ?array $constants = null;
private ?array $constants = null;

/**
* Creates a new enum.
Expand Down Expand Up @@ -53,14 +54,14 @@ public function change($value)
}

/**
* Gets all constants (possible values) as an array.
*
* @param boolean $includeDefault
*
* @return array
*/
public function getConstList($includeDefault = true)
* Gets all constants (possible values) as an array.
*
*
* @return array
*/
public function getConstList(bool $includeDefault = true)
{
$constants = [];
if ($this->constants === null) {
$reflection = new ReflectionClass($this);
$this->constants = $reflection->getConstants();
Expand Down
Loading

0 comments on commit 69c49a5

Please sign in to comment.