Skip to content

Commit 84dd0f2

Browse files
committed
fix: apply php cs fixer
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent bb5b711 commit 84dd0f2

7 files changed

Lines changed: 46 additions & 28 deletions

File tree

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;

tests/Runtime/JavaRuntimeServiceTest.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414
class JavaRuntimeServiceTest extends TestCase
1515
{
1616
public string $testTmpDir = '';
17-
protected function setUp(): void {
17+
protected function setUp(): void
18+
{
1819
$this->testTmpDir = sys_get_temp_dir() . '/jsignpdf_temp_dir_' . uniqid();
1920
mkdir(directory: $this->testTmpDir, recursive: true);
2021
}
2122

22-
public function testGetPathWhenJavaIsInstalled(): void {
23+
public function testGetPathWhenJavaIsInstalled(): void
24+
{
2325
$jsignParam = new JSignParam();
2426
$service = new JavaRuntimeService();
2527
$jsignParam->setIsUseJavaInstalled(true);
2628
$path = $service->getPath($jsignParam);
2729
$this->assertEquals('java', $path);
2830
}
2931

30-
public function testGetPathWithCustomAndValidJavaPath(): void {
32+
public function testGetPathWithCustomAndValidJavaPath(): void
33+
{
3134
$jsignParam = new JSignParam();
3235
$service = new JavaRuntimeService();
3336
vfsStream::setup('download');
@@ -40,7 +43,8 @@ public function testGetPathWithCustomAndValidJavaPath(): void {
4043
$this->assertEquals('vfs://download/bin/java', $path);
4144
}
4245

43-
public function testGetPathWithCustomAndInvalidJavaPath(): void {
46+
public function testGetPathWithCustomAndInvalidJavaPath(): void
47+
{
4448
$jsignParam = new JSignParam();
4549
$service = new JavaRuntimeService();
4650
$jsignParam->setJavaPath(__FILE__);
@@ -50,7 +54,8 @@ public function testGetPathWithCustomAndInvalidJavaPath(): void {
5054
$service->getPath($jsignParam);
5155
}
5256

53-
public function testGetPathWithDownloadUrlAndNotRealDirectory(): void {
57+
public function testGetPathWithDownloadUrlAndNotRealDirectory(): void
58+
{
5459
$jsignParam = new JSignParam();
5560
$service = new JavaRuntimeService();
5661
$root = vfsStream::setup('download');
@@ -65,7 +70,8 @@ public function testGetPathWithDownloadUrlAndNotRealDirectory(): void {
6570
$service->getPath($jsignParam);
6671
}
6772

68-
public function testGetPathWithDownloadUrlWithInvalidUrl(): void {
73+
public function testGetPathWithDownloadUrlWithInvalidUrl(): void
74+
{
6975
vfsStream::setup('download');
7076
mkdir('vfs://download/bin');
7177
touch('vfs://download/bin/java');
@@ -79,7 +85,8 @@ public function testGetPathWithDownloadUrlWithInvalidUrl(): void {
7985
$service->getPath($jsignParam);
8086
}
8187

82-
public function testGetPathWithDownloadUrlWith4xxError(): void {
88+
public function testGetPathWithDownloadUrlWith4xxError(): void
89+
{
8390
vfsStream::setup('download');
8491
mkdir('vfs://download/bin');
8592
touch('vfs://download/bin/java');
@@ -93,7 +100,8 @@ public function testGetPathWithDownloadUrlWith4xxError(): void {
93100
$service->getPath($jsignParam);
94101
}
95102

96-
public function testGetPathWithDownloadUrlWithInvalidGzipedFile(): void {
103+
public function testGetPathWithDownloadUrlWithInvalidGzipedFile(): void
104+
{
97105
vfsStream::setup('download');
98106
mkdir('vfs://download/bin');
99107
touch('vfs://download/bin/java');
@@ -119,7 +127,8 @@ public function testGetPathWithDownloadUrlWithInvalidGzipedFile(): void {
119127
$service->getPath($jsignParam);
120128
}
121129

122-
public function testGetPathWithDownloadUrlWithInvalidJavaPackage(): void {
130+
public function testGetPathWithDownloadUrlWithInvalidJavaPackage(): void
131+
{
123132
mkdir($this->testTmpDir . '/bin', 0755, true);
124133

125134
$jsignParam = new JSignParam();
@@ -146,7 +155,8 @@ public function testGetPathWithDownloadUrlWithInvalidJavaPackage(): void {
146155
$service->getPath($jsignParam);
147156
}
148157

149-
public function testGetPathWithDownloadUrlWithInvalidVersion(): void {
158+
public function testGetPathWithDownloadUrlWithInvalidVersion(): void
159+
{
150160
$jsignParam = new JSignParam();
151161
$service = new JavaRuntimeService();
152162

@@ -166,7 +176,8 @@ public function testGetPathWithDownloadUrlWithInvalidVersion(): void {
166176
$service->getPath($jsignParam);
167177
}
168178

169-
public function testGetPathWithDownloadUrlWithValidVersion(): void {
179+
public function testGetPathWithDownloadUrlWithValidVersion(): void
180+
{
170181
$jsignParam = new JSignParam();
171182
$service = new JavaRuntimeService();
172183

@@ -183,7 +194,8 @@ public function testGetPathWithDownloadUrlWithValidVersion(): void {
183194
$this->assertEquals($jsignParam->getJavaPath(), $javaPath);
184195
}
185196

186-
public function testGetPathWithoutJavaFallback(): void {
197+
public function testGetPathWithoutJavaFallback(): void
198+
{
187199
mkdir($this->testTmpDir . '/bin', 0755, true);
188200

189201
$jsignParam = new JSignParam();

0 commit comments

Comments
 (0)