diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b7333e2..96b6c71 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - php: ['7.4', '8.0', '8.1', '8.2', '8.3'] + php: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout uses: actions/checkout@v2 diff --git a/phpstan.neon b/phpstan.neon index 48e664e..e602b7c 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ parameters: level: 5 + treatPhpDocTypesAsCertain: false paths: - src #- tests diff --git a/src/GraphicsState.php b/src/GraphicsState.php index 27feafb..f8da2b1 100644 --- a/src/GraphicsState.php +++ b/src/GraphicsState.php @@ -26,10 +26,12 @@ class GraphicsState /** * @param Matrix|null $ctm */ - public function __construct(Matrix $ctm = null) + public function __construct($ctm = null) { if ($ctm === null) { $ctm = new Matrix(); + } elseif (!($ctm instanceof Matrix)) { + throw new \InvalidArgumentException('$ctm must be an instance of Fpdi\\Matrix or null'); } $this->ctm = $ctm; diff --git a/src/PdfParser/Type/PdfDictionary.php b/src/PdfParser/Type/PdfDictionary.php index 8991322..9859afc 100644 --- a/src/PdfParser/Type/PdfDictionary.php +++ b/src/PdfParser/Type/PdfDictionary.php @@ -107,8 +107,11 @@ public static function create(array $entries = []) * @return PdfNull|PdfType * @throws PdfTypeException */ - public static function get($dictionary, $key, PdfType $default = null) + public static function get($dictionary, $key, $default = null) { + if ($default !== null && !($default instanceof PdfType)) { + throw new \InvalidArgumentException('Default value must be an instance of PdfType or null'); + } $dictionary = self::ensure($dictionary); if (isset($dictionary->value[$key])) { diff --git a/src/PdfParser/Type/PdfStream.php b/src/PdfParser/Type/PdfStream.php index cfa2cdb..a23fd0d 100644 --- a/src/PdfParser/Type/PdfStream.php +++ b/src/PdfParser/Type/PdfStream.php @@ -31,12 +31,15 @@ class PdfStream extends PdfType * * @param PdfDictionary $dictionary * @param StreamReader $reader - * @param PdfParser $parser Optional to keep backwards compatibility + * @param PdfParser|null $parser Optional to keep backwards compatibility * @return self * @throws PdfTypeException */ - public static function parse(PdfDictionary $dictionary, StreamReader $reader, PdfParser $parser = null) + public static function parse(PdfDictionary $dictionary, StreamReader $reader, $parser = null) { + if ($parser !== null && !($parser instanceof PdfParser)) { + throw new \InvalidArgumentException('$parser must be an instance of PdfParser or null'); + } $v = new self(); $v->value = $dictionary; $v->reader = $reader;