Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Going all in on linting #109

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 0 additions & 61 deletions .php-cs-fixer.dist.php

This file was deleted.

13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
},
"require-dev": {
"phpunit/phpunit": "^9",
"friendsofphp/php-cs-fixer": "^3.13",
"phpstan/phpstan": "^1.9"
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpstan/phpstan": "^1.9",
"symplify/easy-coding-standard": "^11.3"
},
"suggest": {
"bacon/bacon-qr-code": "Needed for BaconQrCodeProvider provider",
Expand All @@ -50,13 +51,15 @@
},
"scripts": {
"phpstan": [
"phpstan analyze --xdebug lib tests testsDependency"
"phpstan analyze"
],
"lint": [
"php-cs-fixer fix -v"
"parallel-lint --exclude vendor .",
"ecs --fix"
],
"lint-ci": [
"PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -v --dry-run --stop-on-violation"
"parallel-lint --exclude vendor .",
"ecs"
],
"test": [
"XDEBUG_MODE=coverage phpunit"
Expand Down
33 changes: 33 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer;
use PhpCsFixer\Fixer\Whitespace\TypesSpacesFixer;
use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/lib',
__DIR__ . '/tests',
__DIR__ . '/testsDependency',
]);

$ecsConfig->sets([
SetList::ARRAY,
SetList::CLEAN_CODE,
SetList::CONTROL_STRUCTURES,
SetList::DOCBLOCK,
SetList::NAMESPACES,
SetList::PSR_12,
SetList::SPACES,
]);

$ecsConfig->dynamicSets([
'@PHP82Migration',
]);

