Skip to content

Commit eed7738

Browse files
authored
Merge pull request #590 from FriendsOfSymfony/phpstan-levels
Phpstan levels
2 parents 5fb0c38 + 50de1fa commit eed7738

19 files changed

+92
-59
lines changed

.github/workflows/static.yml

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ on:
88

99
jobs:
1010
phpstan-src:
11-
name: PHPStan src
11+
name: PHPStan
1212
runs-on: ubuntu-latest
1313

1414
steps:
1515
- name: Checkout code
1616
uses: actions/checkout@v4
1717

1818
- name: Pull in optional dependencies
19-
run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 symfony/process
19+
run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2 symfony/process mockery/mockery phpstan/phpstan-mockery guzzlehttp/guzzle php-http/mock-client
2020

2121
- name: Cache Vendor
2222
id: cache-vendor
@@ -30,31 +30,6 @@ jobs:
3030
with:
3131
args: analyze --no-progress
3232

33-
phpstan-tests:
34-
name: PHPStan tests
35-
runs-on: ubuntu-latest
36-
env:
37-
REQUIRE_DEV: "true"
38-
39-
steps:
40-
- name: Checkout code
41-
uses: actions/checkout@v4
42-
43-
- name: Pull in optional dependencies
44-
run: composer require --no-update phpunit/phpunit toflar/psr6-symfony-http-cache-store:^4.2
45-
46-
- name: Cache Vendor
47-
id: cache-vendor
48-
uses: actions/cache@v4
49-
with:
50-
path: vendor
51-
key: ${{ runner.os }}-vendor
52-
53-
- name: PHPStan
54-
uses: docker://oskarstark/phpstan-ga
55-
with:
56-
args: analyze --no-progress -c phpstan.tests.neon.dist
57-
5833
php-cs-fixer:
5934
name: PHP-CS-Fixer
6035
runs-on: ubuntu-latest

doc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ doctest:
154154
"results in $(BUILDDIR)/doctest/output.txt."
155155

156156
spelling:
157-
$(SPHINXBUILD) -b spelling $(ALLSPHINXOPTS) -w $(BUILDDIR)/spelling/output.txt $(BUILDDIR)/spelling
157+
$(SPHINXBUILD) -b spelling $(ALLSPHINXOPTS) -w $(BUILDDIR)/spelling/output.txt $(BUILDDIR)/spelling
158158
@echo "Spelling report generated in $(BUILDDIR)/spelling/output.txt"

phpstan.neon.dist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
parameters:
2-
level: 1
2+
level: 4
33
paths:
44
- src
5+
- tests
6+
7+
treatPhpDocTypesAsCertain: false

phpstan.tests.neon.dist

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/ProxyClient/Cloudflare.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function invalidateTags(array $tags): static
8181
sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']),
8282
[],
8383
false,
84-
$this->json_encode(['tags' => $tags])
84+
json_encode(['tags' => $tags], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES)
8585
);
8686

8787
return $this;
@@ -115,7 +115,7 @@ public function clear(): static
115115
sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']),
116116
['Accept' => 'application/json'],
117117
false,
118-
$this->json_encode(['purge_everything' => true])
118+
json_encode(['purge_everything' => true], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES)
119119
);
120120

121121
return $this;
@@ -130,7 +130,7 @@ public function flush(): int
130130
sprintf(self::API_ENDPOINT.'/zones/%s/purge_cache', $this->options['zone_identifier']),
131131
[],
132132
false,
133-
$this->json_encode(['files' => $urlChunk])
133+
json_encode(['files' => $urlChunk], JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES)
134134
);
135135
}
136136
$this->purgeByUrlsData = [];
@@ -165,14 +165,4 @@ protected function configureOptions(): OptionsResolver
165165

166166
return $resolver;
167167
}
168-
169-
private function json_encode(array $data): string
170-
{
171-
$json = json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
172-
if (false === $json) {
173-
throw new \InvalidArgumentException(sprintf('Cannot encode "$data": %s', json_last_error_msg()));
174-
}
175-
176-
return $json;
177-
}
178168
}

