Failed Conditions
Pull Request — master (#7143)
by Mike
09:42
created

MetadataCollection::fromClassMetadatas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
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
class MetadataCollection
9
{
0 ignored issues
show
introduced by
There must be exactly 0 empty lines after class opening brace.
Loading history...
10
11
    /**
0 ignored issues
show
introduced by
Found multi-line comment for property \Doctrine\ORM\Mapping\MetadataCollection::$classMetadatas with single line content, use one-line comment instead.
Loading history...
12
     * @var ClassMetadata[]
13
     */
14
    private $classMetadatas;
15
16
    private function __construct(array $classMetadatas)
0 ignored issues
show
introduced by
Method \Doctrine\ORM\Mapping\MetadataCollection::__construct() does not have @param annotation for its traversable parameter $classMetadatas.
Loading history...
17
    {
18
        $metadataByClassName = array_reduce (
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
introduced by
Function array_reduce() should not be referenced via a fallback global name, but via a use statement.
Loading history...
Coding Style introduced by
Space before opening parenthesis of function call prohibited
Loading history...
19
            $classMetadatas,
20
            function ( $carry, ClassMetadata $classMetadata )
0 ignored issues
show
Coding Style introduced by
Expected 0 spaces between opening bracket and argument "$carry"; 1 found
Loading history...
Coding Style introduced by
Expected 0 spaces between argument "$classMetadata" and closing bracket; 1 found
Loading history...
21
            {
0 ignored issues
show
Coding Style introduced by
Opening brace should be on the same line as the declaration
Loading history...
22
                $className = $classMetadata->getClassName();
23
                $carry[$className] = $classMetadata;
24
                return $carry;
25
            } ,
0 ignored issues
show
Coding Style introduced by
Space found before comma in function call
Loading history...
26
            []
27
        ) ;
28
        $this->classMetadatas = $metadataByClassName;
29
    }
30
31
    public function get($name)
32
    {
33
        if(!isset($this->classMetadatas[$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...
34
            throw new \Exception('No metadata found for ' . $name);
35
        }
36
        return $this->classMetadatas[$name];
37
    }
38
39
    public static function fromClassMetadatas(array $classMetadatas)
0 ignored issues
show
introduced by
Method \Doctrine\ORM\Mapping\MetadataCollection::fromClassMetadatas() does not have @param annotation for its traversable parameter $classMetadatas.
Loading history...
40
    {
41
        return new self($classMetadatas);
42
    }
43
}
44