Skip to content

Commit 05a7c07

Browse files
committed
Add ecs with an opinionated default
1 parent e4ee47e commit 05a7c07

Some content is hidden

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

54 files changed

+7847
-7573
lines changed

composer.json

Lines changed: 8 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,10 @@
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"
3643
}
3744
}

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: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,67 +30,67 @@
3030
*/
3131
abstract class Binarizer
3232
{
33-
private $source;
33+
private $source;
3434

35-
protected function __construct($source)
36-
{
37-
$this->source = $source;
38-
}
35+
protected function __construct($source)
36+
{
37+
$this->source = $source;
38+
}
3939

40-
/**
41-
* @return LuminanceSource
42-
*/
43-
public final function getLuminanceSource()
44-
{
45-
return $this->source;
46-
}
40+
/**
41+
* @return LuminanceSource
42+
*/
43+
final public function getLuminanceSource()
44+
{
45+
return $this->source;
46+
}
4747

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);
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 An $row 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+
abstract public function getBlackRow($y, $row);
6464

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();
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+
abstract public function getBlackMatrix();
7575

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);
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+
abstract public function createBinarizer($source);
8686

87-
public final function getWidth()
88-
{
89-
return $this->source->getWidth();
90-
}
87+
final public function getWidth()
88+
{
89+
return $this->source->getWidth();
90+
}
9191

92-
public final function getHeight()
93-
{
94-
return $this->source->getHeight();
95-
}
92+
final public function getHeight()
93+
{
94+
return $this->source->getHeight();
95+
}
9696
}

0 commit comments

Comments
 (0)