From 4d0e62bb186f952ac881bfa8b12500df2033ecf6 Mon Sep 17 00:00:00 2001 From: ADmad Date: Thu, 14 Nov 2024 21:53:07 +0530 Subject: [PATCH] Maintenance --- .editorconfig | 3 +++ .github/codecov:.yml | 7 +++++++ .github/workflows/ci.yml | 31 +++++++++++++++------------- .phive/phars.xml | 4 ++-- phpstan.neon | 16 +++++++------- psalm-baseline.xml | 11 ---------- psalm.xml | 4 +++- src/Pdf/CakePdf.php | 10 ++++----- src/Pdf/Crypto/PdftkCrypto.php | 3 +++ src/Pdf/Engine/TexToPdfEngine.php | 4 ++++ src/Pdf/Engine/WkHtmlToPdfEngine.php | 8 +++---- tests/TestCase/View/PdfViewTest.php | 2 ++ 12 files changed, 58 insertions(+), 45 deletions(-) create mode 100644 .github/codecov:.yml delete mode 100644 psalm-baseline.xml diff --git a/.editorconfig b/.editorconfig index ee55bc74..2654275e 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/codecov:.yml b/.github/codecov:.yml new file mode 100644 index 00000000..56d5ad69 --- /dev/null +++ b/.github/codecov:.yml @@ -0,0 +1,7 @@ +codecov: + require_ci_to_pass: no + +coverage: + range: "90...100" + +comment: false diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e337bf33..99b7119e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,11 +17,14 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.1', '8.2'] - prefer-lowest: [''] + php-version: ['8.1', '8.2', '8.3'] + dependencies: ['highest'] include: + - php-version: '8.4' + dependencies: 'highest' + composer-options: '--ignore-platform-req=php' - php-version: '8.1' - prefer-lowest: 'prefer-lowest' + dependencies: 'lowest' steps: - uses: actions/checkout@v4 @@ -42,27 +45,27 @@ 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 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} cs-stan: uses: cakephp/.github/.github/workflows/cs-stan.yml@5.x diff --git a/.phive/phars.xml b/.phive/phars.xml index 4b17bf93..d311bfa5 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,5 +1,5 @@ - - + + diff --git a/phpstan.neon b/phpstan.neon index ac67f300..832fe591 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: 8 + 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 21f8a96a..00000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - $bottom - $left - $right - $top - - - diff --git a/psalm.xml b/psalm.xml index 0b28919b..bc10acf2 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 7a97c2c9..774a2e26 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 71324772..cb0483b6 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 d769636c..5d5453ed 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 83a0f59a..d4c6cf50 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 e8885438..43eb39c6 100644 --- a/tests/TestCase/View/PdfViewTest.php +++ b/tests/TestCase/View/PdfViewTest.php @@ -16,6 +16,8 @@ */ class PdfViewTest extends TestCase { + protected PdfView $View; + /** * setup callback *