Skip to content

Commit 112a46f

Browse files
committed
Update PHP CS Fixer config
1 parent fb6092c commit 112a46f

7 files changed

Lines changed: 105 additions & 51 deletions

File tree

.php-cs-fixer.dist.php

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,61 @@
11
<?php
22

33
declare(strict_types=1);
4+
use PhpCsFixer\Config;
5+
use PhpCsFixer\Finder;
6+
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
47

5-
use Beste\PhpCsFixer\Config;
8+
$finder = Finder::create()
9+
->in([
10+
__DIR__.'/src',
11+
__DIR__.'/tests',
12+
])
13+
;
614

7-
$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php81());
8-
9-
$config->getFinder()->in(__DIR__);
10-
11-
return $config;
15+
return (new Config())
16+
->setParallelConfig(ParallelConfigFactory::detect())
17+
->setRiskyAllowed(true)
18+
->setRules([
19+
'@PER-CS3x0:risky' => true,
20+
'@PHPUnit9x1Migration:risky' => true,
21+
'class_attributes_separation' => true,
22+
'class_definition' => [
23+
'single_line' => true,
24+
],
25+
'concat_space' => [
26+
'spacing' => 'none',
27+
],
28+
'final_internal_class' => true,
29+
'fully_qualified_strict_types' => [
30+
'import_symbols' => true,
31+
'leading_backslash_in_global_namespace' => true,
32+
],
33+
'method_argument_space' => [
34+
'attribute_placement' => 'standalone', // same_line can break PHP <8.2
35+
],
36+
'no_blank_lines_after_phpdoc' => true,
37+
'no_empty_phpdoc' => true,
38+
'no_unneeded_braces' => true,
39+
'no_unused_imports' => true,
40+
'ordered_imports' => [
41+
'imports_order' => [
42+
'class',
43+
'function',
44+
'const',
45+
],
46+
'sort_algorithm' => 'alpha',
47+
],
48+
'phpdoc_align' => [
49+
'align' => 'left',
50+
],
51+
'php_unit_method_casing' => [
52+
'case' => 'camel_case',
53+
],
54+
'php_unit_test_case_static_method_calls' => [
55+
'call_type' => 'this',
56+
'methods' => [],
57+
],
58+
'single_line_empty_body' => false,
59+
'yoda_style' => false,
60+
])
61+
->setFinder($finder);

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
},
1818
"require-dev": {
1919
"beste/clock": "^3.0",
20-
"beste/php-cs-fixer-config": "^3.2.0",
21-
"friendsofphp/php-cs-fixer": "^3.62.0",
2220
"phpstan/extension-installer": "^1.4.1",
2321
"phpstan/phpstan": "^2.0.1",
2422
"phpstan/phpstan-deprecation-rules": "^2.0",
2523
"phpstan/phpstan-phpunit": "^2.0",
2624
"phpstan/phpstan-strict-rules": "^2.0",
2725
"phpunit/phpunit": "^10.5.2 || ^11.3.1",
2826
"symfony/var-dumper": "^6.4 || ^7.1.3"
27+
"friendsofphp/php-cs-fixer": "^3.95.1",
2928
},
3029
"provide": {
3130
"psr/cache-implementation": "2.0 || 3.0"

src/CacheItem.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
final class CacheItem implements CacheItemInterface
1212
{
1313
private mixed $value;
14+
1415
private ?\DateTimeInterface $expiresAt;
16+
1517
private bool $isHit;
1618

1719
public function __construct(private readonly CacheKey $key, private readonly ClockInterface $clock)

src/InMemoryCache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ final class InMemoryCache implements CacheItemPoolInterface
1313

1414
/** @var array<string, CacheItemInterface> */
1515
private array $items;
16+
1617
/** @var array<string, CacheItemInterface> */
1718
private array $deferredItems;
1819

@@ -24,7 +25,6 @@ public function now(): DateTimeImmutable
2425
{
2526
return new DateTimeImmutable();
2627
}
27-
2828
};
2929
$this->items = [];
3030
$this->deferredItems = [];

tests/CacheItemTest.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
final class CacheItemTest extends TestCase
1414
{
1515
private string $key;
16+
1617
private FrozenClock $clock;
18+
1719
private CacheItem $cacheItem;
1820

1921
protected function setUp(): void
@@ -25,63 +27,63 @@ protected function setUp(): void
2527

2628
public function testItHasAKey(): void
2729
{
28-
self::assertSame($this->key, $this->cacheItem->getKey());
30+
$this->assertSame($this->key, $this->cacheItem->getKey());
2931
}
3032

3133
public function testItInitiallyHasNoValue(): void
3234
{
33-
self::assertNull($this->cacheItem->get());
35+
$this->assertNull($this->cacheItem->get());
3436
}
3537

3638
public function testItInitiallyIsNotAHit(): void
3739
{
38-
self::assertFalse($this->cacheItem->isHit());
40+
$this->assertFalse($this->cacheItem->isHit());
3941
}
4042

4143
public function testItHasAValueWhenSetWithOne(): void
4244
{
4345
$this->cacheItem->set('value');
4446

45-
self::assertSame('value', $this->cacheItem->get());
47+
$this->assertSame('value', $this->cacheItem->get());
4648
}
4749

4850
public function testItBecomesHitWhenSetWithAValue(): void
4951
{
5052
$this->cacheItem->set('value');
5153

52-
self::assertTrue($this->cacheItem->isHit());
54+
$this->assertTrue($this->cacheItem->isHit());
5355
}
5456

5557
public function testItHasAValueAsLongAsItIsNotExpiredAtAGivenTime(): void
5658
{
5759
$this->cacheItem->set('value');
5860
$this->cacheItem->expiresAt($this->clock->now()->modify('+1 minute'));
5961

60-
self::assertSame('value', $this->cacheItem->get());
62+
$this->assertSame('value', $this->cacheItem->get());
6163
}
6264

6365
public function testItHasNoValueWhenItIsExpiredAtAGivenTime(): void
6466
{
6567
$this->cacheItem->set('value');
6668
$this->cacheItem->expiresAt($this->clock->now()->modify('-1 minute'));
6769

68-
self::assertNull($this->cacheItem->get());
70+
$this->assertNull($this->cacheItem->get());
6971
}
7072

7173
public function testItIsAHitAsLongAsItIsNotExpiredAtAGivenTime(): void
7274
{
7375
$this->cacheItem->set('value');
7476
$this->cacheItem->expiresAt($this->clock->now()->modify('+1 minute'));
7577

76-
self::assertTrue($this->cacheItem->isHit());
78+
$this->assertTrue($this->cacheItem->isHit());
7779
}
7880

7981
public function testItIsAMissWhenItIsExpiredAtAGivenTime(): void
8082
{
8183
$this->cacheItem->set('value');
8284
$this->cacheItem->expiresAt($this->clock->now()->modify('-1 minute'));
8385

84-
self::assertFalse($this->cacheItem->isHit());
86+
$this->assertFalse($this->cacheItem->isHit());
8587
}
8688

8789
public function testTheExpirationCanBeGivenInSeconds(): void
@@ -92,7 +94,7 @@ public function testTheExpirationCanBeGivenInSeconds(): void
9294
$this->cacheItem->expiresAfter(60);
9395
$this->clock->setTo($this->clock->now()->modify('+61 seconds'));
9496

95-
self::assertFalse($this->cacheItem->isHit());
97+
$this->assertFalse($this->cacheItem->isHit());
9698
}
9799

98100
public function testTheExpirationCanBeGivenAsADateInterval(): void
@@ -103,7 +105,7 @@ public function testTheExpirationCanBeGivenAsADateInterval(): void
103105
$this->cacheItem->expiresAfter(new \DateInterval('PT60S'));
104106
$this->clock->setTo($this->clock->now()->modify('+61 seconds'));
105107

106-
self::assertFalse($this->cacheItem->isHit());
108+
$this->assertFalse($this->cacheItem->isHit());
107109
}
108110

