Skip to content

Commit 8d73f2c

Browse files
committed
Change miminum PHP version to 8.0
to be able to use up to date language functions
1 parent b677dd9 commit 8d73f2c

11 files changed

+99
-82
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
fail-fast: true
1010
matrix:
11-
php: [7.2, 7.3, 7.4]
11+
php: [8.0, 8.1]
1212

1313
name: PHP ${{ matrix.php }}
1414

.php-cs-fixer.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests')
5+
->in(__DIR__ . DIRECTORY_SEPARATOR . 'src')
6+
->append(['.php_cs']);
7+
8+
$rules = [
9+
'@Symfony' => true,
10+
'phpdoc_no_empty_return' => false,
11+
'array_syntax' => ['syntax' => 'short'],
12+
'yoda_style' => false,
13+
'binary_operator_spaces' => [
14+
'operators' => [
15+
'=>' => 'align',
16+
'=' => 'align',
17+
],
18+
],
19+
'concat_space' => ['spacing' => 'one'],
20+
'not_operator_with_space' => false,
21+
];
22+
23+
$rules['increment_style'] = ['style' => 'post'];
24+
25+
return (new PhpCsFixer\Config())
26+
->setUsingCache(true)
27+
->setRules($rules)
28+
->setFinder($finder);

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.0.0] - 2021-12-22
8+
9+
### Changed
10+
- Minimum PHP version to 8.0
11+
712
## [1.0.0] (2019-12-06)
813
### Added
914
- classes for Server-Timing measurement
1015
- PSR-15 middleware to gather default metrics
11-
- Laravel middleware
16+
- Laravel middleware

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
"license": "MIT",
1313
"homepage": "https://github.com/fetzi/server-timing",
1414
"require": {
15-
"php": "^7.2",
15+
"php": "^8.0",
1616
"psr/http-server-middleware": "^1.0"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^8.5",
20-
"squizlabs/php_codesniffer": "^3.5"
19+
"friendsofphp/php-cs-fixer": "^3.4",
20+
"phpunit/phpunit": "^9.0",
21+
"rector/rector": "^0.12.8"
2122
},
2223
"autoload": {
2324
"psr-4": {
@@ -31,7 +32,8 @@
3132
},
3233
"scripts": {
3334
"test": "vendor/bin/phpunit",
34-
"lint": "vendor/bin/phpcs --standard=PSR2,PSR12 src/"
35+
"lint": "php-cs-fixer fix -v --dry-run",
36+
"fix": "php-cs-fixer fix -v"
3537
},
3638
"config": {
3739
"sort-packages": true

phpunit.xml.dist

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
12-
<testsuites>
13-
<testsuite name="Server-Timing Test Suite">
14-
<directory>tests</directory>
15-
</testsuite>
16-
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Server-Timing Test Suite">
10+
<directory>tests</directory>
11+
</testsuite>
12+
</testsuites>
2213
</phpunit>

rector.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Core\Configuration\Option;
6+
use Rector\Php74\Rector\Property\TypedPropertyRector;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
use Rector\Set\ValueObject\SetList;
9+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
10+
11+
return static function (ContainerConfigurator $containerConfigurator): void {
12+
// get parameters
13+
$parameters = $containerConfigurator->parameters();
14+
$parameters->set(Option::PATHS, [
15+
__DIR__ . '/src'
16+
]);
17+
18+
// Define what rule sets will be applied
19+
$containerConfigurator->import(SetList::CODE_QUALITY);
20+
$containerConfigurator->import(LevelSetList::UP_TO_PHP_80);
21+
22+
// get services (needed for register a single rule)
23+
// $services = $containerConfigurator->services();
24+
25+
// register a single rule
26+
// $services->set(TypedPropertyRector::class);
27+
};

src/Laravel/ServerTimingMiddleware.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,8 @@ class ServerTimingMiddleware
99
{
1010
private const REQUEST_TIME = 'REQUEST_TIME_FLOAT';
1111

12-
/**
13-
* @var ServerTimings
14-
*/
15-
private $serverTimings;
16-
17-
public function __construct(ServerTimings $serverTimings)
12+
public function __construct(private ServerTimings $serverTimings)
1813
{
19-
$this->serverTimings = $serverTimings;
2014
}
2115

2216
public function handle($request, Closure $next)

src/ServerTiming.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,18 @@
22

33
namespace Fetzi\ServerTiming;
44

5-
class ServerTiming
5+
class ServerTiming implements \Stringable
66
{
7-
/**
8-
* @var string
9-
*/
10-
private $name;
11-
12-
/**
13-
* @var string
14-
*/
15-
private $description;
7+
private ?float $start = null;
168

17-
/**
18-
* @var float
19-
*/
20-
private $start;
21-
22-
/**
23-
* @var float
24-
*/
25-
private $end;
9+
private ?float $end = null;
2610

27-
public function __construct(string $name, ?string $description = null)
11+
public function __construct(private string $name, private ?string $description = null)
2812
{
29-
$this->name = $name;
30-
$this->description = $description;
3113
}
3214

3315
/**
34-
* captures the starting microtime value for the server timing
16+
* captures the starting microtime value for the server timing.
3517
*
3618
* @param float $fixedValue allows to set start to a predefined value
3719
*/
@@ -41,14 +23,14 @@ public function start(float $fixedValue = null): void
4123
}
4224

4325
/**
44-
* captures the end microtime value for the server timing
26+
* captures the end microtime value for the server timing.
4527
*/
4628
public function stop(): void
4729
{
4830
$this->end = microtime(true);
4931
}
5032

51-
public function __toString()
33+
public function __toString(): string
5234
{
5335
$timing = $this->name;
5436

src/ServerTimingMiddleware.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Fetzi\ServerTiming;
44

5-
use Fetzi\ServerTiming\ServerTimings;
65
use Psr\Http\Message\ResponseInterface;
76
use Psr\Http\Message\ServerRequestInterface;
87
use Psr\Http\Server\MiddlewareInterface;
@@ -12,18 +11,12 @@ class ServerTimingMiddleware implements MiddlewareInterface
1211
{
1312
private const REQUEST_TIME = 'REQUEST_TIME_FLOAT';
1413

15-
/**
16-
* @var ServerTimings
17-
*/
18-
private $serverTimings;
19-
20-
public function __construct(ServerTimings $serverTimings)
14+
public function __construct(private ServerTimings $serverTimings)
2115
{
22-
$this->serverTimings = $serverTimings;
2316
}
2417

2518
/**
26-
* @inheritdoc
19+
* {@inheritdoc}
2720
*/
2821
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
2922
{

src/ServerTimings.php

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,26 @@
66

77
class ServerTimings
88
{
9-
/**
10-
* @var array
11-
*/
12-
private $timings = [];
9+
private array $timings = [];
1310

1411
/**
15-
* creates a new ServerTiming instance and registers it
12+
* creates a new ServerTiming instance and registers it.
1613
*
17-
* @param string $name the name of the server timing
18-
* @param string $description the description for the server timing
14+
* @param string $name the name of the server timing
15+
* @param string $description the description for the server timing
1916
*
2017
* @return ServerTiming
2118
*/
2219
public function create(string $name, ?string $description = null)
2320
{
24-
$serverTiming = new ServerTiming($name, $description);
21+
$serverTiming = new ServerTiming($name, $description);
2522
$this->timings[] = $serverTiming;
2623

2724
return $serverTiming;
2825
}
2926

3027
/**
31-
* returns the formatted Server-Timing header value
28+
* returns the formatted Server-Timing header value.
3229
*
3330
* @return string
3431
*/
@@ -42,11 +39,9 @@ public function getTimings(): ?string
4239
}
4340

4441
/**
45-
* adds the stored server timings to the given response instance
42+
* adds the stored server timings to the given response instance.
4643
*
4744
* @param ResponseInterface $response the response to add to
48-
*
49-
* @return ResponseInterface
5045
*/
5146
public function addToResponse(ResponseInterface $response): ResponseInterface
5247
{

tests/ServerTimingsTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class ServerTimingsTest extends TestCase
1010
{
1111
public function testWithEmptyTimings()
1212
{
13-
$serverTimings = new ServerTimings;
14-
$response = $this->prophesize(ResponseInterface::class);
13+
$serverTimings = new ServerTimings();
14+
$response = $this->prophesize(ResponseInterface::class);
1515

1616
$response->withAddedHeader()->shouldNotBeCalled();
1717

@@ -20,7 +20,7 @@ public function testWithEmptyTimings()
2020

2121
public function testWithAddedTimings()
2222
{
23-
$serverTimings = new ServerTimings;
23+
$serverTimings = new ServerTimings();
2424
$serverTimings->create('foo');
2525
$serverTimings->create('bar');
2626
$response = $this->prophesize(ResponseInterface::class);

0 commit comments

Comments
 (0)