Skip to content

feat: update psalm 4 => 5 #146

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"php": ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^7.5 | ^8.0 | ^9.0",
"phpunit/phpunit": "^10.5.17",
"rector/rector": "^1.0.4",
"symplify/easy-coding-standard": "^11.0",
"vimeo/psalm": "^4.24"
"vimeo/psalm": "^5.23.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion lib/Common/BitMatrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function set(int|float $x, int|float $y): void
//$this->bits[$offset] = intval32bits($this->bits[$offset]);

//}
//16777216
//16777216
}

public function _unset($x, $y): void
Expand Down
4 changes: 2 additions & 2 deletions lib/Common/Detector/MathUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ private function __construct()
* values. -2.5 rounds to -3, not -2. For purposes here it makes no difference.
*
* @param float $d real value to round
*
* @return int {@code int}
*
* @return int
*/
public static function round(float $d)
{
Expand Down
4 changes: 2 additions & 2 deletions lib/Common/Detector/MonochromeRectangleDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ private function findCornerFromCenter(
): \Zxing\ResultPoint {
$lastRange = null;
for ($y = $centerY, $x = $centerX;
$y < $bottom && $y >= $top && $x < $right && $x >= $left;
$y += $deltaY, $x += $deltaX) {
$y < $bottom && $y >= $top && $x < $right && $x >= $left;
$y += $deltaY, $x += $deltaX) {
$range = 0;
if ($deltaX == 0) {
// horizontal slices, up and down
Expand Down
2 changes: 2 additions & 0 deletions lib/Common/Reedsolomon/GenericGF.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ public function multiply(int|float|null $a, int|float|null $b)
return $this->expTable[($this->logTable[$a] + $this->logTable[$b]) % ($this->size - 1)];
}

/** @return int */
public function getSize()
{
return $this->size;
}

/** @return int */
public function getGeneratorBase()
{
return $this->generatorBase;
Expand Down
8 changes: 5 additions & 3 deletions lib/IMagickLuminanceSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,17 @@ public function rotateCounterClockwise45(): void
* Converts shorthand memory notation value to bytes
* From http://php.net/manual/en/function.ini-get.php
*
* @param int $val Memory size shorthand notation string
* @param string $val Memory size shorthand notation string
*
* @return float|int|string
*/
protected static function kmgStringToBytes(string $val)
protected static function kmgStringToBytes(string $val): int|float|string
{
$val = trim($val);
$last = strtolower($val[strlen($val) - 1]);
$val = substr($val, 0, -1);
switch ($last) {
// The 'G' modifier is available since PHP 5.1.0
// The 'G' modifier is available since PHP 5.1.0
case 'g':
$val *= 1024;
// no break
Expand Down
17 changes: 6 additions & 11 deletions lib/Qrcode/Decoder/Decoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,13 @@ public function __construct()
$this->rsDecoder = new ReedSolomonDecoder(GenericGF::$QR_CODE_FIELD_256);
}

public function decode(BitMatrix|BitMatrixParser $variable, array|null $hints = null): string|DecoderResult
/**
* @throws FormatException
* @throws ChecksumException
*/
public function decode(BitMatrix|BitMatrixParser $variable, array|null $hints = null): string|DecoderResult
{
if (is_array($variable)) {
return $this->decodeImage($variable, $hints);
} elseif ($variable instanceof BitMatrix) {
return $this->decodeBits($variable, $hints);
} elseif ($variable instanceof BitMatrixParser) {
return $this->decodeParser($variable, $hints);
}
die('decode error Decoder.php');
return $this->decodeBits($variable, $hints);
}

/**
Expand Down Expand Up @@ -93,7 +90,6 @@ public function decodeImage(array $image, $hints = null): string|DecoderResult
*/
public function decodeBits(\Zxing\Common\BitMatrix $bits, $hints = null): string|DecoderResult
{

// Construct a parser and read version, error-correction level
$parser = new BitMatrixParser($bits);
$fe = null;
Expand All @@ -107,7 +103,6 @@ public function decodeBits(\Zxing\Common\BitMatrix $bits, $hints = null): string
}

try {

// Revert the bit matrix
$parser->remask();

Expand Down
6 changes: 3 additions & 3 deletions lib/Qrcode/Detector/AlignmentPatternFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public function find()
return $this->possibleCenters[0];
}

throw new NotFoundException("Bottom right alignment pattern not found");
throw new NotFoundException("Bottom right alignment pattern not found");
}

/**
Expand Down Expand Up @@ -198,9 +198,9 @@ private static function centerFromEnd(array $stateCount, int $end)
* alignment pattern to see if the same proportion is detected.</p>
*
* @param int $startI row where an alignment pattern was detected
* @param float $centerJ center of the section that appears to cross an alignment pattern
* @param int $centerJ center of the section that appears to cross an alignment pattern
* @param int $maxCount maximum reasonable number of modules that should be
* observed in any reading state, based on the results of the horizontal scan
* observed in any reading state, based on the results of the horizontal scan
*
* @return float vertical center of alignment pattern, or {@link Float#NaN} if not found
*/
Expand Down
9 changes: 6 additions & 3 deletions lib/Qrcode/Detector/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use Zxing\DecodeHintType;
use Zxing\FormatException;
use Zxing\NotFoundException;
use Zxing\Qrcode\Decoder\Version;
use Zxing\ResultPoint;
use Zxing\ResultPointCallback;

Expand Down Expand Up @@ -54,7 +53,6 @@ public function __construct(private BitMatrix $image)
*/
final public function detect(array $hints = null): DetectorResult
{/*Map<DecodeHintType,?>*/

$resultPointCallback = ($hints !== null && array_key_exists('NEED_RESULT_POINT_CALLBACK', $hints)) ?
$hints['NEED_RESULT_POINT_CALLBACK'] : null;
/* resultPointCallback = hints == null ? null :
Expand Down Expand Up @@ -82,7 +80,6 @@ final protected function processFinderPatternInfo(FinderPatternInfo $info): \Zxi
$alignmentPattern = null;
// Anything above version 1 has an alignment pattern
if ((is_countable($provisionalVersion->getAlignmentPatternCenters()) ? count($provisionalVersion->getAlignmentPatternCenters()) : 0) > 0) {

// Guess where a "bottom right" finder pattern would have been
$bottomRightX = $topRight->getX() - $topLeft->getX() + $bottomLeft->getX();
$bottomRightY = $topRight->getY() - $topLeft->getY() + $bottomLeft->getY();
Expand Down Expand Up @@ -404,6 +401,9 @@ private static function createTransform(
);
}

/**
* @param BitMatrix $image
*/
private static function sampleGrid(
$image,
PerspectiveTransform $transform,
Expand All @@ -414,6 +414,9 @@ private static function sampleGrid(
return $sampler->sampleGrid_($image, $dimension, $dimension, $transform);
}

/**
* @return BitMatrix
*/
final protected function getImage()
{
return $this->image;
Expand Down
2 changes: 1 addition & 1 deletion lib/Qrcode/Detector/FinderPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

namespace Zxing\Qrcode\Detector;

use Zxing\ResultPoint;
use Zxing\ResultPoint;

/**
* <p>Encapsulates a finder pattern, which are the three square patterns found in
Expand Down
4 changes: 2 additions & 2 deletions lib/Qrcode/Detector/FinderPatternFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ final public function find(array|null $hints): \Zxing\Qrcode\Detector\FinderPatt
}

/**
* @param $stateCount ; count of black/white/black/white/black pixels just read
* @param int[] $stateCount
* @param $maxVariance ; count of black/white/black/white/black pixels just read
* @param int[] $maxVariance
*
* @return bool iff the proportions of the counts is close enough to the 1/1/3/1/1 ratios used by finder patterns to be considered a match
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Qrcode/QRCodeReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct()
}

/**
* @param null $hints
* @param array|null $hints
*
* @return Result
* @throws \Zxing\FormatException
Expand Down
3 changes: 1 addition & 2 deletions lib/ResultPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public function __construct($x, $y)
*/
public static function orderBestPatterns(array $patterns): array
{

// Find distances between pattern centers
// Find distances between pattern centers
$zeroOneDistance = self::distance($patterns[0], $patterns[1]);
$oneTwoDistance = self::distance($patterns[1], $patterns[2]);
$zeroTwoDistance = self::distance($patterns[0], $patterns[2]);
Expand Down
19 changes: 12 additions & 7 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">lib</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./vendor/autoload.php"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">

<testsuite name="Tests">
<directory suffix="Test.php">tests</directory>
<directory>tests</directory>
</testsuite>

<source>
<include>
<directory>lib</directory>
</include>
</source>

</phpunit>
1 change: 0 additions & 1 deletion psalm.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="8"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
6 changes: 3 additions & 3 deletions tests/QrReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function testNoText()
{
$image = __DIR__ . "/qrcodes/empty.png";
$qrcode = new QrReader($image);
$this->assertSame(false, $qrcode->text());
$this->assertFalse($qrcode->text());
}

public function testText2()
Expand All @@ -38,7 +38,7 @@ public function testText2()
'NR_ALLOW_SKIP_ROWS' => 0
];
$qrcode->decode($hints);
$this->assertSame(null, $qrcode->getError());
$this->assertNull($qrcode->getError());
$this->assertInstanceOf(Result::class, $qrcode->getResult());
$this->assertEquals("https://www.gosuslugi.ru/covid-cert/verify/9770000014233333?lang=ru&ck=733a9d218d312fe134f1c2cc06e1a800", $qrcode->getResult()->getText());
$this->assertSame("https://www.gosuslugi.ru/covid-cert/verify/9770000014233333?lang=ru&ck=733a9d218d312fe134f1c2cc06e1a800", $qrcode->text($hints));
Expand All @@ -51,7 +51,7 @@ public function testText3()
$qrcode->decode([
'TRY_HARDER' => true
]);
$this->assertSame(null, $qrcode->getError());
$this->assertNull($qrcode->getError());
$this->assertSame("https://www.gosuslugi.ru/covid-cert/verify/9770000014233333?lang=ru&ck=733a9d218d312fe134f1c2cc06e1a800", $qrcode->text());
}

Expand Down
Loading