Skip to content

Commit ec333c9

Browse files
Replace more docblocks by type-hints
1 parent 1ef1cdd commit ec333c9

15 files changed

+35
-144
lines changed

DependencyInjection/SerializerPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SerializerPass implements CompilerPassInterface
3131
private $normalizerTag;
3232
private $encoderTag;
3333

34-
public function __construct($serializerService = 'serializer', $normalizerTag = 'serializer.normalizer', $encoderTag = 'serializer.encoder')
34+
public function __construct(string $serializerService = 'serializer', string $normalizerTag = 'serializer.normalizer', string $encoderTag = 'serializer.encoder')
3535
{
3636
$this->serializerService = $serializerService;
3737
$this->normalizerTag = $normalizerTag;

Encoder/CsvEncoder.php

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
3333
private $escapeChar;
3434
private $keySeparator;
3535

36-
/**
37-
* @param string $delimiter
38-
* @param string $enclosure
39-
* @param string $escapeChar
40-
* @param string $keySeparator
41-
*/
42-
public function __construct($delimiter = ',', $enclosure = '"', $escapeChar = '\\', $keySeparator = '.')
36+
public function __construct(string $delimiter = ',', string $enclosure = '"', string $escapeChar = '\\', string $keySeparator = '.')
4337
{
4438
$this->delimiter = $delimiter;
4539
$this->enclosure = $enclosure;
@@ -174,13 +168,8 @@ public function supportsDecoding($format)
174168

175169
/**
176170
* Flattens an array and generates keys including the path.
177-
*
178-
* @param array $array
179-
* @param array $result
180-
* @param string $keySeparator
181-
* @param string $parentKey
182171
*/
183-
private function flatten(array $array, array &$result, $keySeparator, $parentKey = '')
172+
private function flatten(array $array, array &$result, string $keySeparator, string $parentKey = '')
184173
{
185174
foreach ($array as $key => $value) {
186175
if (is_array($value)) {

Encoder/JsonDecode.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ class JsonDecode implements DecoderInterface
3232
* @param bool $associative True to return the result associative array, false for a nested stdClass hierarchy
3333
* @param int $depth Specifies the recursion depth
3434
*/
35-
public function __construct($associative = false, $depth = 512)
35+
public function __construct(bool $associative = false, int $depth = 512)
3636
{
3737
$this->associative = $associative;
38-
$this->recursionDepth = (int) $depth;
38+
$this->recursionDepth = $depth;
3939
}
4040

4141
/**

Encoder/JsonEncode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class JsonEncode implements EncoderInterface
2323
private $options;
2424
private $lastError = JSON_ERROR_NONE;
2525

26-
public function __construct($bitmask = 0)
26+
public function __construct(int $bitmask = 0)
2727
{
2828
$this->options = $bitmask;
2929
}

Encoder/XmlEncoder.php

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class XmlEncoder implements EncoderInterface, DecoderInterface, NormalizationAwa
4444
* @param string $rootNodeName
4545
* @param int|null $loadOptions A bit field of LIBXML_* constants
4646
*/
47-
public function __construct($rootNodeName = 'response', $loadOptions = null)
47+
public function __construct(string $rootNodeName = 'response', int $loadOptions = null)
4848
{
4949
$this->rootNodeName = $rootNodeName;
5050
$this->loadOptions = null !== $loadOptions ? $loadOptions : LIBXML_NONET | LIBXML_NOBLANKS;
@@ -180,15 +180,9 @@ public function getRootNodeName()
180180
return $this->rootNodeName;
181181
}
182182

183-
/**
184-
* @param \DOMNode $node
185-
* @param string $val
186-
*
187-
* @return bool
188-
*/
189-
final protected function appendXMLString(\DOMNode $node, $val)
183+
final protected function appendXMLString(\DOMNode $node, string $val): bool
190184
{
191-
if (strlen($val) > 0) {
185+
if ('' !== $val) {
192186
$frag = $this->dom->createDocumentFragment();
193187
$frag->appendXML($val);
194188
$node->appendChild($frag);
@@ -199,27 +193,15 @@ final protected function appendXMLString(\DOMNode $node, $val)
199193
return false;
200194
}
201195

202-
/**
203-
* @param \DOMNode $node
204-
* @param string $val
205-
*
206-
* @return bool
207-
*/
208-
final protected function appendText(\DOMNode $node, $val)
196+
final protected function appendText(\DOMNode $node, string $val): bool
209197
{
210198
$nodeText = $this->dom->createTextNode($val);
211199
$node->appendChild($nodeText);
212200

213201
return true;
214202
}
215203

216-
/**
217-
* @param \DOMNode $node
218-
* @param string $val
219-
*
220-
* @return bool
221-
*/
222-
final protected function appendCData(\DOMNode $node, $val)
204+
final protected function appendCData(\DOMNode $node, string $val): bool
223205
{
224206
$nodeText = $this->dom->createCDATASection($val);
225207
$node->appendChild($nodeText);
@@ -230,10 +212,8 @@ final protected function appendCData(\DOMNode $node, $val)
230212
/**
231213
* @param \DOMNode $node
232214
* @param \DOMDocumentFragment $fragment
233-
*
234-
* @return bool
235215
*/
236-
final protected function appendDocumentFragment(\DOMNode $node, $fragment)
216+
final protected function appendDocumentFragment(\DOMNode $node, $fragment): bool
237217
{
238218
if ($fragment instanceof \DOMDocumentFragment) {
239219
$node->appendChild($fragment);
@@ -246,12 +226,8 @@ final protected function appendDocumentFragment(\DOMNode $node, $fragment)
246226

247227
/**
248228
* Checks the name is a valid xml element name.
249-
*
250-
* @param string $name
251-
*
252-
* @return bool
253229
*/
254-
final protected function isElementNameValid($name)
230+
final protected function isElementNameValid(string $name): bool
255231
{
256232
return $name &&
257233
false === strpos($name, ' ') &&
@@ -294,10 +270,8 @@ private function parseXml(\DOMNode $node, array $context = array())
294270

295271
/**
296272
* Parse the input DOMNode attributes into an array.
297-
*
298-
* @return array
299273
*/
300-
private function parseXmlAttributes(\DOMNode $node, array $context = array())
274+
private function parseXmlAttributes(\DOMNode $node, array $context = array()): array
301275
{
302276
if (!$node->hasAttributes()) {
303277
return array();
@@ -374,13 +348,10 @@ private function parseXmlValue(\DOMNode $node, array $context = array())
374348
*
375349
* @param \DOMNode $parentNode
376350
* @param array|object $data
377-
* @param string|null $xmlRootNodeName
378-
*
379-
* @return bool
380351
*
381352
* @throws NotEncodableValueException
382353
*/
383-
private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
354+
private function buildXml(\DOMNode $parentNode, $data, string $xmlRootNodeName = null): bool
384355
{
385356
$append = true;
386357

@@ -443,12 +414,8 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
443414
*
444415
* @param \DOMNode $parentNode
445416
* @param array|object $data
446-
* @param string $nodeName
447-
* @param string $key
448-
*
449-
* @return bool
450417
*/
451-
private function appendNode(\DOMNode $parentNode, $data, $nodeName, $key = null)
418+
private function appendNode(\DOMNode $parentNode, $data, string $nodeName, string $key = null): bool
452419
{
453420
$node = $this->dom->createElement($nodeName);
454421
if (null !== $key) {
@@ -465,12 +432,8 @@ private function appendNode(\DOMNode $parentNode, $data, $nodeName, $key = null)
465432

466433
/**
467434
* Checks if a value contains any characters which would require CDATA wrapping.
468-
*
469-
* @param string $val
470-
*
471-
* @return bool
472435
*/
473-
private function needsCdataWrapping($val)
436+
private function needsCdataWrapping(string $val): bool
474437
{
475438
return 0 < preg_match('/[<>&]/', $val);
476439
}
@@ -481,11 +444,9 @@ private function needsCdataWrapping($val)
481444
* @param \DOMNode $node
482445
* @param mixed $val
483446
*
484-
* @return bool
485-
*
486447
* @throws NotEncodableValueException
487448
*/
488-
private function selectNodeType(\DOMNode $node, $val)
449+
private function selectNodeType(\DOMNode $node, $val): bool
489450
{
490451
if (is_array($val)) {
491452
return $this->buildXml($node, $val);
@@ -514,10 +475,8 @@ private function selectNodeType(\DOMNode $node, $val)
514475

515476
/**
516477
* Get real XML root node name, taking serializer options into account.
517-
*
518-
* @return string
519478
*/
520-
private function resolveXmlRootName(array $context = array())
479+
private function resolveXmlRootName(array $context = array()): string
521480
{
522481
return isset($context['xml_root_node_name'])
523482
? $context['xml_root_node_name']
@@ -526,12 +485,8 @@ private function resolveXmlRootName(array $context = array())
526485

527486
/**
528487
* Get XML option for type casting attributes Defaults to true.
529-
*
530-
* @param array $context
531-
*
532-
* @return bool
533488
*/
534-
private function resolveXmlTypeCastAttributes(array $context = array())
489+
private function resolveXmlTypeCastAttributes(array $context = array()): bool
535490
{
536491
return isset($context['xml_type_cast_attributes'])
537492
? (bool) $context['xml_type_cast_attributes']
@@ -540,12 +495,8 @@ private function resolveXmlTypeCastAttributes(array $context = array())
540495

541496
/**
542497
* Create a DOM document, taking serializer options into account.
543-
*
544-
* @param array $context Options that the encoder has access to
545-
*
546-
* @return \DOMDocument
547498
*/
548-
private function createDomDocument(array $context)
499+
private function createDomDocument(array $context): \DOMDocument
549500
{
550501
$document = new \DOMDocument();
551502

Mapping/AttributeMetadata.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ class AttributeMetadata implements AttributeMetadataInterface
4141
*/
4242
public $maxDepth;
4343

44-
/**
45-
* Constructs a metadata for the given attribute.
46-
*
47-
* @param string $name
48-
*/
49-
public function __construct($name)
44+
public function __construct(string $name)
5045
{
5146
$this->name = $name;
5247
}

Mapping/ClassMetadata.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ class ClassMetadata implements ClassMetadataInterface
3939
*/
4040
private $reflClass;
4141

42-
/**
43-
* Constructs a metadata for the given class.
44-
*
45-
* @param string $class
46-
*/
47-
public function __construct($class)
42+
public function __construct(string $class)
4843
{
4944
$this->name = $class;
5045
}

Mapping/Factory/ClassMetadataFactory.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class ClassMetadataFactory implements ClassMetadataFactoryInterface
3131
*/
3232
private $loadedClasses;
3333

34-
/**
35-
* @param LoaderInterface $loader
36-
*/
3734
public function __construct(LoaderInterface $loader)
3835
{
3936
$this->loader = $loader;

Mapping/Loader/FileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ abstract class FileLoader implements LoaderInterface
2727
*
2828
* @throws MappingException if the mapping file does not exist or is not readable
2929
*/
30-
public function __construct($file)
30+
public function __construct(string $file)
3131
{
3232
if (!is_file($file)) {
3333
throw new MappingException(sprintf('The mapping file %s does not exist', $file));

NameConverter/CamelCaseToSnakeCaseNameConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
2525
* @param null|array $attributes The list of attributes to rename or null for all attributes
2626
* @param bool $lowerCamelCase Use lowerCamelCase style
2727
*/
28-
public function __construct(array $attributes = null, $lowerCamelCase = true)
28+
public function __construct(array $attributes = null, bool $lowerCamelCase = true)
2929
{
3030
$this->attributes = $attributes;
3131
$this->lowerCamelCase = $lowerCamelCase;

Normalizer/AbstractObjectNormalizer.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,14 @@ abstract protected function setAttributeValue($object, $attribute, $value, $form
225225
/**
226226
* Validates the submitted data and denormalizes it.
227227
*
228-
* @param string $currentClass
229-
* @param string $attribute
230228
* @param mixed $data
231-
* @param string|null $format
232-
* @param array $context
233229
*
234230
* @return mixed
235231
*
236232
* @throws NotNormalizableValueException
237233
* @throws LogicException
238234
*/
239-
private function validateAndDenormalize($currentClass, $attribute, $data, $format, array $context)
235+
private function validateAndDenormalize(string $currentClass, string $attribute, $data, ?string $format, array $context)
240236
{
241237
if (null === $this->propertyTypeExtractor || null === $types = $this->propertyTypeExtractor->getTypes($currentClass, $attribute)) {
242238
return $data;
@@ -298,13 +294,9 @@ private function validateAndDenormalize($currentClass, $attribute, $data, $forma
298294
/**
299295
* Sets an attribute and apply the name converter if necessary.
300296
*
301-
* @param array $data
302-
* @param string $attribute
303297
* @param mixed $attributeValue
304-
*
305-
* @return array
306298
*/
307-
private function updateData(array $data, $attribute, $attributeValue)
299+
private function updateData(array $data, string $attribute, $attributeValue): array
308300
{
309301
if ($this->nameConverter) {
310302
$attribute = $this->nameConverter->normalize($attribute);
@@ -319,13 +311,8 @@ private function updateData(array $data, $attribute, $attributeValue)
319311
* Is the max depth reached for the given attribute?
320312
*
321313
* @param AttributeMetadataInterface[] $attributesMetadata
322-
* @param string $class
323-
* @param string $attribute
324-
* @param array $context
325-
*
326-
* @return bool
327314
*/
328-
private function isMaxDepthReached(array $attributesMetadata, $class, $attribute, array &$context)
315+
private function isMaxDepthReached(array $attributesMetadata, string $class, string $attribute, array &$context): bool
329316
{
330317
if (
331318
!isset($context[static::ENABLE_MAX_DEPTH]) ||
@@ -354,12 +341,9 @@ private function isMaxDepthReached(array $attributesMetadata, $class, $attribute
354341
/**
355342
* Gets the cache key to use.
356343
*
357-
* @param string|null $format
358-
* @param array $context
359-
*
360344
* @return bool|string
361345
*/
362-
private function getCacheKey($format, array $context)
346+
private function getCacheKey(?string $format, array $context)
363347
{
364348
try {
365349
return md5($format.serialize($context));

Normalizer/DateIntervalNormalizer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ class DateIntervalNormalizer implements NormalizerInterface, DenormalizerInterfa
2626

2727
private $format;
2828

29-
/**
30-
* @param string $format
31-
*/
32-
public function __construct($format = 'P%yY%mM%dDT%hH%iM%sS')
29+
public function __construct(string $format = 'P%yY%mM%dDT%hH%iM%sS')
3330
{
3431
$this->format = $format;
3532
}

Normalizer/DateTimeNormalizer.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ class DateTimeNormalizer implements NormalizerInterface, DenormalizerInterface
3434
\DateTime::class => true,
3535
);
3636

37-
/**
38-
* @param string $format
39-
* @param \DateTimeZone|null $timezone
40-
*/
41-
public function __construct($format = \DateTime::RFC3339, \DateTimeZone $timezone = null)
37+
public function __construct(?string $format = \DateTime::RFC3339, \DateTimeZone $timezone = null)
4238
{
4339
$this->format = $format;
4440
$this->timezone = $timezone;

0 commit comments

Comments
 (0)