Skip to content

Commit 7a55035

Browse files
authored
Improve deps (#38)
* Improve deps * phpstan * Remove on pull request * Fix typos
1 parent 133763e commit 7a55035

File tree

6 files changed

+72
-31
lines changed

6 files changed

+72
-31
lines changed

Diff for: .github/workflows/tests.yml

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
name: CI
22
on:
33
- push
4-
- pull_request
54
jobs:
6-
build:
5+
phpstan:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- name: Checkout
9+
uses: actions/checkout@v2
10+
11+
- name: Setup PHP, with composer and extensions
12+
uses: shivammathur/setup-php@v2
13+
with:
14+
php-version: 7.3
15+
16+
- name: Install dependencies with Composer
17+
uses: ramsey/composer-install@v1
18+
19+
- name: Run phpstan
20+
run: vendor/bin/phpstan analyse --level=6 src/
21+
tests:
722
strategy:
823
matrix:
924
dependencies:
@@ -13,6 +28,7 @@ jobs:
1328
- 7.3
1429
- 7.4
1530
- 8.0
31+
- 8.1
1632
runs-on: ubuntu-latest
1733
steps:
1834
- name: Checkout

Diff for: composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
"maximebf/debugbar": "^1.4",
1717
"psr/http-server-handler": "^1.0",
1818
"psr/http-server-middleware": "^1.0",
19-
"psr/container": "^1.0",
20-
"psr/http-message": "^1.0.1",
21-
"psr/http-factory": "^1.0",
19+
"psr/container-implementation": "^1.0 || ^2.0",
20+
"psr/http-message-implementation": "^1.0",
2221
"psr/http-factory-implementation": "^1.0"
2322
},
2423
"require-dev": {
@@ -28,7 +27,8 @@
2827
"mezzio/mezzio": "^3.0",
2928
"mezzio/mezzio-fastroute": "^3.0.1",
3029
"laminas/laminas-servicemanager": "^3.3.2",
31-
"laminas/laminas-diactoros": "^2.0"
30+
"laminas/laminas-diactoros": "^2.0",
31+
"phpstan/phpstan": "^1.4"
3232
},
3333
"autoload": {
3434
"psr-4": {

Diff for: phpunit.xml

+11-13
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
3-
<phpunit bootstrap="./vendor/autoload.php" colors="true">
4-
<testsuites>
5-
<testsuite name="unit">
6-
<directory>./test</directory>
7-
</testsuite>
8-
</testsuites>
9-
10-
<filter>
11-
<whitelist processUncoveredFilesFromWhitelist="true">
12-
<directory suffix=".php">./src</directory>
13-
</whitelist>
14-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="unit">
10+
<directory>./test</directory>
11+
</testsuite>
12+
</testsuites>
1513
</phpunit>

Diff for: src/ConfigProvider.php

+6
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55

66
final class ConfigProvider
77
{
8+
/**
9+
* @return array<string, mixed>
10+
*/
811
public static function getConfig(): array
912
{
1013
return (new self())();
1114
}
1215

16+
/**
17+
* @return array<string, mixed>
18+
*/
1319
public function __invoke(): array
1420
{
1521
$config = include __DIR__ . '/../config/phpdebugbar.config.php';

Diff for: src/JavascriptRendererFactory.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ final class JavascriptRendererFactory
1111
{
1212
public function __invoke(ContainerInterface $container): JavascriptRenderer
1313
{
14-
$debugbar = $container->get(DebugBar::class);
14+
$debugBar = $container->get(DebugBar::class);
1515
$config = $container->get(ConfigProvider::class);
1616
$rendererOptions = $config['phpmiddleware']['phpdebugbar']['javascript_renderer'];
1717

18-
$renderer = new JavascriptRenderer($debugbar);
18+
$renderer = new JavascriptRenderer($debugBar);
1919
$renderer->setOptions($rendererOptions);
2020

2121
return $renderer;

Diff for: src/PhpDebugBarMiddleware.php

+31-10
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,27 @@ final class PhpDebugBarMiddleware implements MiddlewareInterface
2121
{
2222
public const FORCE_KEY = 'X-Enable-Debug-Bar';
2323

24+
/**
25+
* @var DebugBarRenderer
26+
*/
2427
private $debugBarRenderer;
28+
29+
/**
30+
* @var ResponseFactoryInterface
31+
*/
2532
private $responseFactory;
33+
34+
/**
35+
* @var StreamFactoryInterface
36+
*/
2637
private $streamFactory;
2738

2839
public function __construct(
29-
DebugBarRenderer $debugbarRenderer,
40+
DebugBarRenderer $debugBarRenderer,
3041
ResponseFactoryInterface $responseFactory,
3142
StreamFactoryInterface $streamFactory
3243
) {
33-
$this->debugBarRenderer = $debugbarRenderer;
44+
$this->debugBarRenderer = $debugBarRenderer;
3445
$this->responseFactory = $responseFactory;
3546
$this->streamFactory = $streamFactory;
3647
}
@@ -60,7 +71,14 @@ public function process(ServerRequest $request, RequestHandler $handler): Respon
6071
public function __invoke(ServerRequest $request, Response $response, callable $next): Response
6172
{
6273
$handler = new class($next, $response) implements RequestHandler {
74+
/**
75+
* @var callable
76+
*/
6377
private $next;
78+
79+
/**
80+
* @var Response
81+
*/
6482
private $response;
6583

6684
public function __construct(callable $next, Response $response)
@@ -81,9 +99,9 @@ private function shouldReturnResponse(ServerRequest $request, Response $response
8199
{
82100
$forceHeaderValue = $request->getHeaderLine(self::FORCE_KEY);
83101
$forceCookieValue = $request->getCookieParams()[self::FORCE_KEY] ?? '';
84-
$forceAttibuteValue = $request->getAttribute(self::FORCE_KEY, '');
85-
$isForceEnable = in_array('true', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true);
86-
$isForceDisable = in_array('false', [$forceHeaderValue, $forceCookieValue, $forceAttibuteValue], true);
102+
$forceAttributeValue = $request->getAttribute(self::FORCE_KEY, '');
103+
$isForceEnable = in_array('true', [$forceHeaderValue, $forceCookieValue, $forceAttributeValue], true);
104+
$isForceDisable = in_array('false', [$forceHeaderValue, $forceCookieValue, $forceAttributeValue], true);
87105

88106
return $isForceDisable || (!$isForceEnable && ($this->isRedirect($response) || !$this->isHtmlAccepted($request)));
89107
}
@@ -169,22 +187,22 @@ private function getContentTypeByFileName(string $filename): string
169187
'woff2' => 'application/font-woff2',
170188
];
171189

172-
return isset($map[$ext]) ? $map[$ext] : 'text/plain';
190+
return $map[$ext] ?? 'text/plain';
173191
}
174192

175193
private function isHtmlResponse(Response $response): bool
176194
{
177-
return $this->hasHeaderContains($response, 'Content-Type', 'text/html');
195+
return $this->isHtml($response, 'Content-Type');
178196
}
179197

180198
private function isHtmlAccepted(ServerRequest $request): bool
181199
{
182-
return $this->hasHeaderContains($request, 'Accept', 'text/html');
200+
return $this->isHtml($request, 'Accept');
183201
}
184202

185-
private function hasHeaderContains(MessageInterface $message, string $headerName, string $value): bool
203+
private function isHtml(MessageInterface $message, string $headerName): bool
186204
{
187-
return strpos($message->getHeaderLine($headerName), $value) !== false;
205+
return strpos($message->getHeaderLine($headerName), 'text/html') !== false;
188206
}
189207

190208
private function isRedirect(Response $response): bool
@@ -216,6 +234,9 @@ private function serializeResponse(Response $response) : string
216234
);
217235
}
218236

237+
/**
238+
* @param array<string, array<string>> $headers
239+
*/
219240
private function serializeHeaders(array $headers) : string
220241
{
221242
$lines = [];

0 commit comments

Comments
 (0)