Skip to content

Commit f32696c

Browse files
committed
:octocat: fix PHPCS config, add Slevomat rules
1 parent 89cdd09 commit f32696c

File tree

97 files changed

+462
-654
lines changed

Some content is hidden

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

97 files changed

+462
-654
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ jobs:
4747
- name: "Install dependencies with composer"
4848
uses: ramsey/composer-install@v3
4949

50-
- name: "Run phan"
51-
run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }}
5250
- name: "Run PHPStan"
5351
run: php vendor/bin/phpstan
5452

53+
- name: "Run PHP_CodeSniffer"
54+
run: php vendor/bin/phpstan
55+
5556

5657
tests:
5758
name: "Unit Tests"

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"phpstan/phpstan": "^1.11",
6161
"phpstan/phpstan-deprecation-rules": "^1.2",
6262
"setasign/fpdf": "^1.8.2",
63+
"slevomat/coding-standard": "^8.15",
6364
"squizlabs/php_codesniffer": "^3.10"
6465
},
6566
"suggest": {
@@ -92,6 +93,9 @@
9293
"config": {
9394
"lock": false,
9495
"sort-packages": true,
95-
"platform-check": true
96+
"platform-check": true,
97+
"allow-plugins": {
98+
"dealerdirect/phpcodesniffer-composer-installer": true
99+
}
96100
}
97101
}

examples/custom_output.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,21 @@
2121

