Skip to content

Commit ace7198

Browse files
authored
Merge pull request #610 from deguif/review-private-final-type-hints
Add type-hints on private / final methods / properties
2 parents 041d482 + 6584336 commit ace7198

33 files changed

+170
-624
lines changed

Annotation/Desc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
*/
3030
final class Desc
3131
{
32-
/** @var string @Required */
33-
public $text;
32+
/** @Required */
33+
public string $text;
3434

3535
public function __construct()
3636
{

Annotation/Meaning.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
*/
3030
final class Meaning
3131
{
32-
/** @var string @Required */
33-
public $text;
32+
/** @Required */
33+
public string $text;
3434

3535
public function __construct()
3636
{

Controller/ApiController.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,9 @@
3636
#[Route('/api')]
3737
class ApiController
3838
{
39-
/**
40-
* @var ConfigFactory
41-
*/
42-
private $configFactory;
39+
private ConfigFactory $configFactory;
4340

44-
/**
45-
* @var Updater
46-
*/
47-
private $updater;
41+
private Updater $updater;
4842

4943
public function __construct(ConfigFactory $configFactory, Updater $updater)
5044
{

Controller/TranslateController.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,13 @@
3737
*/
3838
class TranslateController
3939
{
40-
/**
41-
* @var ConfigFactory
42-
*/
43-
private $configFactory;
40+
private ConfigFactory $configFactory;
4441

45-
/**
46-
* @var LoaderManager
47-
*/
48-
private $loader;
42+
private LoaderManager $loader;
4943

50-
/**
51-
* @var Environment|null
52-
*/
53-
private $twig;
44+
private Environment|null $twig;
5445

55-
/**
56-
* @var string
57-
*/
58-
private $sourceLanguage;
46+
private string|null $sourceLanguage = null;
5947

6048
public function __construct(ConfigFactory $configFactory, LoaderManager $loader, ?Environment $twig = null)
6149
{

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
class Configuration implements ConfigurationInterface
2828
{
29-
private $container;
29+
private ContainerBuilder $container;
3030

3131
public function __construct(ContainerBuilder $container)
3232
{

Logger/OutputLogger.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,9 @@ class OutputLogger implements LoggerInterface
3535
public const DEBUG = 128;
3636
public const ALL = 255;
3737

38-
/**
39-
* @var OutputInterface
40-
*/
41-
private $output;
38+
private OutputInterface $output;
4239

43-
/**
44-
* @var int
45-
*/
46-
private $level = self::ALL;
40+
private int $level = self::ALL;
4741

4842
public function __construct(OutputInterface $output)
4943
{

Model/FileSource.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,11 @@
2222

2323
class FileSource implements SourceInterface
2424
{
25-
/**
26-
* @var string
27-
*/
28-
private $path;
25+
private string $path;
2926

30-
/**
31-
* @var int
32-
*/
33-
private $line;
27+
private int|null $line;
3428

35-
/**
36-
* @var int
37-
*/
38-
private $column;
29+
private int|null $column;
3930

4031
/**
4132
* @param string $path

Model/Message.php

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,48 +31,34 @@ class Message
3131
{
3232
/**
3333
* Unique ID of this message (same across the same domain).
34-
*
35-
* @var string
3634
*/
37-
private $id;
35+
private string $id;
3836

39-
/**
40-
* @var bool
41-
*/
42-
private $new = true;
37+
private bool $new = true;
4338

44-
/**
45-
* @var string
46-
*/
47-
private $domain;
39+
private string $domain;
4840

4941
/**
5042
* This is the translated string.
51-
*
52-
* @var string
5343
*/
54-
private $localeString;
44+
private string|null $localeString = null;
5545

5646
/**
5747
* Additional information about the intended meaning.
58-
*
59-
* @var string
6048
*/
61-
private $meaning;
49+
private string|null $meaning = null;
6250

6351
/**
6452
* The description/sample for translators.
65-
*
66-
* @var string
6753
*/
68-
private $desc;
54+
private string|null $desc = null;
6955

7056
/**
7157
* The sources where this message occurs.
7258
*
73-
* @var array
59+
* @var SourceInterface[]
7460
*/
75-
private $sources = [];
61+
private array $sources = [];
7662

7763
/**
7864
* @deprecated Will be removed in 2.0. Use the FileSourceFactory

Model/MessageCatalogue.php

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@
3636
*/
3737
class MessageCatalogue
3838
{
39-
/**
40-
* @var string
41-
*/
42-
private $locale;
39+
private string|null $locale = null;
4340

44-
/**
45-
* @var array
46-
*/
47-
private $domains = [];
41+
/** @var array<string, MessageCollection> */
42+
private array $domains = [];
4843

4944
public function setLocale($locale)
5045
{
@@ -87,8 +82,6 @@ public function get($id, $domain = 'messages')
8782
}
8883

8984
/**
90-
* @param Message $message
91-
*
9285
* @return bool
9386
*/
9487
public function has(Message $message)
@@ -139,17 +132,8 @@ public function getDomains()
139132
return $this->domains;
140133
}
141134

142-
/**
143-
* @param string $domain
144-
*
145-
* @return MessageCollection
146-
*/
147-
private function getOrCreateDomain($domain)
135+
private function getOrCreateDomain(string $domain): MessageCollection
148136
{
149-
if (!$this->hasDomain($domain)) {
150-
$this->domains[$domain] = new MessageCollection($this);
151-
}
152-
153-
return $this->domains[$domain];
137+
return $this->domains[$domain] ??= new MessageCollection($this);
154138
}
155139
}

Model/MessageCollection.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,10 @@
3333
*/
3434
class MessageCollection
3535
{
36-
/**
37-
* @var MessageCatalogue
38-
*/
39-
private $catalogue;
36+
private MessageCatalogue|null $catalogue = null;
4037

41-
/**
42-
* @var array
43-
*/
44-
private $messages = [];
38+
/** @var array<string, Message> */
39+
private array $messages = [];
4540

4641
public function setCatalogue(MessageCatalogue $catalogue)
4742
{
@@ -155,7 +150,7 @@ public function merge(MessageCollection $domain)
155150
}
156151
}
157152

158-
private function checkConsistency(Message $oldMessage, Message $newMessage)
153+
private function checkConsistency(Message $oldMessage, Message $newMessage): void
159154
{
160155
$oldDesc = $oldMessage->getDesc();
161156
$newDesc = $newMessage->getDesc();

0 commit comments

Comments
 (0)