Skip to content
Merged
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
53 changes: 53 additions & 0 deletions .github/workflows/lint-php-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Lint php-cs

on: pull_request

permissions:
contents: read

concurrency:
group: lint-php-cs-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
php:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

name: php-cs

steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false

- name: Set up php${{ matrix.php }}
uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # v2.35.4
with:
php-version: ${{ matrix.php }}
coverage: none
ini-file: development

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer cache
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install

- name: Lint
run: composer cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ composer.lock
/vendor/
/vendor-bin/**/vendor/
*.swp
.php-cs-fixer.cache
.phpunit.result.cache
/tests/logs
18 changes: 18 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

require_once './vendor-bin/coding-standard/vendor/autoload.php';

use PhpCsFixer\Config;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;

$config = new Config();
$config
->setParallelConfig(ParallelConfigFactory::detect())
->getFinder()
->ignoreVCSIgnored(true)
->notPath('vendor')
->notPath('vendor-bin')
->in(__DIR__);
return $config;
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"scripts": {
"bin": "echo 'bin not installed'",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './vendor-bin/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"post-install-cmd": [
"@composer bin all install --ansi",
"composer dump-autoload"
Expand Down
1 change: 1 addition & 0 deletions src/Command.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace mikehaertl\pdftk;

use mikehaertl\shellcommand\Command as BaseCommand;
Expand Down
5 changes: 3 additions & 2 deletions src/FdfFile.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace mikehaertl\pdftk;

use mikehaertl\tmp\File;
Expand All @@ -15,13 +16,13 @@
class FdfFile extends File
{
// FDF file header
const FDF_HEADER = <<<FDF
private const FDF_HEADER = <<<FDF
%FDF-1.2
1 0 obj<</FDF<< /Fields[
FDF;

// FDF file footer
const FDF_FOOTER = <<<FDF
private const FDF_FOOTER = <<<FDF
] >> >>
endobj
trailer
Expand Down
1 change: 1 addition & 0 deletions src/InfoFields.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace mikehaertl\pdftk;

use ArrayObject;
Expand Down
1 change: 1 addition & 0 deletions src/InfoFile.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace mikehaertl\pdftk;

use Exception;
Expand Down
5 changes: 3 additions & 2 deletions src/Pdf.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace mikehaertl\pdftk;

use mikehaertl\tmp\File;
Expand All @@ -18,7 +19,7 @@
class Pdf
{
// The prefix for temporary files
const TMP_PREFIX = 'tmp_php_pdftk_';
private const TMP_PREFIX = 'tmp_php_pdftk_';

/**
* @var bool whether to ignore any errors if some non-empty output file was
Expand Down Expand Up @@ -669,7 +670,7 @@ public function toString()
public function getCommand()
{
if ($this->_command === null) {
$this->_command = new Command;
$this->_command = new Command();
}
return $this->_command;
}
Expand Down
9 changes: 5 additions & 4 deletions src/XfdfFile.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace mikehaertl\pdftk;

use mikehaertl\tmp\File;
Expand Down Expand Up @@ -52,15 +53,15 @@
class XfdfFile extends File
{
// XFDF file header
const XFDF_HEADER = <<<FDF
private const XFDF_HEADER = <<<FDF
<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
<fields>

FDF;

// XFDF file footer
const XFDF_FOOTER = <<<FDF
private const XFDF_FOOTER = <<<FDF
</fields>
</xfdf>

Expand Down Expand Up @@ -198,14 +199,14 @@ protected function writeXml($fields)
protected function writeFields($fp, $fields)
{
foreach ($fields as $key => $value) {
$key = $this->xmlEncode(substr($key,1));
$key = $this->xmlEncode(substr($key, 1));
fwrite($fp, "<field name=\"$key\">\n");
if (!is_array($value)) {
$value = array($value);
}
if (array_key_exists(0, $value)) {
// Numeric keys: single or multi-value field
foreach($value as $val) {
foreach ($value as $val) {
$val = $this->xmlEncode($val);
fwrite($fp, "<value>$val</value>\n");
}
Expand Down
9 changes: 5 additions & 4 deletions tests/unit/CommandTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace tests;

use PHPUnit\Framework\TestCase;
Expand All @@ -21,7 +22,7 @@ public function testCanAddFiles()
$document2 = $this->getDocument2();
$file = $this->getOutFile();

$command = new Command;
$command = new Command();
$this->assertEquals(0, $command->getFileCount());
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addFile($document1, 'A'));
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addFile($document2, 'B', 'complex\'"password'));
Expand All @@ -37,7 +38,7 @@ public function testCanAddOptions()
$document1 = $this->getDocument1();
$file = $this->getOutFile();

$command = new Command;
$command = new Command();
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addFile($document1, 'A'));
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addOption('encrypt_40bit'));
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addOption('allow', 'Printing', false));
Expand All @@ -53,7 +54,7 @@ public function testCanSetAndGetOperationAndArgument()
$document1 = $this->getDocument1();
$file = $this->getOutFile();

$command = new Command;
$command = new Command();
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addFile($document1, 'A'));
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->setOperation('cat'));
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->setOperationArgument('A'));
Expand All @@ -70,7 +71,7 @@ public function testCanAddPageRanges()
$document1 = $this->getDocument1();
$file = $this->getOutFile();

$command = new Command;
$command = new Command();
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addFile($document1, 'A'));
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->setOperation('cat'));
$this->assertInstanceOf('mikehaertl\pdftk\Command', $command->addPageRange(1));
Expand Down
1 change: 1 addition & 0 deletions tests/unit/DataFieldsTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace tests;

use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/FdfFileTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace tests;

use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/InfoFieldsTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace tests;

use PHPUnit\Framework\TestCase;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/InfoFileTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace tests;

use PHPUnit\Framework\TestCase;
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/PdfTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace tests;

use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -118,7 +119,7 @@ public function testCanAddFiles()
$document2 = $this->getDocument2();
$file = $this->getOutFile();

$pdf = new Pdf;
$pdf = new Pdf();
$this->assertInstanceOf('mikehaertl\pdftk\Pdf', $pdf->addFile($document1, null, 'complex\'"password'));
$this->assertInstanceOf('mikehaertl\pdftk\Pdf', $pdf->addFile($document2, 'D'));
$this->assertTrue($pdf->saveAs($file));
Expand All @@ -136,7 +137,7 @@ public function testCanPerformEmptyOperation()
$document1 = $this->getDocument1();
$file = $this->getOutFile();

$pdf = new Pdf;
$pdf = new Pdf();
$this->assertInstanceOf('mikehaertl\pdftk\Pdf', $pdf->addFile($document1, null, 'complex\'"password'));
$this->assertTrue($pdf->saveAs($file));
$this->assertFileExists($file);
Expand Down
1 change: 1 addition & 0 deletions tests/unit/XfdfFileTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace tests;

use PHPUnit\Framework\TestCase;
Expand Down
10 changes: 10 additions & 0 deletions vendor-bin/coding-standard/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.86"
},
"config": {
"platform": {
"php": "8.1"
}
}
}
Loading