Failed Conditions
Pull Request — master (#7143)
by Mike
07:18
created

MetadataCollection::fromClassMetadatas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Mapping;
6
7
8
use Doctrine\ORM\Utility\StaticClassNameConverter;
9
10
class MetadataCollection
11
{
0 ignored issues
show
introduced by
There must be exactly 0 empty lines after class opening brace.
Loading history...
12
13
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\ORM\Mapping\MetadataCollection::$metadata with single line content, use one-line comment instead.
Loading history...
14
     * @var ClassMetadata[]
15
     */
16
    private $metadata;
17
18
    private function __construct(array $metadata)
0 ignored issues
show
introduced by
Method \Doctrine\ORM\Mapping\MetadataCollection::__construct() does not have @param annotation for its traversable parameter $metadata.
Loading history...
19
    {
20
        $metadataByClassName = array_combine(
0 ignored issues
show
introduced by
Function array_combine() should not be referenced via a fallback global name, but via a use statement.
Loading history...
21
            array_map(function (ClassMetadata $metadata) { return $metadata->getClassName(); }, $metadata),
0 ignored issues
show
introduced by
Function array_map() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Opening brace must be the last content on the line
Loading history...
22
            $metadata
23
        );
24
        $this->metadata = $metadataByClassName;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
25
    }
26
27
    public function get(string $name) : ClassMetadata
28
    {
29
        $name = StaticClassNameConverter::getRealClass($name);
30
        if(!isset($this->metadata[$name])){
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after IF keyword; 0 found
Loading history...
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
31
            throw new \Exception('No metadata found for ' . $name);
32
        }
33
        return $this->metadata[$name];
34
    }
35
36
    public function has(string $name) : bool
37
    {
38
        $name = StaticClassNameConverter::getRealClass($name);
39
        return isset($this->metadata[$name]);
40
    }
41
42
    public static function fromClassMetadatas(ClassMetadata $firstClass, ClassMetadata ...$otherClasses)
43
    {
44
        $otherClasses[] = $firstClass;
45
        return new self($otherClasses);
46
    }
47
}
48