Completed
Push — feature/other-validation ( 1442c4...18a759 )
by Narcotic
64:54
created

DummyBuilderA::buildConstraint()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 11
rs 9.4285
cc 3
eloc 6
nc 2
nop 4
1
<?php
2
/**
3
 * a dummy constraint builder
4
 */
5
6
namespace Graviton\SchemaBundle\Tests\ConstraintBuilder\Builder;
7
8
use Graviton\RestBundle\Model\DocumentModel;
9
use Graviton\SchemaBundle\Constraint\Builder\ConstraintBuilderInterface;
10
use Graviton\SchemaBundle\Document\Schema;
11
12
/**
13
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link     http://swisscom.ch
16
 */
17
class DummyBuilderA implements ConstraintBuilderInterface
18
{
19
20
    /**
21
     * @var array
22
     */
23
    public $options;
24
25
    /**
26
     * if this builder supports a given constraint
27
     *
28
     * @param string $type    Field type
29
     * @param array  $options Options
30
     *
31
     * @return bool
32
     */
33
    public function supportsConstraint($type, array $options = [])
34
    {
35
        return ($type === 'DummyA');
36
    }
37
38
    /**
39
     * Adds constraints to the property
40
     *
41
     * @param string        $fieldName field name
42
     * @param Schema        $property  property
43
     * @param DocumentModel $model     parent model
44
     * @param array         $options   the constraint options
45
     *
46
     * @throws \Exception
47
     *
48
     * @return Schema the modified property
49
     */
50
    public function buildConstraint($fieldName, Schema $property, DocumentModel $model, array $options)
51
    {
52
        $this->options = $options;
53
54
        if (!isset($options[0]) || !$options[0] instanceof \stdClass) {
55
            throw new \Exception('Not good params');
56
        }
57
58
        $property->setTitle('THIS WAS SET BY DUMMY-A');
59
        return $property;
60
    }
61
}
62