Skip to content

Commit f396153

Browse files
committed
Use property type hints
Not a BC break since all of them are private. Had to change an initialization check in `MbTranscoder::__construct`, since PHPStan figured out it is not nullable.
1 parent ac7fc2c commit f396153

7 files changed

+10
-24
lines changed

.php-cs-fixer.php

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'@Symfony' => true,
88
'@PHP74Migration' => true,
99
'@PHP74Migration:risky' => true,
10+
'phpdoc_to_property_type' => true,
1011
// 'phpdoc_to_param_type' => true, // requires PHP 8.0
1112
'phpdoc_to_return_type' => true,
1213
// overwrite some Symfony rules

src/IconvTranscoder.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010

1111
class IconvTranscoder implements TranscoderInterface
1212
{
13-
/**
14-
* @var string
15-
*/
16-
private $defaultEncoding;
13+
private string $defaultEncoding;
1714

1815
/**
1916
* Create an Iconv-based transcoder.

src/MbTranscoder.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ class MbTranscoder implements TranscoderInterface
1313
/**
1414
* @var array<string, int>
1515
*/
16-
private static $encodings;
16+
private static array $encodings;
1717

18-
/**
19-
* @var string
20-
*/
21-
private $defaultEncoding;
18+
private string $defaultEncoding;
2219

2320
/**
2421
* Create a Mb-based transcoder.
@@ -31,7 +28,7 @@ public function __construct(string $defaultEncoding = 'UTF-8')
3128
throw new ExtensionMissingException('mb');
3229
}
3330

34-
if (null === self::$encodings) {
31+
if (!isset(self::$encodings)) {
3532
self::$encodings = array_change_key_case(
3633
array_flip(mb_list_encodings()),
3734
CASE_LOWER

src/Transcoder.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class Transcoder implements TranscoderInterface
1212
/**
1313
* @var array<string, TranscoderInterface>
1414
*/
15-
private static $chain;
15+
private static array $chain;
1616

1717
/**
1818
* @var TranscoderInterface[]
1919
*/
20-
private $transcoders = [];
20+
private array $transcoders = [];
2121

2222
/**
2323
* @param TranscoderInterface[] $transcoders

tests/IconvTranscoderTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
class IconvTranscoderTest extends \PHPUnit\Framework\TestCase
1010
{
11-
/**
12-
* @var IconvTranscoder
13-
*/
14-
private $transcoder;
11+
private IconvTranscoder $transcoder;
1512

1613
/**
1714
* @before

tests/MbTranscoderTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@
88

99
class MbTranscoderTest extends \PHPUnit\Framework\TestCase
1010
{
11-
/**
12-
* @var MbTranscoder
13-
*/
14-
private $transcoder;
11+
private MbTranscoder $transcoder;
1512

1613
/**
1714
* @before

tests/TranscoderTest.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99

1010
class TranscoderTest extends \PHPUnit\Framework\TestCase
1111
{
12-
/**
13-
* @var TranscoderInterface
14-
*/
15-
private $transcoder;
12+
private TranscoderInterface $transcoder;
1613

1714
/**
1815
* @before

0 commit comments

Comments
 (0)