Skip to content

Commit 37bb5ad

Browse files
authored
Update coding standard (#9)
1 parent b6fccbc commit 37bb5ad

File tree

7 files changed

+40
-26
lines changed

7 files changed

+40
-26
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343

4444
-
4545
name: "Run friendsofphp/php-cs-fixer"
46-
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose"
46+
run: "vendor/bin/php-cs-fixer fix --dry-run --diff --verbose --allow-risky=yes"
4747
phpstan:
4848
name: "PHPStan (${{ matrix.php-version }})"
4949

.php_cs.dist

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ $finder = PhpCsFixer\Finder::create()
44
->in('lib')
55
->in('tests')
66
->exclude([
7-
'tests/Workspace'
7+
'tests/Workspace',
88
])
99
;
1010

@@ -13,6 +13,11 @@ return PhpCsFixer\Config::create()
1313
'@PSR2' => true,
1414
'no_unused_imports' => true,
1515
'array_syntax' => ['syntax' => 'short'],
16+
'void_return' => true,
17+
'ordered_class_elements' => true,
18+
'single_quote' => true,
19+
'heredoc_indentation' => true,
20+
'global_namespace_import' => true,
1621
])
1722
->setFinder($finder)
1823
;

lib/Definitions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ public function __construct(array $definitions)
2727
}
2828
}
2929

30-
private function add(Definition $definition): void
31-
{
32-
$this->definitions[$definition->name()] = $definition;
33-
}
34-
3530
/**
3631
* @return Iterator<Definition>
3732
*/
@@ -51,4 +46,9 @@ public function get(string $name): Definition
5146

5247
return $this->definitions[$name];
5348
}
49+
50+
private function add(Definition $definition): void
51+
{
52+
$this->definitions[$definition->name()] = $definition;
53+
}
5454
}

lib/Resolver.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,15 +171,6 @@ public function merge(Resolver $schema): Resolver
171171
return $this;
172172
}
173173

174-
/**
175-
* @return array<string>
176-
*/
177-
private function resolveAllowedKeys(): array
178-
{
179-
$allowedKeys = array_merge(array_keys($this->defaults), $this->required);
180-
return $allowedKeys;
181-
}
182-
183174
public function definitions(): Definitions
184175
{
185176
$definitions = [];
@@ -196,4 +187,13 @@ public function definitions(): Definitions
196187

197188
return new Definitions($definitions);
198189
}
190+
191+
/**
192+
* @return array<string>
193+
*/
194+
private function resolveAllowedKeys(): array
195+
{
196+
$allowedKeys = array_merge(array_keys($this->defaults), $this->required);
197+
return $allowedKeys;
198+
}
199199
}

phpstan-baseline.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
ignoreErrors:
3+
-
4+
message: "#^Method Phpactor\\\\MapResolver\\\\Resolver\\:\\:resolveDescriptions\\(\\) should return array\\<string, string\\> but returns array\\<int\\|string, string\\|false\\|null\\>\\.$#"
5+
count: 1
6+
path: lib/Resolver.php
7+

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ parameters:
33
inferPrivatePropertyTypeFromConstructor: true
44
paths:
55
- lib
6+
includes:
7+
- phpstan-baseline.neon

tests/Unit/ResolverTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class ResolverTest extends TestCase
1212
{
13-
public function testSetsDefaults()
13+
public function testSetsDefaults(): void
1414
{
1515
$resolver = new Resolver();
1616
$resolver->setDefaults([
@@ -20,7 +20,7 @@ public function testSetsDefaults()
2020
$this->assertEquals(['one' => 1, 'two' => 2], $resolver->resolve([]));
2121
}
2222

23-
public function testThrowsExceptionOnUnknownKey()
23+
public function testThrowsExceptionOnUnknownKey(): void
2424
{
2525
$this->expectException(InvalidMap::class);
2626
$this->expectExceptionMessage('Key(s) "three" are not known');
@@ -33,7 +33,7 @@ public function testThrowsExceptionOnUnknownKey()
3333
$resolver->resolve(['three' => 3]);
3434
}
3535

36-
public function testMergesDefaults()
36+
public function testMergesDefaults(): void
3737
{
3838
$resolver = new Resolver();
3939
$resolver->setDefaults([
@@ -43,7 +43,7 @@ public function testMergesDefaults()
4343
$this->assertEquals(['one' => 5, 'two' => 2], $resolver->resolve(['one' => 5]));
4444
}
4545

46-
public function testSettingDefaultsMultipleTimesMerges()
46+
public function testSettingDefaultsMultipleTimesMerges(): void
4747
{
4848
$resolver = new Resolver();
4949
$resolver->setDefaults([
@@ -56,7 +56,7 @@ public function testSettingDefaultsMultipleTimesMerges()
5656
$this->assertEquals(['one' => 3, 'two' => 2], $resolver->resolve([]));
5757
}
5858

59-
public function testThrowsExceptionOnMissingRequiredKeys()
59+
public function testThrowsExceptionOnMissingRequiredKeys(): void
6060
{
6161
$this->expectException(InvalidMap::class);
6262
$this->expectExceptionMessage('Key(s) "one" are required');
@@ -69,7 +69,7 @@ public function testThrowsExceptionOnMissingRequiredKeys()
6969
$resolver->resolve(['two' => 3]);
7070
}
7171

72-
public function testCallingRequiredMultipleTimesMergesRequiredKeys()
72+
public function testCallingRequiredMultipleTimesMergesRequiredKeys(): void
7373
{
7474
$resolver = new Resolver();
7575
$resolver->setRequired(['one']);
@@ -78,7 +78,7 @@ public function testCallingRequiredMultipleTimesMergesRequiredKeys()
7878
$this->assertEquals(['one' => 1, 'two' => 3], $result);
7979
}
8080

81-
public function testThrowsExceptionOnInvalidType()
81+
public function testThrowsExceptionOnInvalidType(): void
8282
{
8383
$this->expectException(InvalidMap::class);
8484
$this->expectExceptionMessage('Type for "one" expected to be "string", got "stdClass"');
@@ -91,7 +91,7 @@ public function testThrowsExceptionOnInvalidType()
9191
$resolver->resolve(['one' => new stdClass]);
9292
}
9393

94-
public function testCallback()
94+
public function testCallback(): void
9595
{
9696
$resolver = new Resolver();
9797
$resolver->setDefaults([
@@ -106,7 +106,7 @@ public function testCallback()
106106
$this->assertEquals('hello', $config['bar']);
107107
}
108108

109-
public function testThrowsExceptionOnUnknownDescriptions()
109+
public function testThrowsExceptionOnUnknownDescriptions(): void
110110
{
111111
$this->expectException(InvalidMap::class);
112112
$this->expectExceptionMessage('Description(s) for key(s) "four" are not known');
@@ -122,7 +122,7 @@ public function testThrowsExceptionOnUnknownDescriptions()
122122
$resolver->resolve(['two' => 3]);
123123
}
124124

125-
public function testResolvesDescriptions()
125+
public function testResolvesDescriptions(): void
126126
{
127127
$resolver = new Resolver();
128128
$resolver->setDefaults([

0 commit comments

Comments
 (0)