Skip to content

Commit 922b36f

Browse files
committed
Update CS fixes
- Added `phpcs` and `phpcs:apply` - Added `rector:apply` - Updated from `PSR12` to `PER-CS` - Updated dependencies - Applied CS rules
1 parent f1e86de commit 922b36f

13 files changed

+373
-311
lines changed

.php-cs-fixer.dist.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
]);
1313

1414
return (new PhpCsFixer\Config())->setRules([
15-
'@PSR12' => true,
15+
'@PER-CS' => true,
16+
'@PHP82Migration' => true,
17+
1618
'header_comment' => [
1719
'comment_type' => 'PHPDoc',
1820
'header' => $header,

composer.lock

+176-165
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+171-128
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"private": true,
55
"devDependencies": {
66
"chokidar-cli": "^3.0.0",
7-
"@mermaid-js/mermaid-cli": "^10.7",
7+
"@mermaid-js/mermaid-cli": "^10.8",
88
"npm-run-all": "^4.1.5"
99
},
1010
"scripts": {
@@ -14,8 +14,13 @@
1414
"watch:tests": "chokidar \"tests/**/*.php\" -c \"npm run phpunit {path}\"",
1515
"watch:mermaid": "chokidar \"**/*.mmd\" -c \"mmdc -e svg -i {path}\"",
1616

17+
"phpcs" : "./vendor/bin/php-cs-fixer fix --verbose --diff --dry-run",
18+
"phpcs:apply" : "./vendor/bin/php-cs-fixer fix --verbose --diff",
19+
1720
"phpstan": "./vendor/bin/phpstan --no-progress analyse",
21+
1822
"rector": "./vendor/bin/rector process --dry-run",
23+
"rector:apply": "./vendor/bin/rector process",
1924

2025
"phpunit": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --configuration phpunit.npm.xml",
2126
"phpunit:filter": "npm run phpunit -- --testsuite unit --filter",

src/Persistence/FilePersistenceAbstract.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ abstract class FilePersistenceAbstract implements FilePersistence
2323
/**
2424
* @var int The output directory permissions.
2525
*/
26-
protected int $directory_permissions = 0755;
26+
protected int $directory_permissions = 0o755;
2727

2828
/**
2929
* Examples: "json", "yaml"
@@ -220,8 +220,8 @@ public function readAll(): array
220220
$ext = $this->getExtension(dot: true);
221221
$files = glob($this->basedir . ('/*' . $ext)) ?: [];
222222

223-
$id_array = array_map(static fn ($file) => basename($file, $ext), $files);
224-
$all_read = array_map(fn (string|int $id): array => $this->read($id), $id_array);
223+
$id_array = array_map(static fn($file) => basename($file, $ext), $files);
224+
$all_read = array_map(fn(string|int $id): array => $this->read($id), $id_array);
225225

226226
return array_filter($all_read);
227227
}

src/Persistence/FrontmatterFilePersistence.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ public function readAll(): array
8383

8484
$files = glob($base_dir . '/*' . $ext) ?: [];
8585

86-
$id_array = array_map(static fn ($file) => basename((string) $file, $ext), $files);
86+
$id_array = array_map(static fn($file) => basename($file, $ext), $files);
8787

88-
$all_read = array_map(fn (string|int $id, &$store = null): array => $this->read($id, $store), $id_array);
88+
$all_read = array_map(fn(string|int $id, &$store = null): array => $this->read($id, $store), $id_array);
8989
return array_filter($all_read);
9090
}
9191

@@ -117,6 +117,7 @@ public function writeToFile(string $file_path, \Stringable|string $file_content,
117117
if ($file_content instanceof \Stringable) {
118118
$file_content = $file_content->__toString();
119119
}
120+
120121
return $this->persistence->writeToFile($file_path, $frontmatter . $file_content);
121122
}
122123

src/Repositories/Repository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function findOneBy(array $criteria): null|array|object
9494
*/
9595
public function findAll(): iterable
9696
{
97-
$items = array_map(fn ($item) => ($this->item_factory)($item), $this->persistence->readAll());
97+
$items = array_map(fn($item) => ($this->item_factory)($item), $this->persistence->readAll());
9898

9999
return ($this->collection_factory)($items);
100100
}

tests/Integration/RepositoryWithFilePersistenceTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public static function buildFixturesPath(string $dir): string
184184
dirname(__DIR__, 2),
185185
'tests',
186186
'fixtures',
187-
$dir
187+
$dir,
188188
]);
189189

190190
// Copy fixtures to a temp directory which will be deleted afterwards

tests/Unit/FilePersistenceAbstractTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ protected function setUp(): void
3030

3131
$this->sut = $this->getMockForAbstractClass(FilePersistenceAbstract::class, [$temp_dir]);
3232

33-
$this->sut->method('encode')->willReturnCallback(static fn ($data) => json_encode($data));
34-
$this->sut->method('decode')->willReturnCallback(static fn ($content) => json_decode((string) $content, true));
33+
$this->sut->method('encode')->willReturnCallback(static fn($data) => json_encode($data));
34+
$this->sut->method('decode')->willReturnCallback(static fn($content) => json_decode((string) $content, true));
3535
}
3636

3737
protected function tearDown(): void
@@ -62,7 +62,7 @@ public static function invalidBaseDirProvider(): array
6262
{
6363
return [
6464
'root directory' => ['/'],
65-
'empty directory' => ['']
65+
'empty directory' => [''],
6666
];
6767
}
6868

tests/Unit/FilePersistenceTestBase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static function invalidBaseDirProvider(): array
155155
{
156156
return [
157157
'root directory' => ['/'],
158-
'empty directory' => ['']
158+
'empty directory' => [''],
159159
];
160160
}
161161

tests/Unit/FrontmatterFilePersistenceTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testReadWithFrontmatterFromFile(): void
9999
{
100100
$sample = ['foo' => 'bar'];
101101

102-
$fileContent = "---\ntitle: Test Title\n".Yaml::dump($sample)."\n---\n" . $this->testContent;
102+
$fileContent = "---\ntitle: Test Title\n" . Yaml::dump($sample) . "\n---\n" . $this->testContent;
103103
$this->filePersistenceMock->method('readFromFile')->willReturn($fileContent);
104104
$this->filePersistenceMock->method('decode')->willReturn($sample);
105105

@@ -137,7 +137,7 @@ public function testWriteToFile(): void
137137
$this->filePersistenceMock->expects($this->once())->method('writeToFile')
138138
->with(
139139
$this->equalTo($this->tempFilePath),
140-
$this->callback(fn ($fileContent) => str_starts_with((string) $fileContent, "---\n") && str_contains((string) $fileContent, $this->testContent))
140+
$this->callback(fn($fileContent) => str_starts_with((string) $fileContent, "---\n") && str_contains((string) $fileContent, $this->testContent))
141141
)
142142
->willReturn(true);
143143

tests/Unit/PersistenceChainTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function setUp(): void
3333
// Initialize PersistenceChain with the mock Persistence object
3434
$this->sut = new PersistenceChain([
3535
$this->mockPersistence1,
36-
$this->mockPersistence2
36+
$this->mockPersistence2,
3737
]);
3838
}
3939

tests/Unit/RepositoryTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static function provideRepositoryAndPersistencesWithCriteria(): array
8989
$repo = new Repository(new InMemoryPersistence([
9090
['some' => 'criteria', 'color' => 'blue'],
9191
['some' => 'criteria', 'color' => 'orange'],
92-
['some' => 'other', 'color' => 'red']
92+
['some' => 'other', 'color' => 'red'],
9393
]));
9494

9595
$empty_repo = new Repository(new NoPersistence());
@@ -98,7 +98,7 @@ public static function provideRepositoryAndPersistencesWithCriteria(): array
9898
'Empty repo with "NoPersistence"' => [ $empty_repo, ['color' => 'yellow'], 0 ],
9999
'Look for color that does not exist in repo' => [ $repo, ['color' => 'yellow'], 0 ],
100100
'Should return only 1 item for unique value' => [ $repo, ['some' => 'criteria', 'color' => 'orange'], 1 ],
101-
'Should return 2 matching items' => [ $repo, ['some' => 'criteria'], 2 ]
101+
'Should return 2 matching items' => [ $repo, ['some' => 'criteria'], 2 ],
102102
];
103103
}
104104

0 commit comments

Comments
 (0)