8000 minor #33190 [Validator] Add more parameter types (derrabus) · symfony/symfony@a9073d1 · GitHub
  • [go: up one dir, main page]

    Skip to content

    Commit a9073d1

    Browse files
    minor #33190 [Validator] Add more parameter types (derrabus)
    This PR was merged into the 5.0-dev branch. Discussion ---------- [Validator] Add more parameter types | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #32179 | License | MIT | Doc PR | N/A Commits ------- a745709 [Validator] Add more parameter types.
    2 parents ec0b0ad + a745709 commit a9073d1

    File tree

    10 files changed

    +22
    -47
    lines changed

    10 files changed

    +22
    -47
    lines changed

    src/Symfony/Component/Validator/ConstraintValidator.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -83,7 +83,7 @@ protected function formatTypeOf($value)
    8383
    *
    8484
    * @return string The string representation of the passed value
    8585
    */
    86-
    protected function formatValue($value, $format = 0)
    86+
    protected function formatValue($value, int $format = 0)
    8787
    {
    8888
    $isDateTime = $value instanceof \DateTimeInterface;
    8989

    @@ -156,7 +156,7 @@ protected function formatValue($value, $format = 0)
    156156
    *
    157157
    * @see formatValue()
    158158
    */
    159-
    protected function formatValues(array $values, $format = 0)
    159+
    protected function formatValues(array $values, int $format = 0)
    160160
    {
    161161
    foreach ($values as $key => $value) {
    162162
    $values[$key] = $this->formatValue($value, $format);

    src/Symfony/Component/Validator/Constraints/FileValidator.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -199,9 +199,9 @@ public function validate($value, Constraint $constraint)
    199199
    }
    200200
    }
    201201

    202-
    private static function moreDecimalsThan($double, $numberOfDecimals)
    202+
    private static function moreDecimalsThan(string $double, int $numberOfDecimals): bool
    203203
    {
    204-
    return \strlen((string) $double) > \strlen(round($double, $numberOfDecimals));
    204+
    return \strlen($double) > \strlen(round($double, $numberOfDecimals));
    205205
    }
    206206

    207207
    /**

    src/Symfony/Component/Validator/Mapping/ClassMetadata.php

    Lines changed: 7 additions & 20 deletions
    Original file line numberDiff line numberDiff line change
    @@ -205,11 +205,9 @@ public function addConstraint(Constraint $constraint)
    205205
    /**
    206206
    * Adds a constraint to the given property.
    207207
    *
    208-
    * @param string $property The name of the property
    209-
    *
    210208
    * @return $this
    211209
    */
    212-
    public function addPropertyConstraint($property, Constraint $constraint)
    210+
    public function addPropertyConstraint(string $property, Constraint $constraint)
    213211
    {
    214212
    if (!isset($this->properties[$property])) {
    215213
    $this->properties[$property] = new PropertyMetadata($this->getClassName(), $property);
    @@ -225,12 +223,11 @@ public function addPropertyConstraint($property, Constraint $constraint)
    225223
    }
    226224

    227225
    /**
    228-
    * @param string $property
    229226
    * @param Constraint[] $constraints
    230227
    *
    231228
    * @return $this
    232229
    */
    233-
    public function addPropertyConstraints($property, array $constraints)
    230+
    public function addPropertyConstraints(string $property, array $constraints)
    234231
    {
    235232
    foreach ($constraints as $constraint) {
    236233
    $this->addPropertyConstraint($property, $constraint);
    @@ -245,11 +242,9 @@ public function addPropertyConstraints($property, array $constraints)
    245242
    * The name of the getter is assumed to be the name of the property with an
    246243
    * uppercased first letter and either the prefix "get" or "is".
    247244
    *
    248-
    * @param string $property The name of the property
    249-
    *
    250245
    * @return $this
    251246
    */
    252-
    public function addGetterConstraint($property, Constraint $constraint)
    247+
    public function addGetterConstraint(string $property, Constraint $constraint)
    253248
    {
    254249
    if (!isset($this->getters[$property])) {
    255250
    $this->getters[$property] = new GetterMetadata($this->getClassName(), $property);
    @@ -267,12 +262,9 @@ public function addGetterConstraint($property, Constraint $constraint)
    267262
    /**
    268263
    * Adds a constraint to the getter of the given property.
    269264
    *
    270-
    * @param string $property The name of the property
    271-
    * @param string $method The name of the getter method
    272-
    *
    273265
    * @return $this
    274266
    */
    275-
    public function addGetterMethodConstraint($property, $method, Constraint $constraint)
    267+
    public function addGetterMethodConstraint(string $property, string $method, Constraint $constraint)
    276268
    {
    277269
    if (!isset($this->getters[$property])) {
    278270
    $this->getters[$property] = new GetterMetadata($this->getClassName(), $property, $method);
    @@ -288,12 +280,11 @@ public function addGetterMethodConstraint($property, $method, Constraint $constr
    288280
    }
    289281

    290282
    /**
    291-
    * @param string $property
    292 F438 283
    * @param Constraint[] $constraints
    293284
    *
    294285
    * @return $this
    295286
    */
    296-
    public function addGetterConstraints($property, array $constraints)
    287+
    public function addGetterConstraints(string $property, array $constraints)
    297288
    {
    298289
    foreach ($constraints as $constraint) {
    299290
    $this->addGetterConstraint($property, $constraint);
    @@ -303,13 +294,11 @@ public function addGetterConstraints($property, array $constraints)
    303294
    }
    304295

    305296
    /**
    306-
    * @param string $property
    307-
    * @param string $method
    308297
    * @param Constraint[] $constraints
    309298
    *
    310299
    * @return $this
    311300
    */
    312-
    public function addGetterMethodConstraints($property, $method, array $constraints)
    301+
    public function addGetterMethodConstraints(string $property, string $method, array $constraints)
    313302
    {
    314303
    foreach ($constraints as $constraint) {
    315304
    $this->addGetterMethodConstraint($property, $method, $constraint);
    @@ -451,11 +440,9 @@ public function getReflectionClass()
    451440
    /**
    452441
    * Sets whether a group sequence provider should be used.
    453442
    *
    454-
    * @param bool $active
    455-
    *
    456443
    * @throws GroupDefinitionException
    457444
    */
    458-
    public function setGroupSequenceProvider($active)
    445+
    public function setGroupSequenceProvider(bool $active)
    459446
    {
    460447
    if ($this->hasGroupSequence()) {
    461448
    throw new GroupDefinitionException('Defining a group sequence provider is not allowed with a static group sequence');

    src/Symfony/Component/Validator/Mapping/Loader/AbstractLoader.php

    Lines changed: 2 additions & 5 deletions
    Original file line numberDiff line numberDiff line change
    @@ -43,11 +43,8 @@ abstract class AbstractLoader implements LoaderInterface
    4343
    * $this->addNamespaceAlias('mynamespace', '\\Acme\\Package\\Constraints\\');
    4444
    *
    4545
    * $constraint = $this->newConstraint('mynamespace:NotNull');
    46-
    *
    47-
    * @param string $alias The alias
    48-
    * @param string $namespace The PHP namespace
    4946
    */
    50-
    protected function addNamespaceAlias($alias, $namespace)
    47+
    protected function addNamespaceAlias(string $alias, string $namespace)
    5148
    {
    5249
    $this->namespaces[$alias] = $namespace;
    5350
    }
    @@ -67,7 +64,7 @@ protected function addNamespaceAlias($alias, $namespace)
    6764
    *
    6865
    * @throws MappingException If the namespace prefix is undefined
    6966
    */
    70-
    protected function newConstraint($name, $options = null)
    67+
    protected function newConstraint(string $name, $options = null)
    7168
    {
    7269
    if (false !== strpos($name, '\\') && class_exists($name)) {
    7370
    $className = (string) $name;

    src/Symfony/Component/Validator/Mapping/Loader/FilesLoader.php

    Lines changed: 2 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -35,11 +35,9 @@ public function __construct(array $paths)
    3535
    /**
    3636
    * Returns an array of file loaders for the given file paths.
    3737
    *
    38-
    * @param array $paths An array of file paths
    39-
    *
    4038
    * @return LoaderInterface[] The metadata loaders
    4139
    */
    42-
    protected function getFileLoaders($paths)
    40+
    protected function getFileLoaders(array $paths)
    4341
    {
    4442
    $loaders = [];
    4543

    @@ -53,9 +51,7 @@ protected function getFileLoaders($paths)
    5351
    /**
    5452
    * Creates a loader for the given file path.
    5553
    *
    56-
    * @param string $path The file path
    57-
    *
    5854
    * @return LoaderInterface The created loader
    5955
    */
    60-
    abstract protected function getFileLoaderInstance($path);
    56+
    abstract protected function getFileLoaderInstance(string $path);
    6157
    }

    src/Symfony/Component/Validator/Mapping/Loader/XmlFileLoader.php

    Lines changed: 1 addition & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -167,13 +167,11 @@ protected function parseOptions(\SimpleXMLElement $nodes)
    167167
    /**
    168168
    * Loads the XML class descriptions from the given file.
    169169
    *
    170-
    * @param string $path The path of the XML file
    171-
    *
    172170
    * @return \SimpleXMLElement The class descriptions
    173171
    *
    174172
    * @throws MappingException If the file could not be loaded
    175173
    */
    176-
    protected function parseFile($path)
    174+
    protected function parseFile(string $path)
    177175
    {
    178176
    try {
    179177
    $dom = XmlUtils::loadFile($path, __DIR__.'/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd');

    src/Symfony/Component/Validator/Mapping/Loader/XmlFilesLoader.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -24,7 +24,7 @@ class XmlFilesLoader extends FilesLoader
    2424
    /**
    2525
    * {@inheritdoc}
    2626
    */
    27-
    public function getFileLoaderInstance($file)
    27+
    public function getFileLoaderInstance(string $file)
    2828
    {
    2929
    return new XmlFileLoader($file);
    3030
    }

    src/Symfony/Component/Validator/Mapping/Loader/YamlFilesLoader.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -24,7 +24,7 @@ class YamlFilesLoader extends FilesLoader
    2424
    /**
    2525
    * {@inheritdoc}
    2626
    */
    27-
    public function getFileLoaderInstance($file)
    27+
    public function getFileLoaderInstance(string $file)
    2828
    {
    2929
    return new YamlFileLoader($file);
    3030
    }

    src/Symfony/Component/Validator/Tests/Fixtures/FilesLoader.php

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -25,7 +25,7 @@ public function __construct(array $paths, LoaderInterface $loader)
    2525
    parent::__construct($paths);
    2626
    }
    2727

    28-
    protected function getFileLoaderInstance($file)
    28+
    protected function getFileLoaderInstance(string $file)
    2929
    {
    3030
    ++$this->timesCalled;
    3131

    src/Symfony/Component/Validator/Util/PropertyPath.php

    Lines changed: 3 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -29,19 +29,16 @@ class PropertyPath
    2929
    * returned. Otherwise, the concatenation of the two paths is returned,
    3030
    * separated by a dot (".").
    3131
    *
    32-
    * @param string $basePath The base path
    33-
    * @param string $subPath The path to append
    34-
    *
    3532
    * @return string The concatenation of the two property paths
    3633
    */
    37-
    public static function append($basePath, $subPath)
    34+
    public static function append(string $basePath, string $subPath)
    3835
    {
    39-
    if ('' !== (string) $subPath) {
    36+
    if ('' !== $subPath) {
    4037
    if ('[' === $subPath[0]) {
    4138
    return $basePath.$subPath;
    4239
    }
    4340

    44-
    return '' !== (string) $basePath ? $basePath.'.'.$subPath : $subPath;
    41+
    return '' !== $basePath ? $basePath.'.'.$subPath : $subPath;
    4542
    }
    4643

    4744
    return $basePath;

    0 commit comments

    Comments
     (0)
    0