diff --git a/.editorconfig b/.editorconfig index ee55bc7..2654275 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,6 @@ trim_trailing_whitespace = true [*.yml] indent_size = 2 + +[*.neon] +indent_style = tab diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e337bf3..5625070 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,11 +17,12 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.1', '8.2'] - prefer-lowest: [''] + php-version: ['8.1', '8.2', '8.3'] include: - php-version: '8.1' - prefer-lowest: 'prefer-lowest' + composer-options: '--ignore-platform-req=php' + - php-version: '8.1' + dependencies: lowest steps: - uses: actions/checkout@v4 @@ -42,27 +43,25 @@ jobs: wkhtmltopdf --version - name: Composer install - run: | - if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then - composer update --prefer-lowest --prefer-stable - else - composer install - fi + uses: ramsey/composer-install@v3 + with: + dependency-versions: ${{ matrix.dependencies }} + composer-options: ${{ matrix.composer-options }} - name: Setup problem matchers for PHPUnit run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - name: Run PHPUnit run: | - if [[ ${{ matrix.php-version }} == '8.1' ]]; then - vendor/bin/phpunit --coverage-clover=coverage.xml + if [[ ${{ matrix.php-version }} == '8.3' ]]; then + vendor/bin/phpunit --display-warnings --display-deprecations --display-incomplete --display-skipped --coverage-clover=coverage.xml else - vendor/bin/phpunit + vendor/bin/phpunit --display-warnings --display-deprecations fi - name: Code Coverage Report - if: matrix.php-version == '8.1' - uses: codecov/codecov-action@v3 + if: matrix.php-version == '8.3' + uses: codecov/codecov-action@v4 cs-stan: uses: cakephp/.github/.github/workflows/cs-stan.yml@5.x diff --git a/.phive/phars.xml b/.phive/phars.xml index 4b17bf9..d311bfa 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,5 +1,5 @@ - - + + diff --git a/phpstan.neon b/phpstan.neon index ac67f30..95251d6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,8 +1,10 @@ parameters: - level: 6 - checkMissingIterableValueType: false - bootstrapFiles: - - vendor/cakephp/cakephp/src/Core/Exception/CakeException.php - - tests/bootstrap.php - paths: - - src + level: 7 + bootstrapFiles: + - vendor/cakephp/cakephp/src/Core/Exception/CakeException.php + - tests/bootstrap.php + paths: + - src + ignoreErrors: + - + identifier: missingType.iterableValue diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index 21f8a96..0000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - $bottom - $left - $right - $top - - - diff --git a/psalm.xml b/psalm.xml index 0b28919..bc10acf 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,7 +5,8 @@ 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" - errorBaseline="psalm-baseline.xml" + findUnusedBaselineEntry="true" + findUnusedCode="false" > @@ -32,5 +33,6 @@ + diff --git a/src/Pdf/CakePdf.php b/src/Pdf/CakePdf.php index 7a97c2c..774a2e2 100644 --- a/src/Pdf/CakePdf.php +++ b/src/Pdf/CakePdf.php @@ -349,7 +349,6 @@ public function write(string $destination, bool $create = true, ?string $html = } $splFileInfo = $fileInfo->getPathInfo(); - /** @phpstan-ignore-next-line */ if ($splFileInfo === null) { throw new CakeException('Failed to retrieve path information'); } @@ -378,7 +377,6 @@ public function engine(array|string|null $name = null): ?AbstractPdfEngine $name = $name['className']; } - /** @var class-string<\CakePdf\Pdf\Engine\AbstractPdfEngine>|null $engineClassName */ $engineClassName = App::className($name, 'Pdf/Engine', 'Engine'); if ($engineClassName === null) { throw new CakeException(sprintf('Pdf engine "%s" not found', $name)); @@ -580,10 +578,10 @@ public function margin( $right = $left; } - $this->marginBottom($bottom); - $this->marginLeft($left); - $this->marginRight($right); - $this->marginTop($top); + $this->marginBottom($bottom); // @phpstan-ignore argument.type + $this->marginLeft($left); // @phpstan-ignore argument.type + $this->marginRight($right); // @phpstan-ignore argument.type + $this->marginTop($top); // @phpstan-ignore argument.type return $this; } diff --git a/src/Pdf/Crypto/PdftkCrypto.php b/src/Pdf/Crypto/PdftkCrypto.php index 7132477..cb0483b 100644 --- a/src/Pdf/Crypto/PdftkCrypto.php +++ b/src/Pdf/Crypto/PdftkCrypto.php @@ -84,6 +84,9 @@ public function encrypt(string $data): string ]; $prochandle = proc_open($command, $descriptorspec, $pipes); + if ($prochandle === false) { + throw new CakeException('Unable to execute pdftk, proc_open() failed'); + } fwrite($pipes[0], $data); fclose($pipes[0]); diff --git a/src/Pdf/Engine/TexToPdfEngine.php b/src/Pdf/Engine/TexToPdfEngine.php index d769636..5d5453e 100644 --- a/src/Pdf/Engine/TexToPdfEngine.php +++ b/src/Pdf/Engine/TexToPdfEngine.php @@ -102,6 +102,10 @@ protected function _exec(string $cmd, string $input): array $result = ['stdout' => '', 'stderr' => '', 'return' => '']; $proc = proc_open($cmd, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes); + if ($proc === false) { + throw new CakeException('Unable to execute latexpdf, proc_open() failed'); + } + fwrite($pipes[0], $input); fclose($pipes[0]); diff --git a/src/Pdf/Engine/WkHtmlToPdfEngine.php b/src/Pdf/Engine/WkHtmlToPdfEngine.php index 83a0f59..d4c6cf5 100644 --- a/src/Pdf/Engine/WkHtmlToPdfEngine.php +++ b/src/Pdf/Engine/WkHtmlToPdfEngine.php @@ -80,6 +80,10 @@ protected function _exec(string $cmd, string $input): array $cwd = $this->getConfig('cwd'); $proc = proc_open($cmd, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['pipe', 'w']], $pipes, $cwd); + if ($proc === false) { + throw new CakeException('Unable to execute wkhtmltopdf, proc_open() failed'); + } + fwrite($pipes[0], $input); fclose($pipes[0]); @@ -150,10 +154,6 @@ protected function _getCommand(): string } $command .= ' - -'; - if ($this->_windowsEnvironment && PHP_MAJOR_VERSION < 8) { - $command = '"' . $command . '"'; - } - return $command; } diff --git a/tests/TestCase/View/PdfViewTest.php b/tests/TestCase/View/PdfViewTest.php index e888543..ba57310 100644 --- a/tests/TestCase/View/PdfViewTest.php +++ b/tests/TestCase/View/PdfViewTest.php @@ -7,6 +7,7 @@ use Cake\Http\Response; use Cake\Http\ServerRequest; use Cake\TestSuite\TestCase; +use Cake\View\View; use CakePdf\Pdf\CakePdf; use CakePdf\View\PdfView; use TestApp\Pdf\Engine\PdfTestEngine; @@ -16,6 +17,8 @@ */ class PdfViewTest extends TestCase { + protected PdfView $View; + /** * setup callback *