File tree 11 files changed +99
-82
lines changed 11 files changed +99
-82
lines changed Original file line number Diff line number Diff line change 8
8
strategy :
9
9
fail-fast : true
10
10
matrix :
11
- php : [7.2, 7.3, 7.4 ]
11
+ php : [8.0, 8.1 ]
12
12
13
13
name : PHP ${{ matrix.php }}
14
14
Original file line number Diff line number Diff line change
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 );
Original file line number Diff line number Diff line change @@ -4,8 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
The format is based on [ Keep a Changelog] ( https://keepachangelog.com/en/1.0.0/ ) ,
5
5
and this project adheres to [ Semantic Versioning] ( https://semver.org/spec/v2.0.0.html ) .
6
6
7
+ ## [ 2.0.0] - 2021-12-22
8
+
9
+ ### Changed
10
+ - Minimum PHP version to 8.0
11
+
7
12
## [ 1.0.0] (2019-12-06)
8
13
### Added
9
14
- classes for Server-Timing measurement
10
15
- PSR-15 middleware to gather default metrics
11
- - Laravel middleware
16
+ - Laravel middleware
Original file line number Diff line number Diff line change 12
12
"license" : " MIT" ,
13
13
"homepage" : " https://github.com/fetzi/server-timing" ,
14
14
"require" : {
15
- "php" : " ^7.2 " ,
15
+ "php" : " ^8.0 " ,
16
16
"psr/http-server-middleware" : " ^1.0"
17
17
},
18
18
"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"
21
22
},
22
23
"autoload" : {
23
24
"psr-4" : {
31
32
},
32
33
"scripts" : {
33
34
"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"
35
37
},
36
38
"config" : {
37
39
"sort-packages" : true
Original file line number Diff line number Diff line change 1
1
<?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 >
22
13
</phpunit >
Original file line number Diff line number Diff line change
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
+ };
Original file line number Diff line number Diff line change @@ -9,14 +9,8 @@ class ServerTimingMiddleware
9
9
{
10
10
private const REQUEST_TIME = 'REQUEST_TIME_FLOAT ' ;
11
11
12
- /**
13
- * @var ServerTimings
14
- */
15
- private $ serverTimings ;
16
-
17
- public function __construct (ServerTimings $ serverTimings )
12
+ public function __construct (private ServerTimings $ serverTimings )
18
13
{
19
- $ this ->serverTimings = $ serverTimings ;
20
14
}
21
15
22
16
public function handle ($ request , Closure $ next )
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fetzi \ServerTiming ;
4
4
5
- class ServerTiming
5
+ class ServerTiming implements \Stringable
6
6
{
7
- /**
8
- * @var string
9
- */
10
- private $ name ;
11
-
12
- /**
13
- * @var string
14
- */
15
- private $ description ;
7
+ private ?float $ start = null ;
16
8
17
- /**
18
- * @var float
19
- */
20
- private $ start ;
21
-
22
- /**
23
- * @var float
24
- */
25
- private $ end ;
9
+ private ?float $ end = null ;
26
10
27
- public function __construct (string $ name , ?string $ description = null )
11
+ public function __construct (private string $ name , private ?string $ description = null )
28
12
{
29
- $ this ->name = $ name ;
30
- $ this ->description = $ description ;
31
13
}
32
14
33
15
/**
34
- * captures the starting microtime value for the server timing
16
+ * captures the starting microtime value for the server timing.
35
17
*
36
18
* @param float $fixedValue allows to set start to a predefined value
37
19
*/
@@ -41,14 +23,14 @@ public function start(float $fixedValue = null): void
41
23
}
42
24
43
25
/**
44
- * captures the end microtime value for the server timing
26
+ * captures the end microtime value for the server timing.
45
27
*/
46
28
public function stop (): void
47
29
{
48
30
$ this ->end = microtime (true );
49
31
}
50
32
51
- public function __toString ()
33
+ public function __toString (): string
52
34
{
53
35
$ timing = $ this ->name ;
54
36
Original file line number Diff line number Diff line change 2
2
3
3
namespace Fetzi \ServerTiming ;
4
4
5
- use Fetzi \ServerTiming \ServerTimings ;
6
5
use Psr \Http \Message \ResponseInterface ;
7
6
use Psr \Http \Message \ServerRequestInterface ;
8
7
use Psr \Http \Server \MiddlewareInterface ;
@@ -12,18 +11,12 @@ class ServerTimingMiddleware implements MiddlewareInterface
12
11
{
13
12
private const REQUEST_TIME = 'REQUEST_TIME_FLOAT ' ;
14
13
15
- /**
16
- * @var ServerTimings
17
- */
18
- private $ serverTimings ;
19
-
20
- public function __construct (ServerTimings $ serverTimings )
14
+ public function __construct (private ServerTimings $ serverTimings )
21
15
{
22
- $ this ->serverTimings = $ serverTimings ;
23
16
}
24
17
25
18
/**
26
- * @inheritdoc
19
+ * { @inheritdoc}
27
20
*/
28
21
public function process (ServerRequestInterface $ request , RequestHandlerInterface $ handler ): ResponseInterface
29
22
{
Original file line number Diff line number Diff line change 6
6
7
7
class ServerTimings
8
8
{
9
- /**
10
- * @var array
11
- */
12
- private $ timings = [];
9
+ private array $ timings = [];
13
10
14
11
/**
15
- * creates a new ServerTiming instance and registers it
12
+ * creates a new ServerTiming instance and registers it.
16
13
*
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
19
16
*
20
17
* @return ServerTiming
21
18
*/
22
19
public function create (string $ name , ?string $ description = null )
23
20
{
24
- $ serverTiming = new ServerTiming ($ name , $ description );
21
+ $ serverTiming = new ServerTiming ($ name , $ description );
25
22
$ this ->timings [] = $ serverTiming ;
26
23
27
24
return $ serverTiming ;
28
25
}
29
26
30
27
/**
31
- * returns the formatted Server-Timing header value
28
+ * returns the formatted Server-Timing header value.
32
29
*
33
30
* @return string
34
31
*/
@@ -42,11 +39,9 @@ public function getTimings(): ?string
42
39
}
43
40
44
41
/**
45
- * adds the stored server timings to the given response instance
42
+ * adds the stored server timings to the given response instance.
46
43
*
47
44
* @param ResponseInterface $response the response to add to
48
- *
49
- * @return ResponseInterface
50
45
*/
51
46
public function addToResponse (ResponseInterface $ response ): ResponseInterface
52
47
{
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ class ServerTimingsTest extends TestCase
10
10
{
11
11
public function testWithEmptyTimings ()
12
12
{
13
- $ serverTimings = new ServerTimings ;
14
- $ response = $ this ->prophesize (ResponseInterface::class);
13
+ $ serverTimings = new ServerTimings () ;
14
+ $ response = $ this ->prophesize (ResponseInterface::class);
15
15
16
16
$ response ->withAddedHeader ()->shouldNotBeCalled ();
17
17
@@ -20,7 +20,7 @@ public function testWithEmptyTimings()
20
20
21
21
public function testWithAddedTimings ()
22
22
{
23
- $ serverTimings = new ServerTimings ;
23
+ $ serverTimings = new ServerTimings () ;
24
24
$ serverTimings ->create ('foo ' );
25
25
$ serverTimings ->create ('bar ' );
26
26
$ response = $ this ->prophesize (ResponseInterface::class);
You can’t perform that action at this time.
0 commit comments