Skip to content

Commit 6826748

Browse files
Replace more docblocks by type-hints
1 parent 7beac86 commit 6826748

File tree

11 files changed

+18
-71
lines changed

11 files changed

+18
-71
lines changed

Command/XliffLintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class XliffLintCommand extends Command
3333
private $directoryIteratorProvider;
3434
private $isReadableProvider;
3535

36-
public function __construct($name = null, $directoryIteratorProvider = null, $isReadableProvider = null)
36+
public function __construct(string $name = null, callable $directoryIteratorProvider = null, callable $isReadableProvider = null)
3737
{
3838
parent::__construct($name);
3939

DependencyInjection/TranslationDumperPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TranslationDumperPass implements CompilerPassInterface
2323
private $writerServiceId;
2424
private $dumperTag;
2525

26-
public function __construct($writerServiceId = 'translation.writer', $dumperTag = 'translation.dumper')
26+
public function __construct(string $writerServiceId = 'translation.writer', string $dumperTag = 'translation.dumper')
2727
{
2828
$this->writerServiceId = $writerServiceId;
2929
$this->dumperTag = $dumperTag;

DependencyInjection/TranslationExtractorPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TranslationExtractorPass implements CompilerPassInterface
2424
private $extractorServiceId;
2525
private $extractorTag;
2626

27-
public function __construct($extractorServiceId = 'translation.extractor', $extractorTag = 'translation.extractor')
27+
public function __construct(string $extractorServiceId = 'translation.extractor', string $extractorTag = 'translation.extractor')
2828
{
2929
$this->extractorServiceId = $extractorServiceId;
3030
$this->extractorTag = $extractorTag;

DependencyInjection/TranslatorPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class TranslatorPass implements CompilerPassInterface
2222
private $readerServiceId;
2323
private $loaderTag;
2424

25-
public function __construct($translatorServiceId = 'translator.default', $readerServiceId = 'translation.reader', $loaderTag = 'translation.loader')
25+
public function __construct(string $translatorServiceId = 'translator.default', string $readerServiceId = 'translation.reader', string $loaderTag = 'translation.loader')
2626
{
2727
$this->translatorServiceId = $translatorServiceId;
2828
$this->readerServiceId = $readerServiceId;

Dumper/FileDumper.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,8 @@ abstract protected function getExtension();
100100

101101
/**
102102
* Gets the relative file path using the template.
103-
*
104-
* @param string $domain The domain
105-
* @param string $locale The locale
106-
*
107-
* @return string The relative file path
108103
*/
109-
private function getRelativePath($domain, $locale)
104+
private function getRelativePath(string $domain, string $locale): string
110105
{
111106
return strtr($this->relativePathTemplate, array(
112107
'%domain%' => $domain,

Extractor/AbstractFileExtractor.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,7 @@ protected function extractFiles($resource)
4343
return $files;
4444
}
4545

46-
/**
47-
* @param string $file
48-
*
49-
* @return \SplFileInfo
50-
*/
51-
private function toSplFileInfo($file)
46+
private function toSplFileInfo(string $file): \SplFileInfo
5247
{
5348
return ($file instanceof \SplFileInfo) ? $file : new \SplFileInfo($file);
5449
}

Loader/MoFileLoader.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,8 @@ protected function loadResource($resource)
134134
* Reads an unsigned long from stream respecting endianness.
135135
*
136136
* @param resource $stream
137-
* @param bool $isBigEndian
138-
*
139-
* @return int
140137
*/
141-
private function readLong($stream, $isBigEndian)
138+
private function readLong($stream, bool $isBigEndian): int
142139
{
143140
$result = unpack($isBigEndian ? 'N1' : 'V1', fread($stream, 4));
144141
$result = current($result);

Loader/XliffFileLoader.php

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private function extract($resource, MessageCatalogue $catalogue, $domain)
7575
* @param MessageCatalogue $catalogue Catalogue where we'll collect messages and metadata
7676
* @param string $domain The domain
7777
*/
78-
private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $domain)
78+
private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, string $domain)
7979
{
8080
$xml = simplexml_import_dom($dom);
8181
$encoding = strtoupper($dom->encoding);
@@ -115,12 +115,7 @@ private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $
115115
}
116116
}
117117

118-
/**
119-
* @param \DOMDocument $dom
120-
* @param MessageCatalogue $catalogue
121-
* @param string $domain
122-
*/
123-
private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $domain)
118+
private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, string $domain)
124119
{
125120
$xml = simplexml_import_dom($dom);
126121
$encoding = strtoupper($dom->encoding);
@@ -163,13 +158,8 @@ private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $
163158

164159
/**
165160
* Convert a UTF8 string to the specified encoding.
166-
*
167-
* @param string $content String to decode
168-
* @param string $encoding Target encoding
169-
*
170-
* @return string
171161
*/
172-
private function utf8ToCharset($content, $encoding = null)
162+
private function utf8ToCharset(string $content, string $encoding = null): string
173163
{
174164
if ('UTF-8' !== $encoding && !empty($encoding)) {
175165
return mb_convert_encoding($content, $encoding, 'UTF-8');
@@ -181,13 +171,9 @@ private function utf8ToCharset($content, $encoding = null)
181171
/**
182172
* Validates and parses the given file into a DOMDocument.
183173
*
184-
* @param string $file
185-
* @param \DOMDocument $dom
186-
* @param string $schema source of the schema
187-
*
188174
* @throws InvalidResourceException
189175
*/
190-
private function validateSchema($file, \DOMDocument $dom, $schema)
176+
private function validateSchema(string $file, \DOMDocument $dom, string $schema)
191177
{
192178
$internalErrors = libxml_use_internal_errors(true);
193179

@@ -224,13 +210,8 @@ private function getSchema($xliffVersion)
224210

225211
/**
226212
* Internally changes the URI of a dependent xsd to be loaded locally.
227-
*
228-
* @param string $schemaSource Current content of schema file
229-
* @param string $xmlUri External URI of XML to convert to local
230-
*
231-
* @return string
232213
*/
233-
private function fixXmlLocation($schemaSource, $xmlUri)
214+
private function fixXmlLocation(string $schemaSource, string $xmlUri): string
234215
{
235216
$newPath = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
236217
$parts = explode('/', $newPath);
@@ -250,12 +231,8 @@ private function fixXmlLocation($schemaSource, $xmlUri)
250231

251232
/**
252233
* Returns the XML errors of the internal XML parser.
253-
*
254-
* @param bool $internalErrors
255-
*
256-
* @return array An array of errors
257234
*/
258-
private function getXmlErrors($internalErrors)
235+
private function getXmlErrors(bool $internalErrors): array
259236
{
260237
$errors = array();
261238
foreach (libxml_get_errors() as $error) {
@@ -279,13 +256,9 @@ private function getXmlErrors($internalErrors)
279256
* Gets xliff file version based on the root "version" attribute.
280257
* Defaults to 1.2 for backwards compatibility.
281258
*
282-
* @param \DOMDocument $dom
283-
*
284259
* @throws InvalidArgumentException
285-
*
286-
* @return string
287260
*/
288-
private function getVersionNumber(\DOMDocument $dom)
261+
private function getVersionNumber(\DOMDocument $dom): string
289262
{
290263
/** @var \DOMNode $xliff */
291264
foreach ($dom->getElementsByTagName('xliff') as $xliff) {
@@ -308,13 +281,7 @@ private function getVersionNumber(\DOMDocument $dom)
308281
return '1.2';
309282
}
310283

311-
/**
312-
* @param \SimpleXMLElement|null $noteElement
313-
* @param string|null $encoding
314-
*
315-
* @return array
316-
*/
317-
private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, $encoding = null)
284+
private function parseNotesMetadata(\SimpleXMLElement $noteElement = null, string $encoding = null): array
318285
{
319286
$notes = array();
320287

MessageCatalogue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
3030
* @param string $locale The locale
3131
* @param array $messages An array of messages classified by domain
3232
*/
33-
public function __construct($locale, array $messages = array())
33+
public function __construct(?string $locale, array $messages = array())
3434
{
3535
$this->locale = $locale;
3636
$this->messages = $messages;

Tests/Writer/TranslationWriterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testWrite()
2727

2828
$writer = new TranslationWriter();
2929
$writer->addDumper('test', $dumper);
30-
$writer->write(new MessageCatalogue(array()), 'test');
30+
$writer->write(new MessageCatalogue('en'), 'test');
3131
}
3232

3333
public function testDisableBackup()

0 commit comments

Comments
 (0)