Skip to content

Commit 1448e1a

Browse files
authored
Merge pull request #33 from JSignPdf/feat/add-php-cs
feat: add php cs
2 parents 5fe5fea + 84dd0f2 commit 1448e1a

13 files changed

Lines changed: 2698 additions & 28 deletions

File tree

.github/workflows/lint-php-cs.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Lint php-cs
2+
3+
on: pull_request
4+
5+
permissions:
6+
contents: read
7+
8+
concurrency:
9+
group: lint-php-cs-${{ github.head_ref || github.run_id }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
lint:
14+
runs-on: ubuntu-latest
15+
16+
name: php-cs
17+
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
with:
22+
persist-credentials: false
23+
24+
- name: Set up php8.1
25+
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
26+
with:
27+
php-version: 8.1
28+
extensions: json, openssl
29+
coverage: none
30+
ini-file: development
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Install dependencies
35+
run: composer i
36+
37+
- name: Lint
38+
run: composer run cs:check || ( echo 'Please run `composer run cs:fix` to format your code' && exit 1 )

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea
22
.vscode
33
.phpunit.result.cache
4+
.php-cs-fixer.cache
45
vendor
56
/vendor-bin/**/vendor/

.php-cs-fixer.dist.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
require_once './vendor-bin/coding-standard/vendor/autoload.php';
6+
7+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
8+
9+
$config = new PhpCsFixer\Config();
10+
$config
11+
->setParallelConfig(ParallelConfigFactory::detect())
12+
->getFinder()
13+
->ignoreVCSIgnored(true)
14+
->notPath('vendor')
15+
->notPath('vendor-bin')
16+
->in(__DIR__);
17+
return $config;

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
}
3838
},
3939
"scripts": {
40+
"cs:check": "php-cs-fixer fix --dry-run --diff",
41+
"cs:fix": "php-cs-fixer fix",
4042
"test:unit": "vendor/bin/phpunit --no-coverage --colors=always --fail-on-warning --fail-on-risky --display-deprecations --display-phpunit-deprecations",
4143
"test:coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit",
4244
"psalm": "psalm --no-cache --threads=$(nproc)",

src/JSignFileService.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88
class JSignFileService
99
{
10-
1110
public static function instance(): self
1211
{
1312
return new self();
@@ -31,8 +30,9 @@ public function storeFile(string $path, string $name, string $content): string
3130

3231
public function deleteFile(string $path): void
3332
{
34-
if (is_file($path))
33+
if (is_file($path)) {
3534
unlink($path);
35+
}
3636
}
3737

3838
public function deleteTempFiles(string $pathTemp, string $name): void
@@ -41,8 +41,9 @@ public function deleteTempFiles(string $pathTemp, string $name): void
4141
$pathPdfFile = "$pathTemp$name.pdf";
4242
$pathPdfSignedFile = "{$pathTemp}{$name}_signed.pdf";
4343
$tempFiles = [$pathPfxFile, $pathPdfFile, $pathPdfSignedFile];
44-
foreach ($tempFiles as $path)
44+
foreach ($tempFiles as $path) {
4545
$this->deleteFile($path);
46+
}
4647
}
4748

4849
}

src/Runtime/JavaRuntimeService.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ private function downloadAndExtract(string $url, string $baseDir): void
100100
chmod($baseDir . '/bin/java', 0700);
101101
}
102102

103-
private function findRootDir(PharData $phar, string $rootDir): string {
103+
private function findRootDir(PharData $phar, string $rootDir): string
104+
{
104105
$files = new \RecursiveIteratorIterator($phar, \RecursiveIteratorIterator::CHILD_FIRST);
105106
$rootDir = realpath($rootDir);
106107
if (!is_string($rootDir) || empty($rootDir)) {

src/Sign/JSignParam.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,14 @@ public function setIsUseJavaInstalled(bool $isUseJavaInstalled): self
116116
return $this;
117117
}
118118

119-
public function setJavaPath(string $javaPath): self {
119+
public function setJavaPath(string $javaPath): self
120+
{
120121
$this->javaPath = $javaPath;
121122
return $this;
122123
}
123124

124-
public function getJavaPath(): string {
125+
public function getJavaPath(): string
126+
{
125127
return $this->javaPath;
126128
}
127129

src/Sign/JSignService.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@ public function sign(JSignParam $params): string
5050

5151
return $fileSigned;
5252
} catch (Throwable $e) {
53-
if ($params->getTempPath())
53+
if ($params->getTempPath()) {
5454
$this->fileService->deleteTempFiles($params->getTempPath(), $params->getTempName());
55+
}
5556

5657
throw new Exception($e->getMessage());
5758
}
@@ -66,8 +67,7 @@ private function repackCertificateIfPasswordIsUnicode(
6667
JSignParam $params,
6768
\OpenSSLCertificate|string $cert,
6869
\OpenSSLAsymmetricKey|\OpenSSLCertificate|string $pkey,
69-
): void
70-
{
70+
): void {
7171
$detectedEncodingString = mb_detect_encoding($params->getPassword(), 'ASCII', true);
7272
if ($detectedEncodingString === false) {
7373
$password = md5(microtime());
@@ -132,7 +132,7 @@ private function storeTempFiles(JSignParam $params): array
132132

133133
private function commandSign(JSignParam $params): string
134134
{
135-
list ($pdf, $certificate) = $this->storeTempFiles($params);
135+
list($pdf, $certificate) = $this->storeTempFiles($params);
136136
$java = $this->javaCommand($params);
137137
$jSignPdf = $this->getjSignPdfJarPath($params);
138138

@@ -154,8 +154,9 @@ private function getjSignPdfJarPath(JSignParam $params): string
154154

155155
private function throwIf(bool $condition, string $message): void
156156
{
157-
if ($condition)
157+
if ($condition) {
158158
throw new Exception($message);
159+
}
159160
}
160161

161162
private function isPasswordCertificateValid(JSignParam $params): bool
@@ -221,14 +222,14 @@ private function safeExec(
221222
string $tempEncriptedOriginal,
222223
string $tempDecrypted,
223224
string $tempEncriptedRepacked,
224-
): void
225-
{
225+
): void {
226226
$tempPassword = escapeshellarg($tempPassword);
227227
$tempEncriptedOriginal = escapeshellarg($tempEncriptedOriginal);
228228
$tempDecrypted = escapeshellarg($tempDecrypted);
229229
$tempEncriptedRepacked = escapeshellarg($tempEncriptedRepacked);
230230

231-
exec(<<<REPACK_COMMAND
231+
exec(
232+
<<<REPACK_COMMAND
232233
cat $tempPassword | openssl pkcs12 -legacy -in $tempEncriptedOriginal -nodes -out $tempDecrypted -passin stdin &&
233234
cat $tempPassword | openssl pkcs12 -in $tempDecrypted -export -out $tempEncriptedRepacked -passout stdin
234235
REPACK_COMMAND

tests/Builder/JSignParamBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ public function withDefault()
3232
return $params;
3333
}
3434

35-
}
35+
}

tests/JSignPDFTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
namespace Jeidison\JSignPDF\Sign;
44

5-
function exec(string $command, ?array &$output = null, ?int &$return_var = null) {
5+
function exec(string $command, ?array &$output = null, ?int &$return_var = null)
6+
{
67
global $mockExec;
78
if ($mockExec) {
89
$output = $mockExec;

0 commit comments

Comments
 (0)