Completed
Push — master ( 799d88...dee4c0 )
by Antoine
21s queued 13s
created

PropertySchemaRegexRestriction::supports()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 1
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace ApiPlatform\Core\Bridge\Symfony\Validator\Metadata\Property\Restriction;
15
16
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
17
use Symfony\Component\Validator\Constraint;
18
use Symfony\Component\Validator\Constraints\Regex;
19
20
/**
21
 * Class PropertySchemaRegexRestriction.
22
 *
23
 * @author Andrii Penchuk [email protected]
24
 */
25
class PropertySchemaRegexRestriction implements PropertySchemaRestrictionMetadataInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function create(Constraint $constraint, PropertyMetadata $propertyMetadata): array
31
    {
32
        return isset($constraint->pattern) ? ['pattern' => $constraint->pattern] : [];
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function supports(Constraint $constraint, PropertyMetadata $propertyMetadata): bool
39
    {
40
        return $constraint instanceof Regex && $constraint->match;
41
    }
42
}
43