2222
class MyCustomOutput extends QROutputAbstract{
2323

24-
/**
25-
* @inheritDoc
26-
*/
2724
public static function moduleValueIsValid(mixed $value):bool{
2825
// TODO: Implement moduleValueIsValid() method. (interface)
2926
return false;
3027
}
3128

32-
/**
33-
* @inheritDoc
34-
*/
3529
protected function prepareModuleValue(mixed $value):mixed{
3630
// TODO: Implement prepareModuleValue() method. (abstract)
3731
return null;
3832
}
3933

40-
/**
41-
* @inheritDoc
42-
*/
4334
protected function getDefaultModuleValue(bool $isDark):mixed{
4435
// TODO: Implement getDefaultModuleValue() method. (abstract)
4536
return null;
4637
}
4738

48-
/**
49-
* @inheritDoc
50-
*/
5139
public function dump(string|null $file = null):string{
5240
$output = '';
5341

examples/eps.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555

5656
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ', __DIR__.'/qrcode.eps');
5757

58-
if(php_sapi_name() !== 'cli'){
58+
if(PHP_SAPI !== 'cli'){
5959
// if viewed in the browser, we should push it as file download as EPS isn't usually supported
6060
header('Content-type: application/postscript');
6161
header('Content-Disposition: filename="qrcode.eps"');

examples/fpdf.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use chillerlan\QRCode\Data\QRMatrix;
1212
use chillerlan\QRCode\Output\QRFpdf;
1313

14-
require_once __DIR__ . '/../vendor/autoload.php';
14+
require_once __DIR__.'/../vendor/autoload.php';
1515

1616
$options = new QROptions;
1717

@@ -53,7 +53,7 @@
5353

5454
$out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
5555

56-
if(php_sapi_name() !== 'cli'){
56+
if(PHP_SAPI !== 'cli'){
5757
header('Content-type: application/pdf');
5858
}
5959

examples/imageWithLogo.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,11 @@
2424
class QRImageWithLogo extends QRGdImagePNG{
2525

2626
/**
27-
* @param string|null $file
28-
* @param string|null $logo
29-
*
30-
* @return string
3127
* @throws \chillerlan\QRCode\Output\QRCodeOutputException
3228
*/
3329
public function dump(string|null $file = null, string|null $logo = null):string{
30+
$logo ??= '';
31+
3432
// set returnResource to true to skip further processing for now
3533
$this->options->returnResource = true;
3634

@@ -45,6 +43,10 @@ public function dump(string|null $file = null, string|null $logo = null):string{
4543

4644
$im = imagecreatefrompng($logo);
4745

46+
if($im === false){
47+
throw new QRCodeOutputException('imagecreatefrompng() error');
48+
}
49+
4850
// get logo image size
4951
$w = imagesx($im);
5052
$h = imagesy($im);

examples/imageWithRoundedShapes.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,21 @@
1919
use chillerlan\QRCode\Output\QRGdImagePNG;
2020
use chillerlan\Settings\SettingsContainerInterface;
2121

22-
require_once __DIR__ . '/../vendor/autoload.php';
22+
require_once __DIR__.'/../vendor/autoload.php';
2323

2424
// --------------------
2525
// Class definition
2626
// --------------------
2727

2828
class QRGdRounded extends QRGdImagePNG{
2929

30-
/** @inheritDoc */
3130
public function __construct(SettingsContainerInterface|QROptions $options, QRMatrix $matrix){
3231
// enable the internal scaling for better rounding results at scale < 20
3332
$options->drawCircularModules = true;
3433

3534
parent::__construct($options, $matrix);
3635
}
3736

38-
/** @inheritDoc */
3937
protected function module(int $x, int $y, int $M_TYPE):void{
4038

4139
/**
@@ -121,7 +119,7 @@ protected function module(int $x, int $y, int $M_TYPE):void{
121119
(int)($y * $this->scale + $this->scale / 2),
122120
($this->scale - 1),
123121
($this->scale - 1),
124-
$light
122+
$light,
125123
);
126124
}
127125

@@ -133,14 +131,14 @@ protected function module(int $x, int $y, int $M_TYPE):void{
133131
// --------------------
134132

135133
$options = new QROptions([
136-
'version' => 7,
137-
'eccLevel' => EccLevel::H,
138-
'outputInterface' => QRGdRounded::class,
139-
'outputBase64' => false,
140-
'scale' => 30,
141-
'addLogoSpace' => true,
142-
'logoSpaceWidth' => 13,
143-
'logoSpaceHeight' => 13,
134+
'version' => 7,
135+
'eccLevel' => EccLevel::H,
136+
'outputInterface' => QRGdRounded::class,
137+
'outputBase64' => false,
138+
'scale' => 30,
139+
'addLogoSpace' => true,
140+
'logoSpaceWidth' => 13,
141+
'logoSpaceHeight' => 13,
144142
]);
145143

146144

examples/imageWithText.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
class QRImageWithText extends QRGdImagePNG{
2525

26-
/**
27-
* @inheritDoc
28-
*/
2926
public function dump(string|null $file = null, string|null $text = null):string{
3027
// set returnResource to true to skip further processing for now
3128
$this->options->returnResource = true;

examples/imagickConvertSVGtoPNG.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
* @author smiley <[email protected]>
1515
* @copyright 2023 smiley
1616
* @license MIT
17+
*
18+
* @noinspection PhpComposerExtensionStubsInspection
1719
*/
1820

1921
use chillerlan\QRCode\{QRCode, QROptions};
2022
use chillerlan\QRCode\Data\QRMatrix;
21-
use chillerlan\QRCode\Output\QRMarkupSVG;
23+
use chillerlan\QRCode\Output\{QRCodeOutputException, QRMarkupSVG};
2224

2325
require_once __DIR__.'/../vendor/autoload.php';
2426

2527
class SVGConvert extends QRMarkupSVG{
2628

27-
/** @inheritDoc */
2829
protected function header():string{
2930
[$width, $height] = $this->getOutputDimensions();
3031

@@ -36,7 +37,7 @@ protected function header():string{
3637
$this->options->svgPreserveAspectRatio,
3738
$this->options->eol,
3839
($width * $this->scale), // use the scale option to modify the size
39-
($height * $this->scale)
40+
($height * $this->scale),
4041
);
4142

4243
if($this->options->svgAddXmlHeader){
@@ -46,7 +47,6 @@ protected function header():string{
4647
return $header;
4748
}
4849

49-
/** @inheritDoc */
5050
public function dump(string|null $file = null):string{
5151
$base64 = $this->options->outputBase64;
5252
// we don't want the SVG in base64
@@ -70,7 +70,13 @@ public function dump(string|null $file = null):string{
7070

7171
if($base64){
7272
// use finfo to guess the mime type
73-
$imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData));
73+
$mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData);
74+
75+
if($mime === false){
76+
throw new QRCodeOutputException('unable to detect mime type');
77+
}
78+
79+
$imageData = $this->toBase64DataURI($imageData);
7480
}
7581

7682
return $imageData;

examples/imagickImageAsBackground.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,11 @@
1616

1717
class QRImagickImageAsBackground extends QRImagick{
1818

19-
/**
20-
* @inheritDoc
21-
*/
2219
protected function getDefaultModuleValue(bool $isDark):ImagickPixel{
2320
// RGBA, adjust opacity to increase contrast
2421
return $this->prepareModuleValue(($isDark) ? '#00000040' : '#ffffffa0');
2522
}
2623

27-
/**
28-
* @inheritDoc
29-
*/
3024
protected function createImage():Imagick{
3125
$imagick = new Imagick($this->options->background);
3226
$width = $imagick->getImageWidth();

0 commit comments

Comments
 (0)