$ecsConfig->rule(ArraySyntaxFixer::class);
$ecsConfig->rule(TypesSpacesFixer::class);
};
8 changes: 4 additions & 4 deletions lib/Providers/Qr/BaconQrCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __construct(
private readonly int $borderWidth = 4,
private string|array $backgroundColour = '#ffffff',
private string|array $foregroundColour = '#000000',
private string $format = 'png',
private string $format = 'png',
) {
$this->backgroundColour = $this->handleColour($this->backgroundColour);
$this->foregroundColour = $this->handleColour($this->foregroundColour);
Expand Down Expand Up @@ -75,10 +75,10 @@ public function getQRCodeImage(string $qrText, int $size): string
*/
private function getQRCodeByBackend($qrText, $size, ImageBackEndInterface $backend)
{
$rendererStyleArgs = array($size, $this->borderWidth);
$rendererStyleArgs = [$size, $this->borderWidth];

if (is_array($this->foregroundColour) && is_array($this->backgroundColour)) {
$rendererStyleArgs = array(...$rendererStyleArgs, ...array(
$rendererStyleArgs = [...$rendererStyleArgs, ...[
null,
null,
Fill::withForegroundColor(
Expand All @@ -88,7 +88,7 @@ private function getQRCodeByBackend($qrText, $size, ImageBackEndInterface $backe
new EyeFill(null, null),
new EyeFill(null, null)
),
));
]];
}

$writer = new Writer(new ImageRenderer(
Expand Down
4 changes: 2 additions & 2 deletions lib/Providers/Qr/BaseHTTPQRCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ protected function getContent(string $url): string|bool
{
$curlhandle = curl_init();

curl_setopt_array($curlhandle, array(
curl_setopt_array($curlhandle, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_DNS_CACHE_TIMEOUT => 10,
CURLOPT_TIMEOUT => 10,
CURLOPT_SSL_VERIFYPEER => $this->verifyssl,
CURLOPT_USERAGENT => 'TwoFactorAuth',
));
]);
$data = curl_exec($curlhandle);

curl_close($curlhandle);
Expand Down
11 changes: 9 additions & 2 deletions lib/Providers/Qr/EndroidQrCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getMimeType(): string

public function getQRCodeImage(string $qrText, int $size): string
{
if (!$this->endroid4) {
if (! $this->endroid4) {
return $this->qrCodeInstance($qrText, $size)->writeString();
}

Expand Down Expand Up @@ -71,7 +71,14 @@ private function handleColor(string $color): Color|array
$g = hexdec($split[1]);
$b = hexdec($split[2]);

return $this->endroid4 ? new Color($r, $g, $b, 0) : array('r' => $r, 'g' => $g, 'b' => $b, 'a' => 0);
return $this->endroid4
? new Color($r, $g, $b, 0)
: [
'r' => $r,
'g' => $g,
'b' => $b,
'a' => 0,
];
}

private function handleErrorCorrectionLevel(string $level): ErrorCorrectionLevelInterface|ErrorCorrectionLevel
Expand Down
6 changes: 3 additions & 3 deletions lib/Providers/Qr/EndroidQrCodeWithLogoProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ class EndroidQrCodeWithLogoProvider extends EndroidQrCodeProvider
public function setLogo($path, $size = null)
{
$this->logoPath = $path;
$this->logoSize = (array)$size;
$this->logoSize = (array) $size;
}

public function getQRCodeImage(string $qrText, int $size): string
{
if (!$this->endroid4) {
if (! $this->endroid4) {
return $this->qrCodeInstance($qrText, $size)->writeString();
}

Expand All @@ -49,7 +49,7 @@ protected function qrCodeInstance(string $qrText, int $size): QrCode
{
$qrCode = parent::qrCodeInstance($qrText, $size);

if (!$this->endroid4 && $this->logoPath) {
if (! $this->endroid4 && $this->logoPath) {
$qrCode->setLogoPath($this->logoPath);
if ($this->logoSize) {
$qrCode->setLogoSize($this->logoSize[0], $this->logoSize[1] ?? null);
Expand Down
12 changes: 8 additions & 4 deletions lib/Providers/Qr/GoogleChartsQrCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
// https://developers.google.com/chart/infographics/docs/qr_codes
class GoogleChartsQrCodeProvider extends BaseHTTPQRCodeProvider
{
public function __construct(protected bool $verifyssl = false, public string $errorcorrectionlevel = 'L', public int $margin = 4, public string $encoding = 'UTF-8')
{
public function __construct(
protected bool $verifyssl = false,
public string $errorcorrectionlevel = 'L',
public int $margin = 4,
public string $encoding = 'UTF-8'
) {
}

public function getMimeType(): string
Expand All @@ -23,13 +27,13 @@ public function getQRCodeImage(string $qrText, int $size): string

public function getUrl(string $qrText, int $size): string
{
$queryParameters = array(
$queryParameters = [
'chs' => $size . 'x' . $size,
'chld' => strtoupper($this->errorcorrectionlevel) . '|' . $this->margin,
'cht' => 'qr',
'choe' => $this->encoding,
'chl' => $qrText,
);
];

return 'https://chart.googleapis.com/chart?' . http_build_query($queryParameters);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Providers/Qr/HandlesDataUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ trait HandlesDataUri
private function DecodeDataUri(string $datauri): ?array
{
if (preg_match('/data:(?P<mimetype>[\w\.\-\+\/]+);(?P<encoding>\w+),(?P<data>.*)/', $datauri, $m) === 1) {
return array(
return [
'mimetype' => $m['mimetype'],
'encoding' => $m['encoding'],
'data' => base64_decode($m['data'], true),
);
];
}

return null;
Expand Down
11 changes: 7 additions & 4 deletions lib/Providers/Qr/ImageChartsQRCodeProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
*/
class ImageChartsQRCodeProvider extends BaseHTTPQRCodeProvider
{
public function __construct(protected bool $verifyssl = false, public string $errorcorrectionlevel = 'L', public int $margin = 1)
{
public function __construct(
protected bool $verifyssl = false,
public string $errorcorrectionlevel = 'L',
public int $margin = 1
) {
}

public function getMimeType(): string
Expand All @@ -25,12 +28,12 @@ public function getQRCodeImage(string $qrText, int $size): string

public function getUrl(string $qrText, int $size): string
{
$queryParameters = array(
$queryParameters = [
'cht' => 'qr',
'chs' => ceil($size / 2) . 'x' . ceil($size / 2),
'chld' => $this->errorcorrectionlevel . '|' . $this->margin,
'chl' => $qrText,
);
];

return 'https://image-charts.com/chart?' . http_build_query($queryParameters);
}
Expand Down
15 changes: 11 additions & 4 deletions lib/Providers/Qr/QRServerProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
*/
class QRServerProvider extends BaseHTTPQRCodeProvider
{
public function __construct(protected bool $verifyssl = false, public string $errorcorrectionlevel = 'L', public int $margin = 4, public int $qzone = 1, public string $bgcolor = 'ffffff', public string $color = '000000', public string $format = 'png')
{
public function __construct(
protected bool $verifyssl = false,
public string $errorcorrectionlevel = 'L',
public int $margin = 4,
public int $qzone = 1,
public string $bgcolor = 'ffffff',
public string $color = '000000',
public string $format = 'png'
) {
}

public function getMimeType(): string
Expand Down Expand Up @@ -38,7 +45,7 @@ public function getQRCodeImage(string $qrText, int $size): string

public function getUrl(string $qrText, int $size): string
{
$queryParameters = array(
$queryParameters = [
'size' => $size . 'x' . $size,
'ecc' => strtoupper($this->errorcorrectionlevel),
'margin' => $this->margin,
Expand All @@ -47,7 +54,7 @@ public function getUrl(string $qrText, int $size): string
'color' => $this->decodeColor($this->color),
'format' => strtolower($this->format),
'data' => $qrText,
);
];

return 'https://api.qrserver.com/v1/create-qr-code/?' . http_build_query($queryParameters);
}
Expand Down
12 changes: 8 additions & 4 deletions lib/Providers/Qr/QRicketProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
*/
class QRicketProvider extends BaseHTTPQRCodeProvider
{
public function __construct(public string $errorcorrectionlevel = 'L', public string $bgcolor = 'ffffff', public string $color = '000000', public string $format = 'p')
{
public function __construct(
public string $errorcorrectionlevel = 'L',
public string $bgcolor = 'ffffff',
public string $color = '000000',
public string $format = 'p'
) {
$this->verifyssl = false;
}

Expand All @@ -34,14 +38,14 @@ public function getQRCodeImage(string $qrText, int $size): string

public function getUrl(string $qrText, int $size): string
{
$queryParameters = array(
$queryParameters = [
'qrsize' => $size,
'e' => strtolower($this->errorcorrectionlevel),
'bgdcolor' => $this->bgcolor,
'fgdcolor' => $this->color,
't' => strtolower($this->format),
'd' => $qrText,
);
];

return 'http://qrickit.com/api/qr?' . http_build_query($queryParameters);
}
Expand Down
6 changes: 0 additions & 6 deletions lib/Providers/Rng/CSRNGProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,11 @@

class CSRNGProvider implements IRNGProvider
{
/**
* {@inheritdoc}
*/
public function getRandomBytes(int $bytecount): string
{
return random_bytes($bytecount); // PHP7+
}

/**
* {@inheritdoc}
*/
public function isCryptographicallySecure(): bool
{
return true;
Expand Down
Loading