Skip to content

Commit 490b760

Browse files
committed
update
1 parent 98c1dd5 commit 490b760

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

.github/workflows/phpci.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,8 @@ jobs:
1919
with:
2020
php-version: '8.4'
2121

22-
- name: PHP Security Checker
23-
uses: StephaneBour/[email protected]
24-
2522
- name: Setup project
26-
run: make setup
23+
run: make install
2724

2825
- name: Check lint
2926
run: make lint

composer.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@
1010
}
1111
],
1212
"require": {
13-
"php": ">=7.4 || >=8.1"
14-
},
15-
"scripts": {
16-
"phpcs": "phpcs",
17-
"phpunit": "phpunit",
18-
"test": "phpunit tests"
13+
"php": ">=8.3"
1914
},
2015
"autoload": {
2116
"files": [
2217
"src/trees.php"
2318
]
2419
},
2520
"require-dev": {
26-
"phpunit/phpunit": "^9.5",
27-
"squizlabs/php_codesniffer": "^3.6"
21+
"phpunit/phpunit": "^12",
22+
"squizlabs/php_codesniffer": "*"
2823
}
2924
}

src/trees.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @param array $meta
1010
* @return array
1111
*/
12-
function mkdir(string $name, array $children = [], array $meta = [])
12+
function mkdir(string $name, array $children = [], array $meta = []): array
1313
{
1414
return [
1515
"name" => $name,
@@ -25,7 +25,7 @@ function mkdir(string $name, array $children = [], array $meta = [])
2525
* @param array $meta
2626
* @return array
2727
*/
28-
function mkfile(string $name, array $meta = [])
28+
function mkfile(string $name, array $meta = []): array
2929
{
3030
return [
3131
"name" => $name,
@@ -43,7 +43,7 @@ function mkfile(string $name, array $meta = [])
4343
* getChildren(mkdir('etc')); // []
4444
* getChildren(mkdir('etc', [mkfile('name')])); // [<file>]
4545
*/
46-
function getChildren($node)
46+
function getChildren($node): array
4747
{
4848
return $node['children'];
4949
}
@@ -56,7 +56,7 @@ function getChildren($node)
5656
* getMeta(mkfile('etc')); // []
5757
* getMeta(mkfile('etc', ['owner' => 'root'])); // ['owner' => 'root']
5858
*/
59-
function getMeta($node)
59+
function getMeta($node): array
6060
{
6161
return $node['meta'];
6262
}
@@ -69,7 +69,7 @@ function getMeta($node)
6969
* getName(mkfile('etc')); // etc
7070
* getName(mkdir('/')); // /
7171
*/
72-
function getName($node)
72+
function getName($node): string
7373
{
7474
return $node['name'];
7575
}
@@ -79,7 +79,7 @@ function getName($node)
7979
* @param array $node
8080
* @return boolean
8181
*/
82-
function isFile($node)
82+
function isFile($node): bool
8383
{
8484
return $node['type'] == 'file';
8585
}
@@ -89,7 +89,7 @@ function isFile($node)
8989
* @param array $node
9090
* @return boolean
9191
*/
92-
function isDirectory($node)
92+
function isDirectory($node): bool
9393
{
9494
return $node['type'] == 'directory';
9595
}
@@ -124,7 +124,7 @@ function array_flatten($tree, $depth = 0)
124124
* @param array $tree
125125
* @return array
126126
*/
127-
function map($func, $tree)
127+
function map($func, $tree): array
128128
{
129129
$updatedNode = $func($tree);
130130
$children = $tree['children'] ?? [];
@@ -144,7 +144,7 @@ function map($func, $tree)
144144
* @param mixed $accumulator
145145
* @return mixed
146146
*/
147-
function reduce($func, $tree, $accumulator)
147+
function reduce($func, $tree, $accumulator): mixed
148148
{
149149
$children = $tree['children'] ?? [];
150150
$newAcc = $func($accumulator, $tree);
@@ -164,9 +164,9 @@ function reduce($func, $tree, $accumulator)
164164
* Filter tree
165165
* @param callable $func
166166
* @param array $tree
167-
* @return array
167+
* @return ?array
168168
*/
169-
function filter($func, $tree)
169+
function filter($func, $tree): ?array
170170
{
171171
if (!$func($tree)) {
172172
return null;

tests/TreesTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
class TreesTest extends TestCase
2020
{
21-
public function testMake()
21+
public function testMake(): void
2222
{
2323
$tree = mkdir('/', [mkdir('etc'), mkdir('usr'), mkfile('robots.txt')]);
2424
$expected = [
@@ -49,19 +49,19 @@ public function testMake()
4949
$this->assertEquals($expected, $tree);
5050
}
5151

52-
public function testGetMeta()
52+
public function testGetMeta(): void
5353
{
5454
$file = mkfile('etc', ['owner' => 'root']);
5555
$this->assertEquals(['owner' => 'root'], getMeta($file));
5656
}
5757

58-
public function testGetName()
58+
public function testGetName(): void
5959
{
6060
$file = mkfile('etc');
6161
$this->assertEquals('etc', getName($file));
6262
}
6363

64-
public function testGetChildren()
64+
public function testGetChildren(): void
6565
{
6666
$tree = mkdir('/', [mkdir('etc'), mkdir('usr'), mkfile('robots.txt')]);
6767
$expected = [
@@ -86,19 +86,19 @@ public function testGetChildren()
8686
$this->assertEquals($expected, getChildren($tree));
8787
}
8888

89-
public function testFile()
89+
public function testFile(): void
9090
{
9191
$file = mkfile('robots.txt');
9292
$this->assertTrue(isFile($file));
9393
}
9494

95-
public function testDirectory()
95+
public function testDirectory(): void
9696
{
9797
$directory = mkdir('/');
9898
$this->assertTrue(isDirectory($directory));
9999
}
100100

101-
public function testFlattenDepth()
101+
public function testFlattenDepth(): void
102102
{
103103
$tree = [1, 2, [3, [4, 5], [6, 7], 8]];
104104
$this->assertEquals([], array_flatten([]));
@@ -108,7 +108,7 @@ public function testFlattenDepth()
108108
$this->assertEquals([1, 2, 3, 4, 5, 6, 7, 8], array_flatten($tree, 3));
109109
}
110110

111-
public function testMap()
111+
public function testMap(): void
112112
{
113113
$tree = mkdir('/', [
114114
mkdir('eTc', [
@@ -154,7 +154,7 @@ public function testMap()
154154
$this->assertEquals($expected, $actual);
155155
}
156156

157-
public function testReduce()
157+
public function testReduce(): void
158158
{
159159
$tree = mkdir('/', [
160160
mkdir('eTc', [
@@ -178,7 +178,7 @@ public function testReduce()
178178
$this->assertEquals(4, $actual3);
179179
}
180180

181-
public function testFilter()
181+
public function testFilter(): void
182182
{
183183
$tree = mkdir('/', [
184184
mkdir('etc', [
@@ -229,7 +229,7 @@ public function testFilter()
229229
$this->assertEquals($expected, $actual);
230230
}
231231

232-
public function testFilter2()
232+
public function testFilter2(): void
233233
{
234234
$tree = mkdir('/', [
235235
mkdir('etc', [

0 commit comments

Comments
 (0)