Skip to content

Commit 45326fb

Browse files
authored
Merge pull request #123 from GenieTim/master
Merge various of the open PRs + Improve PHP 8.1+ compatibility
2 parents 04fdd58 + 37269d3 commit 45326fb

Some content is hidden

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

58 files changed

+7707
-7489
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ $ composer require khanamiryan/qrcode-detector-decoder
1616
## Usage
1717
```php
1818
require __DIR__ . "/vendor/autoload.php";
19+
use Zxing\QrReader;
1920
$qrcode = new QrReader('path/to_image');
2021
$text = $qrcode->text(); //return decoded text from QR Code
2122
```

composer.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"php": ">=5.6"
2525
},
2626
"require-dev": {
27-
"phpunit/phpunit": "^5.7 | ^7.5 | ^8.0 | ^9.0"
27+
"phpunit/phpunit": "^5.7 | ^7.5 | ^8.0 | ^9.0",
28+
"rector/rector": "^0.13.6",
29+
"symplify/easy-coding-standard": "^11.0"
2830
},
2931
"autoload": {
3032
"psr-4": {
@@ -33,5 +35,15 @@
3335
"files": [
3436
"lib/Common/customFunctions.php"
3537
]
38+
},
39+
"scripts": {
40+
"check-cs": "./vendor/bin/ecs check",
41+
"fix-cs": "./vendor/bin/ecs check --fix",
42+
"tests": "./vendor/bin/phpunit"
43+
},
44+
"autoload-dev": {
45+
"psr-4": {
46+
"Khanamiryan\\QrCodeTests\\": "tests/"
47+
}
3648
}
3749
}

ecs.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use Rector\Set\ValueObject\LevelSetList;
4+
use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer;
5+
use Symplify\EasyCodingStandard\Config\ECSConfig;
6+
use Symplify\EasyCodingStandard\ValueObject\Option;
7+
8+
use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
9+
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
10+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
11+
12+
return static function (ECSConfig $configurator): void {
13+
14+
// alternative to CLI arguments, easier to maintain and extend
15+
$configurator->paths([__DIR__ . '/lib', __DIR__ . '/tests']);
16+
17+
// choose
18+
$configurator->sets([
19+
SetList::CLEAN_CODE, SetList::PSR_12//, LevelSetList::UP_TO_PHP_81 //, SymfonySetList::SYMFONY_60
20+
]);
21+
22+
$configurator->ruleWithConfiguration(ConcatSpaceFixer::class, [
23+
'spacing' => 'one'
24+
]);
25+
26+
// indent and tabs/spaces
27+
// [default: spaces]. BUT: tabs are superiour due to accessibility reasons
28+
$configurator->indentation('tab');
29+
};

lib/Binarizer.php

Lines changed: 54 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -30,67 +30,64 @@
3030
*/
3131
abstract class Binarizer
3232
{
33-
private $source;
33+
protected function __construct(private $source)
34+
{
35+
}
3436

35-
protected function __construct($source)
36-
{
37-
$this->source = $source;
38-
}
37+
/**
38+
* @return LuminanceSource
39+
*/
40+
final public function getLuminanceSource()
41+
{
42+
return $this->source;
43+
}
3944

40-
/**
41-
* @return LuminanceSource
42-
*/
43-
public final function getLuminanceSource()
44-
{
45-
return $this->source;
46-
}
45+
/**
46+
* Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
47+
* cached data. Callers should assume this method is expensive and call it as seldom as possible.
48+
* This method is intended for decoding 1D barcodes and may choose to apply sharpening.
49+
* For callers which only examine one row of pixels at a time, the same BitArray should be reused
50+
* and passed in with each call for performance. However it is legal to keep more than one row
51+
* at a time if needed.
52+
*
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.
55+
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
56+
*
57+
* @return array The array of bits for this row (true means black).
58+
* @throws NotFoundException if row can't be binarized
59+
*/
60+
abstract public function getBlackRow($y, $row);
4761

48-
/**
49-
* Converts one row of luminance data to 1 bit data. May actually do the conversion, or return
50-
* cached data. Callers should assume this method is expensive and call it as seldom as possible.
51-
* This method is intended for decoding 1D barcodes and may choose to apply sharpening.
52-
* For callers which only examine one row of pixels at a time, the same BitArray should be reused
53-
* and passed in with each call for performance. However it is legal to keep more than one row
54-
* at a time if needed.
55-
*
56-
* @param y The row to fetch, which must be in [0, bitmap height)
57-
* @param row An optional preallocated array. If null or too small, it will be ignored.
58-
* If used, the Binarizer will call BitArray.clear(). Always use the returned object.
59-
*
60-
* @return array The array of bits for this row (true means black).
61-
* @throws NotFoundException if row can't be binarized
62-
*/
63-
public abstract function getBlackRow($y, $row);
62+
/**
63+
* Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
64+
* and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
65+
* may not apply sharpening. Therefore, a row from this matrix may not be identical to one
66+
* fetched using getBlackRow(), so don't mix and match between them.
67+
*
68+
* @return BitMatrix The 2D array of bits for the image (true means black).
69+
* @throws NotFoundException if image can't be binarized to make a matrix
70+
*/
71+
abstract public function getBlackMatrix();
6472

65-
/**
66-
* Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive
67-
* and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or
68-
* may not apply sharpening. Therefore, a row from this matrix may not be identical to one
69-
* fetched using getBlackRow(), so don't mix and match between them.
70-
*
71-
* @return BitMatrix The 2D array of bits for the image (true means black).
72-
* @throws NotFoundException if image can't be binarized to make a matrix
73-
*/
74-
public abstract function getBlackMatrix();
73+
/**
74+
* Creates a new object with the same type as this Binarizer implementation, but with pristine
75+
* state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache
76+
* of 1 bit data. See Effective Java for why we can't use Java's clone() method.
77+
*
78+
* @param $source The LuminanceSource this Binarizer will operate on.
79+
*
80+
* @return Binarizer A new concrete Binarizer implementation object.
81+
*/
82+
abstract public function createBinarizer($source);
7583

76-
/**
77-
* Creates a new object with the same type as this Binarizer implementation, but with pristine
78-
* state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache
79-
* of 1 bit data. See Effective Java for why we can't use Java's clone() method.
80-
*
81-
* @param source The LuminanceSource this Binarizer will operate on.
82-
*
83-
* @return Binarizer A new concrete Binarizer implementation object.
84-
*/
85-
public abstract function createBinarizer($source);
84+
final public function getWidth()
85+
{
86+
return $this->source->getWidth();
87+
}
8688

87-
public final function getWidth()
88-
{
89-
return $this->source->getWidth();
90-
}
91-
92-
public final function getHeight()
93-
{
94-
return $this->source->getHeight();
95-
}
89+
final public function getHeight()
90+
{
91+
return $this->source->getHeight();
92+
}
9693
}

0 commit comments

Comments
 (0)