109111
public function testTheExpirationCanBeUnset(): void
@@ -115,7 +117,7 @@ public function testTheExpirationCanBeUnset(): void
115117

116118
$this->cacheItem->expiresAfter(null);
117119

118-
self::assertTrue($this->cacheItem->isHit());
120+
$this->assertTrue($this->cacheItem->isHit());
119121

120122

121123
}

tests/CacheKeyTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
/**
1212
* @internal
1313
*/
14-
class CacheKeyTest extends TestCase
14+
final class CacheKeyTest extends TestCase
1515
{
1616
#[DataProvider('validValues')]
1717
#[DoesNotPerformAssertions]

tests/InMemoryCacheTest.php

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
final class InMemoryCacheTest extends TestCase
1313
{
1414
private FrozenClock $clock;
15+
1516
private InMemoryCache $pool;
1617

1718
protected function setUp(): void
@@ -25,21 +26,21 @@ public function testItWorksWithoutProvidingAClock(): void
2526
$pool = new InMemoryCache();
2627
$item = $pool->getItem('item');
2728

28-
self::assertFalse($item->isHit());
29+
$this->assertFalse($item->isHit());
2930

3031
$item->set('value')->expiresAfter(new \DateInterval('PT5M'));
3132
$pool->save($item);
3233

3334
$item = $pool->getItem('item');
34-
self::assertTrue($item->isHit());
35+
$this->assertTrue($item->isHit());
3536
}
3637

3738
public function testItReturnsANewItem(): void
3839
{
3940
$item = $this->pool->getItem('item');
4041

41-
self::assertFalse($item->isHit());
42-
self::assertNull($item->get());
42+
$this->assertFalse($item->isHit());
43+
$this->assertNull($item->get());
4344
}
4445

4546
public function testItUsesTheProvidedClock(): void
@@ -50,10 +51,10 @@ public function testItUsesTheProvidedClock(): void
5051
$this->pool->save($item);
5152

5253
$this->clock->setTo($this->clock->now()->add(new \DateInterval('PT1H')));
53-
self::assertTrue($this->pool->getItem('item')->isHit());
54+
$this->assertTrue($this->pool->getItem('item')->isHit());
5455

5556
$this->clock->setTo($this->clock->now()->add(new \DateInterval('PT2H')));
56-
self::assertFalse($this->pool->getItem('item')->isHit());
57+
$this->assertFalse($this->pool->getItem('item')->isHit());
5758
}
5859

