Completed
Push — feature/EVO-5751-text-index-mo... ( 0ab3ac...8fecb1 )
by
unknown
62:16 queued 57:01
created

UrlConstraintBuilder::supportsConstraint()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
ccs 0
cts 2
cp 0
cc 1
eloc 2
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * UrlConstraintBuilder class file
4
 */
5
6
namespace Graviton\SchemaBundle\Constraint\Builder;
7
8
use Graviton\RestBundle\Model\DocumentModel;
9
use Graviton\SchemaBundle\Document\Schema;
10
11
/**
12
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
13
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
14
 * @link     http://swisscom.ch
15
 */
16
class UrlConstraintBuilder implements ConstraintBuilderInterface
17
{
18
    /**
19
     * if this builder supports a given constraint
20
     *
21
     * @param string $type    Field type
22
     * @param array  $options Options
23
     *
24
     * @return bool
25
     */
26
    public function supportsConstraint($type, array $options = [])
27
    {
28
        return ($type === 'Url');
29
    }
30
31
    /**
32
     * Adds constraints to the property
33
     *
34
     * @param string        $fieldName field name
35
     * @param Schema        $property  property
36
     * @param DocumentModel $model     parent model
37
     * @param array         $options   the constraint options
38
     *
39
     * @return Schema the modified property
40
     */
41
    public function buildConstraint($fieldName, Schema $property, DocumentModel $model, array $options)
42
    {
43
        $property->setFormat('uri');
44
        return $property;
45
    }
46
}
47