mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-24 14:17:50 +00:00
:octocat: reintroducing phan because phpstan keeps making trouble
This commit is contained in:
@@ -21,6 +21,10 @@ jobs:
|
||||
name: "Static Code Analysis"
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
env:
|
||||
PHAN_ALLOW_XDEBUG: 0
|
||||
PHAN_DISABLE_XDEBUG_WARN: 1
|
||||
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
@@ -37,19 +41,22 @@ jobs:
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php-version }}
|
||||
extensions: ${{ env.PHP_EXTENSIONS }}
|
||||
extensions: ast, ${{ env.PHP_EXTENSIONS }}
|
||||
ini-values: ${{ env.PHP_INI_VALUES }}
|
||||
coverage: none
|
||||
|
||||
- name: "Install dependencies with composer"
|
||||
uses: ramsey/composer-install@v3
|
||||
|
||||
- name: "Run PHPStan"
|
||||
run: php vendor/bin/phpstan
|
||||
- name: "Run phan"
|
||||
run: php vendor/bin/phan --target-php-version=${{ matrix.php-version }}
|
||||
|
||||
- name: "Run PHP_CodeSniffer"
|
||||
run: php vendor/bin/phpcs
|
||||
|
||||
# - name: "Run PHPStan"
|
||||
# run: php vendor/bin/phpstan
|
||||
|
||||
|
||||
tests:
|
||||
name: "Unit Tests"
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* This configuration will be read and overlaid on top of the
|
||||
* default configuration. Command-line arguments will be applied
|
||||
* after this file is read.
|
||||
*/
|
||||
return [
|
||||
// If this is set to `null`,
|
||||
// then Phan assumes the PHP version which is closest to the minor version
|
||||
// of the php executable used to execute Phan.
|
||||
//
|
||||
// Note that the **only** effect of choosing `'5.6'` is to infer
|
||||
// that functions removed in php 7.0 exist.
|
||||
// (See `backward_compatibility_checks` for additional options)
|
||||
'target_php_version' => null,
|
||||
'minimum_target_php_version' => '8.2',
|
||||
|
||||
// A list of directories that should be parsed for class and
|
||||
// method information. After excluding the directories
|
||||
// defined in exclude_analysis_directory_list, the remaining
|
||||
// files will be statically analyzed for errors.
|
||||
//
|
||||
// Thus, both first-party and third-party code being used by
|
||||
// your application should be included in this list.
|
||||
'directory_list' => [
|
||||
'examples',
|
||||
'src',
|
||||
'tests',
|
||||
'vendor',
|
||||
'.phan/stubs',
|
||||
],
|
||||
|
||||
// A regex used to match every file name that you want to
|
||||
// exclude from parsing. Actual value will exclude every
|
||||
// "test", "tests", "Test" and "Tests" folders found in
|
||||
// "vendor/" directory.
|
||||
'exclude_file_regex' => '@^vendor/.*/(tests?|Tests?)/@',
|
||||
|
||||
// A directory list that defines files that will be excluded
|
||||
// from static analysis, but whose class and method
|
||||
// information should be included.
|
||||
//
|
||||
// Generally, you'll want to include the directories for
|
||||
// third-party code (such as "vendor/") in this list.
|
||||
//
|
||||
// n.b.: If you'd like to parse but not analyze 3rd
|
||||
// party code, directories containing that code
|
||||
// should be added to both the `directory_list`
|
||||
// and `exclude_analysis_directory_list` arrays.
|
||||
'exclude_analysis_directory_list' => [
|
||||
'vendor/',
|
||||
'.phan/stubs',
|
||||
],
|
||||
'suppress_issue_types' => [
|
||||
'PhanAccessMethodInternal',
|
||||
'PhanAccessOverridesFinalConstant',
|
||||
'PhanDeprecatedClass',
|
||||
'PhanDeprecatedClassConstant',
|
||||
'PhanNoopNew',
|
||||
'PhanTypePossiblyInvalidDimOffset',
|
||||
],
|
||||
];
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Miscellaneous stubs for phan
|
||||
*
|
||||
* @created 25.01.2021
|
||||
* @author smiley <smiley@chillerlan.net>
|
||||
* @copyright 2021 smiley
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
#class GdImage{}
|
||||
@@ -55,6 +55,7 @@
|
||||
"ext-fileinfo": "*",
|
||||
"chillerlan/php-authenticator": "^5.2.1",
|
||||
"intervention/image": "^3.11",
|
||||
"phan/phan": "^5.5.0",
|
||||
"phpbench/phpbench": "^1.4",
|
||||
"phpunit/phpunit": "^11.5",
|
||||
"phpmd/phpmd": "^2.15",
|
||||
@@ -82,6 +83,7 @@
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"phan": "@php vendor/bin/phan",
|
||||
"phpbench":[
|
||||
"Composer\\Config::disableProcessTimeout",
|
||||
"@php vendor/bin/phpbench run"
|
||||
|
||||
@@ -61,7 +61,8 @@ class MyCustomOutput extends QROutputAbstract{
|
||||
$options = new QROptions;
|
||||
|
||||
$options->version = 5;
|
||||
$options->eccLevel = 'L';
|
||||
/** @phan-suppress-next-line PhanTypeMismatchPropertyProbablyReal */
|
||||
$options->eccLevel = 'L'; // can be assigned as string
|
||||
|
||||
$data = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ';
|
||||
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ final class Mode{
|
||||
/**
|
||||
* Map of data mode => interface (detection order)
|
||||
*
|
||||
* @var array<int, (\chillerlan\QRCode\Data\QRDataModeInterface|string)>
|
||||
* @var array<int, string>
|
||||
*/
|
||||
public const INTERFACES = [
|
||||
self::NUMBER => Number::class,
|
||||
|
||||
@@ -100,6 +100,7 @@ final class AlphaNum extends QRDataModeAbstract{
|
||||
* @throws \chillerlan\QRCode\Data\QRCodeDataException
|
||||
*/
|
||||
private function ord(string $chr):int{
|
||||
/** @phan-suppress-next-line PhanParamSuspiciousOrder */
|
||||
$ord = strpos(self::CHAR_MAP, $chr);
|
||||
|
||||
if($ord === false){
|
||||
|
||||
@@ -186,6 +186,7 @@ class QRMatrix{
|
||||
* Returns a boolean representation of the data matrix
|
||||
*
|
||||
* @return bool[][]
|
||||
* @phan-suppress PhanTypeMismatchReturn
|
||||
*/
|
||||
public function getBooleanMatrix():array{
|
||||
$matrix = $this->matrix;
|
||||
@@ -594,6 +595,7 @@ class QRMatrix{
|
||||
* Rotates the matrix by 90 degrees clock wise
|
||||
*/
|
||||
public function rotate90():static{
|
||||
/** @phan-suppress-next-line PhanParamTooFewInternalUnpack */
|
||||
$this->matrix = array_map((fn(int ...$a):array => array_reverse($a)), ...$this->matrix);
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
* @author smiley <smiley@chillerlan.net>
|
||||
* @copyright 2024 smiley
|
||||
* @license MIT
|
||||
*
|
||||
* @phan-file-suppress PhanTypeMismatchDeclaredParamNullable
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
|
||||
final public const MIME_TYPE = 'application/pdf';
|
||||
|
||||
/** @var int[] */
|
||||
/** @var int[]|null */
|
||||
protected array|null $prevColor = null;
|
||||
protected FPDF $fpdf;
|
||||
|
||||
@@ -70,7 +70,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
if($this::moduleValueIsValid($this->options->bgColor)){
|
||||
$bgColor = $this->prepareModuleValue($this->options->bgColor);
|
||||
[$width, $height] = $this->getOutputDimensions();
|
||||
|
||||
/** @phan-suppress-next-line PhanParamTooFewUnpack */
|
||||
$this->fpdf->SetFillColor(...$bgColor);
|
||||
$this->fpdf->Rect(0, 0, $width, $height, 'F');
|
||||
}
|
||||
@@ -110,6 +110,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
$color = $this->getModuleValue($M_TYPE);
|
||||
|
||||
if($color !== null && $color !== $this->prevColor){
|
||||
/** @phan-suppress-next-line PhanParamTooFewUnpack */
|
||||
$this->fpdf->SetFillColor(...$color);
|
||||
$this->prevColor = $color;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,7 @@ abstract class QRGdImage extends QROutputAbstract{
|
||||
$values[] = max(0, min(255, intval($val)));
|
||||
}
|
||||
|
||||
/** @phan-suppress-next-line PhanParamTooFewInternalUnpack */
|
||||
$color = imagecolorallocate($this->image, ...$values);
|
||||
|
||||
if($color === false){
|
||||
|
||||
@@ -13,7 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace chillerlan\QRCode\Output;
|
||||
|
||||
use function imageavif, max, min;
|
||||
use function imageavif;
|
||||
|
||||
/**
|
||||
* GDImage avif output
|
||||
|
||||
@@ -13,7 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace chillerlan\QRCode\Output;
|
||||
|
||||
use function imagejpeg, max, min;
|
||||
use function imagejpeg;
|
||||
|
||||
/**
|
||||
* GdImage jpeg output
|
||||
|
||||
@@ -13,7 +13,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace chillerlan\QRCode\Output;
|
||||
|
||||
use function imagewebp, max, min;
|
||||
use function imagewebp;
|
||||
|
||||
/**
|
||||
* GdImage webp output
|
||||
|
||||
@@ -23,7 +23,7 @@ class QRStringText extends QROutputAbstract{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param string $value
|
||||
* @param string|mixed $value
|
||||
*/
|
||||
public static function moduleValueIsValid(mixed $value):bool{
|
||||
return is_string($value);
|
||||
@@ -32,7 +32,7 @@ class QRStringText extends QROutputAbstract{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*
|
||||
* @param string $value
|
||||
* @param string|mixed $value
|
||||
*/
|
||||
protected function prepareModuleValue(mixed $value):string{
|
||||
return $value;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
* @author smiley <smiley@chillerlan.net>
|
||||
* @copyright 2024 smiley
|
||||
* @license MIT
|
||||
*
|
||||
* @phan-file-suppress PhanTypeMismatchDeclaredParamNullable
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ abstract class DataInterfaceTestAbstract extends TestCase{
|
||||
public static function maxLengthProvider():Generator{
|
||||
$eccLevels = array_map(fn(int $ecc):EccLevel => new EccLevel($ecc), [EccLevel::L, EccLevel::M, EccLevel::Q, EccLevel::H]);
|
||||
$str = str_repeat(static::testData, 1000);
|
||||
|
||||
/** @phan-suppress-next-line PhanAbstractStaticMethodCallInStatic */
|
||||
$dataMode = static::getDataModeInterface(static::testData)::DATAMODE;
|
||||
$mb = ($dataMode === Mode::KANJI || $dataMode === Mode::HANZI);
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ final class ECITest extends TestCase{
|
||||
private function getDataSegments():array{
|
||||
return [
|
||||
new ECI($this->testCharset),
|
||||
/** @phan-suppress-next-line PhanParamSuspiciousOrder */
|
||||
new Byte(mb_convert_encoding(self::testData, ECICharset::MB_ENCODINGS[$this->testCharset], mb_internal_encoding())),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
* @license MIT
|
||||
*
|
||||
* @noinspection PhpComposerExtensionStubsInspection
|
||||
* @phan-file-suppress PhanUndeclaredConstant
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ final class QROptionsTest extends TestCase{
|
||||
|
||||
/**
|
||||
* Tests setting the ECC level from string or int
|
||||
*
|
||||
* @phan-suppress PhanTypeMismatchPropertyProbablyReal
|
||||
*/
|
||||
public function testSetEccLevel():void{
|
||||
$o = new QROptions(['eccLevel' => EccLevel::H]);
|
||||
|
||||
Reference in New Issue
Block a user