Skip to content

Commit 45d95df

Browse files
refactor: add PHP 7.4+ property typehints to all class properties (#133)
Add missing typehints to all class properties across the codebase, replacing PHPDoc-only type annotations with native PHP property type declarations. Changes include: - Added typehints to all properties in main classes (Har, Log, Entry, Request, Response, Cache, Content, etc.) - Added typehints to all trait properties (CommentTrait, NameTrait, BodySizeTrait, etc.) - Used nullable types (?Type) for properties that can be null - Set explicit default values where needed - Used -1.0 (float) for timing properties with -1 defaults - Updated comparisons in Timings class to use -1.0 for consistency All tests pass successfully after these changes. Co-authored-by: Claude <[email protected]>
1 parent 0f293aa commit 45d95df

27 files changed

+71
-195
lines changed

src/Cache.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,17 @@ final class Cache
1818
* beforeRequest [object, optional] - State of a cache entry before the
1919
* request. Leave out this field if the information is not available.
2020
*
21-
* @var CacheState
22-
*
2321
* @Serializer\Type("Deviantintegral\Har\CacheState")
2422
*/
25-
private $beforeRequest;
23+
private ?CacheState $beforeRequest = null;
2624

2725
/**
2826
* afterRequest [object, optional] - State of a cache entry after the
2927
* request. Leave out this field if the information is not available.
3028
*
31-
* @var CacheState
32-
*
3329
* @Serializer\Type("Deviantintegral\Har\CacheState")
3430
*/
35-
private $afterRequest;
31+
private ?CacheState $afterRequest = null;
3632

3733
public function hasBeforeRequest(): bool
3834
{

src/CacheState.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,23 @@ final class CacheState
1919
/**
2020
* lastAccess [string] - The last time the cache entry was opened.
2121
*
22-
* @var string
23-
*
2422
* @Serializer\Type("string")
2523
*/
26-
private $lastAccess;
24+
private string $lastAccess;
2725

2826
/**
2927
* eTag [string] - Etag.
3028
*
31-
* @var string
32-
*
3329
* @Serializer\Type("string")
3430
*/
35-
private $eTag;
31+
private string $eTag;
3632

3733
/**
3834
* hitCount [number] - The number of times the cache entry has been opened.
3935
*
40-
* @var int
41-
*
4236
* @Serializer\Type("integer")
4337
*/
44-
private $hitCount = 0;
38+
private int $hitCount = 0;
4539

4640
public function getLastAccess(): string
4741
{

src/Content.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,42 +20,34 @@ final class Content
2020
* response.bodySize if there is no compression and bigger when the content
2121
* has been compressed.
2222
*
23-
* @var int
24-
*
2523
* @Serializer\Type("integer")
2624
*/
27-
private $size;
25+
private int $size;
2826

2927
/**
3028
* compression [number, optional] - Number of bytes saved. Leave out this
3129
* field if the information is not available.
3230
*
33-
* @var int
34-
*
3531
* @Serializer\Type("integer")
3632
*/
37-
private $compression;
33+
private int $compression;
3834

3935
/**
4036
* Number of bytes saved. Leave out this field if the information is not
4137
* available.
4238
*
43-
* @var int
44-
*
4539
* @Serializer\Type("integer")
4640
*/
47-
private $number;
41+
private ?int $number = null;
4842

4943
/**
5044
* Encoding used for response text field e.g "base64". Leave out this field
5145
* if the text field is HTTP decoded (decompressed & unchunked), than
5246
* trans-coded from its original character set into UTF-8.
5347
*
54-
* @var string
55-
*
5648
* @Serializer\Type("string")
5749
*/
58-
private $encoding;
50+
private ?string $encoding = null;
5951

6052
public function getCompression(): int
6153
{

src/Cookie.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,37 @@ final class Cookie
2121
/**
2222
* The name of the cookie.
2323
*
24-
* @var string
25-
*
2624
* @Serializer\Type("string")
2725
*/
28-
private $cookie;
26+
private string $cookie;
2927

3028
/**
3129
* The path pertaining to the cookie.
3230
*
33-
* @var string
34-
*
3531
* @Serializer\Type("string")
3632
*/
37-
private $path;
33+
private string $path;
3834

3935
/**
4036
* The host of the cookie.
4137
*
42-
* @var string
43-
*
4438
* @Serializer\Type("string")
4539
*/
46-
private $domain;
40+
private string $domain;
4741

4842
/**
4943
* Set to true if the cookie is HTTP only, false otherwise.
5044
*
51-
* @var bool
52-
*
5345
* @Serializer\Type("boolean")
5446
*/
55-
private $httpOnly;
47+
private ?bool $httpOnly = null;
5648

5749
/**
5850
* True if the cookie was transmitted over ssl, false otherwise.
5951
*
60-
* @var bool
61-
*
6252
* @Serializer\Type("boolean")
6353
*/
64-
private $secure;
54+
private ?bool $secure = null;
6555

6656
public function getCookie(): string
6757
{

src/Creator.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@ class Creator
1919
use NameTrait;
2020

2121
/**
22-
* @var string
23-
*
2422
* @Serializer\Type("string")
2523
*/
26-
private $version;
24+
private string $version;
2725

2826
public function getVersion(): string
2927
{

src/Entry.php

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,78 +22,60 @@ final class Entry
2222
* Reference to the parent page. Leave out this field if the application
2323
* does not support grouping by pages.
2424
*
25-
* @var string
26-
*
2725
* @Serializer\Type("string")
2826
*/
29-
private $pageref;
27+
private string $pageref;
3028

3129
/**
3230
* Total elapsed time of the request in milliseconds. This is the sum of all
3331
* timings available in the timings object (i.e. not including -1 values).
3432
*
35-
* @var float
36-
*
3733
* @Serializer\Type("float")
3834
*/
39-
private $time;
35+
private float $time;
4036

4137
/**
4238
* Detailed info about the request.
4339
*
44-
* @var Request
45-
*
4640
* @Serializer\Type("Deviantintegral\Har\Request")
4741
*/
48-
private $request;
42+
private Request $request;
4943

5044
/**
5145
* Detailed info about the response.
5246
*
53-
* @var Response
54-
*
5547
* @Serializer\Type("Deviantintegral\Har\Response")
5648
*/
57-
private $response;
49+
private Response $response;
5850

5951
/**
6052
* Info about cache usage.
6153
*
62-
* @var Cache
63-
*
6454
* @Serializer\Type("Deviantintegral\Har\Cache")
6555
*/
66-
private $cache;
56+
private Cache $cache;
6757

6858
/**
69-
* @var Timings
70-
*
7159
* @Serializer\Type("Deviantintegral\Har\Timings")
7260
*/
73-
private $timings;
61+
private Timings $timings;
7462

7563
/**
76-
* @var string
77-
*
7864
* @Serializer\Type("string")
7965
*/
80-
private $serverIPAddress;
66+
private string $serverIPAddress;
8167

8268
/**
83-
* @var string
84-
*
8569
* @Serializer\Type("string")
8670
*/
87-
private $connection;
71+
private string $connection;
8872

8973
/**
9074
* Detailed info about the request.
9175
*
92-
* @var Initiator
93-
*
9476
* @Serializer\Type("Deviantintegral\Har\Initiator")
9577
*/
96-
private $_initiator;
78+
private ?Initiator $_initiator = null;
9779

9880
public function getPageref(): string
9981
{

src/Har.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@
99
final class Har
1010
{
1111
/**
12-
* @var Log
13-
*
1412
* @Serializer\Type("Deviantintegral\Har\Log")
1513
*/
16-
private $log;
14+
private Log $log;
1715

1816
public function getLog(): Log
1917
{

src/Initiator.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
final class Initiator
1111
{
1212
/**
13-
* @var string
14-
*
1513
* @Serializer\Type("string")
1614
*
1715
* parser:
@@ -24,25 +22,21 @@ final class Initiator
2422
* Some other process or action, such as navigating to a page via a link
2523
* or entering a URL in the address bar.
2624
*/
27-
private $type;
25+
private ?string $type = null;
2826

2927
/**
3028
* URL of the entry that initiated this request.
3129
*
32-
* @var \Psr\Http\Message\UriInterface
33-
*
3430
* @Serializer\Type("Psr\Http\Message\UriInterface")
3531
*/
36-
private $url;
32+
private ?\Psr\Http\Message\UriInterface $url = null;
3733

3834
/**
3935
* Line number that initiated this request.
4036
*
41-
* @var int
42-
*
4337
* @Serializer\Type("integer")
4438
*/
45-
private $lineNumber;
39+
private ?int $lineNumber = null;
4640

4741
public function getType(): ?string
4842
{

src/Log.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,33 @@ class Log
2222
public const ISO_8601_MICROSECONDS = 'Y-m-d\TH:i:s.uT';
2323

2424
/**
25-
* @var string
26-
*
2725
* @Serializer\Type("string")
2826
*/
29-
private $version;
27+
private string $version;
3028

3129
/**
32-
* @var Creator
33-
*
3430
* @Serializer\Type("Deviantintegral\Har\Creator")
3531
*/
36-
private $creator;
32+
private Creator $creator;
3733

3834
/**
39-
* @var Browser
40-
*
4135
* @Serializer\Type("Deviantintegral\Har\Browser")
4236
*/
43-
private $browser;
37+
private Browser $browser;
4438

4539
/**
4640
* @var Page[]
4741
*
4842
* @Serializer\Type("array<Deviantintegral\Har\Page>")
4943
*/
50-
private $pages;
44+
private array $pages;
5145

5246
/**
5347
* @var Entry[]
5448
*
5549
* @Serializer\Type("array<integer, Deviantintegral\Har\Entry>")
5650
*/
57-
private $entries;
51+
private array $entries;
5852

5953
public function getVersion(): string
6054
{

src/Page.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@ final class Page
1414
use StartedDateTimeTrait;
1515

1616
/**
17-
* @var string
18-
*
1917
* @Serializer\Type("string")
2018
*/
21-
private $id;
19+
private string $id;
2220

2321
/**
24-
* @var string
25-
*
2622
* @Serializer\Type("string")
2723
*/
28-
private $title;
24+
private string $title;
2925

3026
/**
31-
* @var PageTimings
32-
*
3327
* @Serializer\Type("Deviantintegral\Har\PageTimings")
3428
*/
35-
private $pageTimings;
29+
private PageTimings $pageTimings;
3630

3731
public function getId(): string
3832
{

0 commit comments

Comments
 (0)