Factory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 40
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setEventDispatcher() 0 4 1
A createInstanceFor() 0 10 3
1
<?php
2
/**
3
 * custom factory to inject the event dispatcher into our constraints
4
 */
5
6
namespace Graviton\JsonSchemaBundle\Validator\Constraint;
7
8
use JsonSchema\Constraints\BaseConstraint;
9
use JsonSchema\Constraints\Factory as BaseFactory;
10
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
11
12
/**
13
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license  https://opensource.org/licenses/MIT MIT License
15
 * @link     http://swisscom.ch
16
 */
17
class Factory extends BaseFactory
18
{
19
20
    /**
21
     * @var EventDispatcherInterface
22
     */
23
    private $dispatcher = null;
24
25
    /**
26
     * set EventDispatcher
27
     *
28
     * @param EventDispatcherInterface $dispatcher dispatcher
29
     *
30
     * @return void
31
     */
32
    public function setEventDispatcher($dispatcher)
33
    {
34
        $this->dispatcher = $dispatcher;
35
    }
36
37
    /**
38
     * Create a constraint instance for the given constraint name.
39
     *
40
     * @param string $constraintName constraint name
41
     *
42
     * @throws InvalidArgumentException if is not possible create the constraint instance.
43
     *
44
     * @return BaseConstraint instance
45
     */
46
    public function createInstanceFor($constraintName)
47
    {
48
        $instance = parent::createInstanceFor($constraintName);
49
50
        if (!is_null($this->dispatcher) && is_callable([$instance, 'setEventDispatcher'])) {
51
            $instance->setEventDispatcher($this->dispatcher);
52
        }
53
54
        return $instance;
55
    }
56
}
57