:octocat: fix PHPCS config, add Slevomat rules

This commit is contained in:
smiley
2024-07-21 14:54:15 +02:00
parent 89cdd09044
commit f32696c8a7
97 changed files with 462 additions and 654 deletions
+9 -1
View File
@@ -81,9 +81,17 @@ trait BuildDirTrait{
/**
* returns the contents of the given build file
*
* @throws \RuntimeException
*/
protected function getBuildFileContent(string $fileSubPath):string{
return file_get_contents($this->getBuildFilePath($fileSubPath));
$content = file_get_contents($this->getBuildFilePath($fileSubPath));
if($content === false){
throw new RuntimeException('file_get_contents() error while reading build file');
}
return $content;
}
}
-6
View File
@@ -38,16 +38,10 @@ final class ByteTest extends DataInterfaceTestAbstract{
];
}
/**
* @inheritDoc
*/
public function testInvalidDataException():void{
$this::markTestSkipped('N/A (binary mode)');
}
/**
* @inheritDoc
*/
public function testBinaryStringInvalid():void{
$this::markTestSkipped('N/A (binary mode)');
}
+1 -1
View File
@@ -187,7 +187,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{
try{
$this::assertSame($version->getVersionNumber(), $minimumVersionNumber);
}
catch(ExpectationFailedException $e){
catch(ExpectationFailedException){
$this::assertSame(($version->getVersionNumber() + 1), $minimumVersionNumber, 'safety margin');
}
+2 -2
View File
@@ -76,7 +76,7 @@ final class HanziTest extends DataInterfaceTestAbstract{
try{
$this::assertTrue(Hanzi::validateString($chr));
}
catch(Throwable $e){
catch(Throwable){
/** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */
if(defined('TEST_IS_CI') && TEST_IS_CI === true){
$this::markTestSkipped();
@@ -85,7 +85,7 @@ final class HanziTest extends DataInterfaceTestAbstract{
$this::markTestSkipped(sprintf(
'invalid glyph: %s => %s',
bin2hex(mb_convert_encoding($chr, Hanzi::ENCODING, 'UTF-8')),
$chr
$chr,
));
}
}
+2 -2
View File
@@ -103,7 +103,7 @@ final class KanjiTest extends DataInterfaceTestAbstract{
try{
$this::assertTrue(Kanji::validateString($chr));
}
catch(Throwable $e){
catch(Throwable){
/** @noinspection PhpUndefinedConstantInspection - see phpunit.xml.dist */
if(defined('TEST_IS_CI') && TEST_IS_CI === true){
$this::markTestSkipped();
@@ -112,7 +112,7 @@ final class KanjiTest extends DataInterfaceTestAbstract{
$this::markTestSkipped(sprintf(
'invalid glyph: %s => %s',
bin2hex(mb_convert_encoding($chr, Kanji::ENCODING, 'UTF-8')),
$chr
$chr,
));
}
}
-3
View File
@@ -21,9 +21,6 @@ use chillerlan\QRCode\QROptions;
use chillerlan\QRCodeTest\QRMatrixDebugTrait;
use PHPUnit\Framework\TestCase;
/**
*
*/
final class QRDataTest extends TestCase{
use QRMatrixDebugTrait;
+1 -1
View File
@@ -33,7 +33,7 @@ final class QRMatrixTest extends TestCase{
protected function setUp():void{
$this->matrix = new QRMatrix(
new Version($this::version),
new EccLevel(EccLevel::L)
new EccLevel(EccLevel::L),
);
}
+1 -4
View File
@@ -31,14 +31,11 @@ class QREpsTest extends QROutputTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QREps($options, $matrix);
}
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->moduleValues = [
+1 -7
View File
@@ -23,9 +23,6 @@ use function class_exists;
final class QRFpdfTest extends QROutputTestAbstract{
use RGBArrayModuleValueProviderTrait;
/**
* @inheritDoc
*/
protected function setUp():void{
if(!class_exists(FPDF::class)){
@@ -37,14 +34,11 @@ final class QRFpdfTest extends QROutputTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRFpdf($options, $matrix);
}
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->moduleValues = [
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRGdImageAVIF, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRGdImageAVIFTest extends QRGdImageTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRGdImageAVIF($options, $matrix);
}
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRGdImageBMP, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRGdImageBMPTest extends QRGdImageTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRGdImageBMP($options, $matrix);
}
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRGdImageGIF, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRGdImageGIFTest extends QRGdImageTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRGdImageGIF($options, $matrix);
}
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRGdImageJPEG, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRGdImageJPGTest extends QRGdImageTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRGdImageJPEG($options, $matrix);
}
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRGdImagePNG, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRGdImagePNGTest extends QRGdImageTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRGdImagePNG($options, $matrix);
}
-6
View File
@@ -22,9 +22,6 @@ use function extension_loaded;
abstract class QRGdImageTestAbstract extends QROutputTestAbstract{
use RGBArrayModuleValueProviderTrait;
/**
* @inheritDoc
*/
protected function setUp():void{
if(!extension_loaded('gd')){
@@ -34,9 +31,6 @@ abstract class QRGdImageTestAbstract extends QROutputTestAbstract{
parent::setUp();
}
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->moduleValues = [
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRGdImageWEBP, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRGdImageWEBPTest extends QRGdImageTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRGdImageWEBP($options, $matrix);
}
+1 -7
View File
@@ -24,9 +24,6 @@ use function extension_loaded;
*/
final class QRImagickTest extends QROutputTestAbstract{
/**
* @inheritDoc
*/
protected function setUp():void{
if(!extension_loaded('imagick')){
@@ -38,7 +35,7 @@ final class QRImagickTest extends QROutputTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRImagick($options, $matrix);
}
@@ -69,9 +66,6 @@ final class QRImagickTest extends QROutputTestAbstract{
];
}
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->moduleValues = [
+1 -7
View File
@@ -24,9 +24,6 @@ use function extension_loaded;
class QRInterventionImageTest extends QROutputTestAbstract{
use CssColorModuleValueProviderTrait;
/**
* @inheritDoc
*/
protected function setUp():void{
if(!extension_loaded('gd')){
@@ -38,14 +35,11 @@ class QRInterventionImageTest extends QROutputTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRInterventionImage($options, $matrix);
}
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->moduleValues = [
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRMarkupHTML, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRMarkupHTMLTest extends QRMarkupTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRMarkupHTML($options, $matrix);
}
+1 -4
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRMarkupSVG, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRMarkupSVGTest extends QRMarkupTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRMarkupSVG($options, $matrix);
}
-3
View File
@@ -18,9 +18,6 @@ use chillerlan\QRCode\Data\QRMatrix;
abstract class QRMarkupTestAbstract extends QROutputTestAbstract{
use CssColorModuleValueProviderTrait;
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->outputBase64 = false;
$this->options->drawLightModules = true;
-3
View File
@@ -15,9 +15,6 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QRMarkupXML, QROutputInterface};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
class QRMarkupXMLTest extends QRMarkupTestAbstract{
protected function getOutputInterface(
+1 -7
View File
@@ -15,22 +15,16 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QROutputInterface, QRStringJSON};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRStringJSONTest extends QROutputTestAbstract{
use CssColorModuleValueProviderTrait;
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRStringJSON($options, $matrix);
}
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->moduleValues = [
+1 -7
View File
@@ -15,14 +15,11 @@ use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\{QROutputInterface, QRStringText};
use chillerlan\Settings\SettingsContainerInterface;
/**
*
*/
final class QRStringTextTest extends QROutputTestAbstract{
protected function getOutputInterface(
SettingsContainerInterface|QROptions $options,
QRMatrix $matrix
QRMatrix $matrix,
):QROutputInterface{
return new QRStringText($options, $matrix);
}
@@ -39,9 +36,6 @@ final class QRStringTextTest extends QROutputTestAbstract{
];
}
/**
* @inheritDoc
*/
public function testSetModuleValues():void{
$this->options->moduleValues = [
+1 -1
View File
@@ -21,7 +21,7 @@ final class QRCodeReaderGDTest extends QRCodeReaderTestAbstract{
protected function getLuminanceSourceFromFile(
string $file,
SettingsContainerInterface|QROptions $options
SettingsContainerInterface|QROptions $options,
):LuminanceSourceInterface{
return GDLuminanceSource::fromFile($file, $options);
}
+1 -1
View File
@@ -36,7 +36,7 @@ final class QRCodeReaderImagickTest extends QRCodeReaderTestAbstract{
protected function getLuminanceSourceFromFile(
string $file,
SettingsContainerInterface|QROptions $options
SettingsContainerInterface|QROptions $options,
):LuminanceSourceInterface{
return IMagickLuminanceSource::fromFile($file, $options);
}
+10 -3
View File
@@ -20,6 +20,7 @@ use chillerlan\Settings\SettingsContainerInterface;
use PHPUnit\Framework\Attributes\{DataProvider, Group};
use PHPUnit\Framework\TestCase;
use Exception, Generator;
use RuntimeException;
use function array_map, defined, realpath, sprintf, str_repeat, substr;
/**
@@ -83,7 +84,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{
abstract protected function getLuminanceSourceFromFile(
string $file,
SettingsContainerInterface|QROptions $options
SettingsContainerInterface|QROptions $options,
):LuminanceSourceInterface;
#[Group('slow')]
@@ -95,7 +96,13 @@ abstract class QRCodeReaderTestAbstract extends TestCase{
$this->options->readerIncreaseContrast = true;
}
$luminanceSource = $this->getLuminanceSourceFromFile(realpath($this::samplesDir.$img), $this->options);
$file = realpath($this::samplesDir.$img);
if($file === false){
throw new RuntimeException(sprintf('invalid file given: "%s" in samples directory "%s"', $img, $this::samplesDir));
}
$luminanceSource = $this->getLuminanceSourceFromFile($file, $this->options);
$result = (new Decoder)->decode($luminanceSource);
$this->debugMatrix($result->getQRMatrix());
@@ -141,7 +148,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{
yield 'version: '.$version.$eccLevel => [
$version,
$eccLevel,
substr($str, 0, (self::getMaxLengthForMode(Mode::BYTE, $version, $eccLevel) ?? '')),
substr($str, 0, self::getMaxLengthForMode(Mode::BYTE, $version, $eccLevel)),
];
}
}
+1 -1
View File
@@ -72,7 +72,7 @@ trait QRMatrixDebugTrait{
$out = (new QRStringText($options, $matrix))->dump();
printf("\n\n%s\n\n", $out) ;
printf("\n\n%s\n\n", $out);
}
/**
+1 -1
View File
@@ -25,7 +25,7 @@ trait QRMaxLengthTrait{
*
* @var int[][][]
*/
protected const MAX_LENGTH =[
protected const MAX_LENGTH = [
// v => [NUMERIC => [L, M, Q, H ], ALPHANUM => [L, M, Q, H], BINARY => [L, M, Q, H ], KANJI => [L, M, Q, H ]]
1 => [[ 41, 34, 27, 17], [ 25, 20, 16, 10], [ 17, 14, 11, 7], [ 10, 8, 7, 4]],
2 => [[ 77, 63, 48, 34], [ 47, 38, 29, 20], [ 32, 26, 20, 14], [ 20, 16, 12, 8]],