src/ProxyClient/MultiplexerClient.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function clear(): static
133133
* Invoke the given $method on all available ProxyClients implementing the
134134
* given $interface.
135135
*
136-
* @param string $interface The FQN of the interface
136+
* @param class-string $interface The FQN of the interface
137137
* @param string $method The method to invoke
138138
* @param array<mixed> $arguments The arguments to be passed to the method
139139
*/
@@ -155,7 +155,9 @@ private function getProxyClients(string $interface): array
155155
{
156156
return array_filter(
157157
$this->proxyClients,
158-
static function ($proxyClient) use ($interface) {
158+
static function (ProxyClient $proxyClient) use ($interface) {
159+
// https://github.com/phpstan/phpstan/issues/8464
160+
// @phpstan-ignore-next-line
159161
return is_subclass_of($proxyClient, $interface);
160162
}
161163
);

src/SymfonyCache/PurgeTagsListener.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function handlePurgeTags(CacheEvent $event): void
118118
if (1 === $reflection->getMethod('all')->getNumberOfParameters()) {
119119
$headers = $request->headers->all($this->tagsHeader);
120120
} else {
121-
$headers = $request->headers->get($this->tagsHeader, '', false);
121+
$headers = $request->headers->get($this->tagsHeader, '');
122122
}
123123

124124
$tags = $this->tagsParser->parseTagsHeaderValue($headers);

src/Test/EventDispatchingHttpCacheTestCase.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ public function testPreStoreResponseNoStore()
251251
$httpCache = $this->getHttpCachePartialMock();
252252
$testListener = new TestListener($this, $httpCache, $request);
253253
$testListener->preStoreResponse = $preStoreResponse;
254+
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
254255
$httpCache->addSubscriber($testListener);
255256

256257
$store = $this->createMock(StoreInterface::class);
@@ -279,8 +280,8 @@ public function testPreInvalidateCalled(): void
279280

280281
$httpCache = $this->getHttpCachePartialMock(['pass']);
281282
$testListener = new TestListener($this, $httpCache, $request);
282-
$httpCache->addSubscriber($testListener);
283283
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
284+
$httpCache->addSubscriber($testListener);
284285
$httpCache
285286
->method('pass')
286287
->with($request)
@@ -307,8 +308,8 @@ public function testPreInvalidateReturnEarly(): void
307308
$httpCache = $this->getHttpCachePartialMock(['pass']);
308309
$testListener = new TestListener($this, $httpCache, $request);
309310
$testListener->preInvalidateResponse = $response;
310-
$httpCache->addSubscriber($testListener);
311311
$this->assertTrue(method_exists($httpCache, 'addSubscriber'));
312+
$httpCache->addSubscriber($testListener);
312313
$httpCache
313314
->expects($this->never())
314315
->method('pass')
@@ -327,6 +328,7 @@ public function testAddListener(): void
327328

328329
$httpCache = $this->getHttpCachePartialMock(['lookup']);
329330
$simpleListener = new SimpleListener($this, $httpCache, $request);
331+
$this->assertTrue(method_exists($httpCache, 'addListener'));
330332
$httpCache->addListener(Events::PRE_HANDLE, [$simpleListener, 'callback']);
331333

332334
$httpCache

src/Test/WebServerSubscriber.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace FOS\HttpCache\Test;
1313

14-
use PHPUnit\Event\Code\TestMethod;
1514
use PHPUnit\Event\TestRunner\ExecutionStarted;
1615
use PHPUnit\Event\TestRunner\ExecutionStartedSubscriber;
1716
use PHPUnit\Event\TestSuite\TestSuite;
@@ -52,8 +51,6 @@ private function hasTestsWithGroup(TestSuite $testSuite, string $group): bool
5251
continue;
5352
}
5453

55-
assert($test instanceof TestMethod);
56-
5754
foreach ($test->metadata()->isGroup() as $testGroup) {
5855
assert($testGroup instanceof Group);
5956

@@ -83,7 +80,7 @@ public function startPhpWebServer(): int
8380

8481
$this->waitFor($this->getHostName(), (int) $this->getPort(), 2000);
8582

86-
return $output[0];
83+
return (int) $output[0];
8784
}
8885

8986
public function getHostName(): string

tests/Functional/ProxyClient/NginxProxyClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testPurgeContentType(): void
3535
{
3636
$this->markTestSkipped('Not working with nginx, it can only purge one type');
3737

38-
$this->assertPurgeContentType($this->getProxyClient());
38+
// $this->assertPurgeContentType($this->getProxyClient());
3939
}
4040

4141
public function testPurgeSeparateLocationHost(): void
@@ -57,6 +57,6 @@ public function testRefreshContentType(): void
5757
{
5858
$this->markTestSkipped('TODO: is nginx mixing up variants?');
5959

60-
$this->assertRefreshContentType($this->getProxyClient());
60+
// $this->assertRefreshContentType($this->getProxyClient());
6161
}
6262
}

0 commit comments

Comments
 (0)