5960
public function testItSavesAnItem(): void
@@ -63,19 +64,19 @@ public function testItSavesAnItem(): void
6364
$item->set('value');
6465
$this->pool->save($item);
6566

66-
self::assertTrue($this->pool->getItem('item')->isHit());
67-
self::assertSame('value', $this->pool->getItem('item')->get());
67+
$this->assertTrue($this->pool->getItem('item')->isHit());
68+
$this->assertSame('value', $this->pool->getItem('item')->get());
6869
}
6970

7071
public function testItHasAnItem(): void
7172
{
72-
self::assertFalse($this->pool->hasItem('key'));
73+
$this->assertFalse($this->pool->hasItem('key'));
7374

7475
$item = $this->pool->getItem('key');
7576
$item->set('value');
7677
$this->pool->save($item);
7778

78-
self::assertTrue($this->pool->hasItem('key'));
79+
$this->assertTrue($this->pool->hasItem('key'));
7980
}
8081

8182
public function testItCommitsDeferredItems(): void
@@ -86,22 +87,22 @@ public function testItCommitsDeferredItems(): void
8687

8788
$this->pool->saveDeferred($item);
8889

89-
self::assertFalse($this->pool->getItem('item')->isHit());
90+
$this->assertFalse($this->pool->getItem('item')->isHit());
9091

9192
$this->pool->commit();
9293

93-
self::assertTrue($this->pool->getItem('item')->isHit());
94+
$this->assertTrue($this->pool->getItem('item')->isHit());
9495
}
9596

9697
public function testItCanBeCleared(): void
9798
{
9899
$this->pool->save($this->pool->getItem('key')->set('value'));
99100

100-
self::assertTrue($this->pool->getItem('key')->isHit());
101+
$this->assertTrue($this->pool->getItem('key')->isHit());
101102

102103
$this->pool->clear();
103104

104-
self::assertFalse($this->pool->getItem('key')->isHit());
105+
$this->assertFalse($this->pool->getItem('key')->isHit());
105106
}
106107

107108
public function testItReturnsMultipleItems(): void
@@ -111,35 +112,35 @@ public function testItReturnsMultipleItems(): void
111112

112113
$items = $this->pool->getItems(['first', 'second', 'third']);
113114

114-
self::assertCount(3, $items);
115-
self::assertIsArray($items);
115+
$this->assertCount(3, $items);
116+
$this->assertIsArray($items);
116117

117-
self::assertArrayHasKey('first', $items);
118-
self::assertTrue($items['first']->isHit());
118+
$this->assertArrayHasKey('first', $items);
119+
$this->assertTrue($items['first']->isHit());
119120

120-
self::assertArrayHasKey('second', $items);
121-
self::assertFalse($items['second']->isHit());
121+
$this->assertArrayHasKey('second', $items);
122+
$this->assertFalse($items['second']->isHit());
122123

123-
self::assertArrayHasKey('third', $items);
124-
self::assertTrue($items['third']->isHit());
124+
$this->assertArrayHasKey('third', $items);
125+
$this->assertTrue($items['third']->isHit());
125126
}
126127

127128
public function testItReturnsNoItemsWhenNoKeysAreGiven(): void
128129
{
129130
$this->pool->save($this->pool->getItem('key')->set('value'));
130131

131-
self::assertEmpty($this->pool->getItems());
132+
$this->assertEmpty($this->pool->getItems());
132133
}
133134

134135
public function testItDeletesAnItem(): void
135136
{
136137
$this->pool->save($this->pool->getItem('key')->set('value'));
137138

138-
self::assertTrue($this->pool->hasItem('key'));
139+
$this->assertTrue($this->pool->hasItem('key'));
139140

140141
$this->pool->deleteItem('key');
141142

142-
self::assertFalse($this->pool->hasItem('key'));
143+
$this->assertFalse($this->pool->hasItem('key'));
143144
}
144145

145146
public function testItDeletesMultipleItems(): void
@@ -150,9 +151,9 @@ public function testItDeletesMultipleItems(): void
150151

151152
$this->pool->deleteItems(['first', 'third', 'fourth']);
152153

153-
self::assertFalse($this->pool->hasItem('first'));
154-
self::assertTrue($this->pool->hasItem('second'));
155-
self::assertFalse($this->pool->hasItem('third'));
156-
self::assertFalse($this->pool->hasItem('fourth'));
154+
$this->assertFalse($this->pool->hasItem('first'));
155+
$this->assertTrue($this->pool->hasItem('second'));
156+
$this->assertFalse($this->pool->hasItem('third'));
157+
$this->assertFalse($this->pool->hasItem('fourth'));
157158
}
158159
}

0 commit comments

Comments
 (0)