Skip to content

Commit 5ec22d5

Browse files
committed
Fixed more coding standards.
1 parent bd2f143 commit 5ec22d5

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

scaffold/tests/phpunit/Dirs.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function printInfo(): void {
7171
fwrite(STDERR, PHP_EOL . implode(PHP_EOL, $lines) . PHP_EOL);
7272
}
7373

74-
protected function prepareLocalRepo() {
74+
protected function prepareLocalRepo(): void {
7575
$root = $this->fileFindDir('composer.json');
7676

7777
$this->fs->copy($root . '/composer.json', $this->repo . '/composer.json');
@@ -80,15 +80,25 @@ protected function prepareLocalRepo() {
8080
$this->fs->copy($root . '/myfile1.txt', $this->repo . '/myfile1.txt');
8181

8282
// Add the local repository to the composer.json file.
83-
$dstJson = json_decode(file_get_contents($this->repo . '/composer.json'), TRUE);
84-
$dstJson['repositories'][] = [
83+
$composerjson = file_get_contents($this->repo . '/composer.json');
84+
if ($composerjson === FALSE) {
85+
throw new \Exception('Failed to read the local composer.json file.');
86+
}
87+
88+
/** @var array $dst_json */
89+
$dst_json = json_decode($composerjson, TRUE);
90+
if (!$dst_json) {
91+
throw new \Exception('Failed to decode the local composer.json file.');
92+
}
93+
94+
$dst_json['repositories'][] = [
8595
'type' => 'path',
8696
'url' => $this->repo,
8797
'options' => [
8898
'symlink' => FALSE,
8999
],
90100
];
91-
file_put_contents($this->repo . '/composer.json', json_encode($dstJson, JSON_PRETTY_PRINT));
101+
file_put_contents($this->repo . '/composer.json', json_encode($dst_json, JSON_PRETTY_PRINT));
92102
}
93103

94104
}

scaffold/tests/phpunit/Traits/ComposerTrait.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protected function composerCreateProject(array|string $args = NULL): string {
2525
*
2626
* @param string $cmd
2727
* The Composer command to execute (escaped as required)
28-
* @param null $cwd
28+
* @param string|null $cwd
2929
* The current working directory to run the command from.
3030
* @param array $env
3131
* Environment variables to define for the subprocess.
@@ -35,8 +35,8 @@ protected function composerCreateProject(array|string $args = NULL): string {
3535
*
3636
* @throws \Exception
3737
*/
38-
public function composerRun($cmd, $cwd = NULL, $env = []): string {
39-
$cwd = $cwd ?? $this->dirs->build;
38+
public function composerRun(string $cmd, ?string $cwd = NULL, array $env = []): string {
39+
$cwd = $cwd ?: $this->dirs->build;
4040

4141
$env += [
4242
'DREVOPS_SCAFFOLD_VERSION' => '@dev',
@@ -64,11 +64,17 @@ public function composerRun($cmd, $cwd = NULL, $env = []): string {
6464
return $output;
6565
}
6666

67-
protected function composerReadJson($path = NULL) {
68-
$path = $path ?? $this->dirs->sut . '/composer.json';
67+
protected function composerReadJson(?string $path = NULL): array {
68+
$path = $path ?: $this->dirs->sut . '/composer.json';
6969
$this->assertFileExists($path);
7070

71-
return json_decode(file_get_contents($path), TRUE);
71+
$composerjson = file_get_contents($path);
72+
$this->assertIsString($composerjson);
73+
74+
$data = json_decode($composerjson, TRUE);
75+
$this->assertIsArray($data);
76+
77+
return $data;
7278
}
7379

7480
}

scaffold/tests/phpunit/Traits/EnvTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static function envIsSet(string $name): bool {
6363
/**
6464
* Check if an environment variable is not set.
6565
*/
66-
public static function envIsUnset($name): bool {
66+
public static function envIsUnset(string $name): bool {
6767
return getenv($name) === FALSE;
6868
}
6969

scaffold/tests/phpunit/Traits/FileTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
trait FileTrait {
1111

12-
public function fileFindDir(string $file, $start = NULL) {
12+
public function fileFindDir(string $file, ?string $start = NULL): string {
1313
if (empty($start)) {
1414
$start = dirname(__FILE__);
1515
}
@@ -23,7 +23,7 @@ public function fileFindDir(string $file, $start = NULL) {
2323
if ($fs->exists($path)) {
2424
return $current;
2525
}
26-
$current = dirname((string) $current);
26+
$current = dirname($current);
2727
}
2828

2929
throw new \RuntimeException('File not found: ' . $file);

scaffold/tests/phpunit/Traits/JsonAssertTrait.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,19 @@
66
use Helmich\JsonAssert\JsonAssertions;
77

88
/**
9+
* Trait JsonAssertTrait.
910
*
11+
* This trait provides a method to assert JSON data.
1012
*/
1113
trait JsonAssertTrait {
1214

1315
use JsonAssertions;
1416

15-
public function assertJsonHasNoKey($jsonDocument, string $jsonPath, $message = NULL): void {
16-
$result = (new JSONPath($jsonDocument))->find($jsonPath);
17+
public function assertJsonHasNoKey(array $json_data, string $path, ?string $message = NULL): void {
18+
$result = (new JSONPath($json_data))->find($path);
1719

1820
if (isset($result[0])) {
19-
$this->fail($message ?: sprintf("The JSON path '%s' exists, but it was expected not to.", $jsonPath));
21+
$this->fail($message ?: sprintf("The JSON path '%s' exists, but it was expected not to.", $path));
2022
}
2123

2224
$this->addToAssertionCount(1);

0 commit comments

Comments
 (0)