FakeMetadataFactory::getMetadataFor()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
rs 9.2
cc 4
eloc 8
nc 6
nop 1
1
<?php
2
3
namespace N98\Util\Validator;
4
5
use Symfony\Component\Validator\MetadataFactoryInterface;
6
use Symfony\Component\Validator\Exception\NoSuchMetadataException;
7
use Symfony\Component\Validator\Mapping\ClassMetadata;
8
9
class FakeMetadataFactory implements MetadataFactoryInterface
0 ignored issues
show
Deprecated Code introduced by
The interface Symfony\Component\Valida...etadataFactoryInterface has been deprecated with message: since version 2.5, to be removed in 3.0. Use {@link Mapping\Factory\MetadataFactoryInterface} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
10
{
11
    protected $metadatas = array();
12
13
    public function getMetadataFor($class)
14
    {
15
        if (is_object($class)) {
16
            $class = get_class($class);
17
        }
18
19
        if (!is_string($class)) {
20
            throw new NoSuchMetadataException('No metadata for type ' . gettype($class));
21
        }
22
23
        if (!isset($this->metadatas[$class])) {
24
            throw new NoSuchMetadataException('No metadata for "' . $class . '"');
25
        }
26
27
        return $this->metadatas[$class];
28
    }
29
30
    public function hasMetadataFor($class)
31
    {
32
        if (is_object($class)) {
33
            $class = get_class($class);
34
        }
35
36
        if (!is_string($class)) {
37
            return false;
38
        }
39
40
        return isset($this->metadatas[$class]);
41
    }
42
43
    public function addMetadata(ClassMetadata $metadata)
44
    {
45
        $this->metadatas[$metadata->getClassName()] = $metadata;
46
    }
47
}
48