Failed Conditions
Pull Request — master (#6392)
by Alessandro
18:37
created

HierarchyDiscriminatorResolver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 22
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A resolveDiscriminatorsForClass() 0 19 3
1
<?php
2
3
namespace Doctrine\ORM\Utility;
4
5
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
6
use Doctrine\ORM\EntityManagerInterface;
7
8
/**
9
 * Class HierarchyDiscriminatorResolver
10
 * @package Doctrine\ORM\Utility
11
 * @internal This class exists only to avoid code duplication, do not reuse it externally
12
 */
13
class HierarchyDiscriminatorResolver
14
{
15 11
    public static function resolveDiscriminatorsForClass(
16
        ClassMetadata $rootClassMetadata,
17
        EntityManagerInterface $entityManager
18
    ) {
19 11
        $hierarchyClasses = $rootClassMetadata->subClasses;
0 ignored issues
show
Bug introduced by
Accessing subClasses on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
20 11
        $hierarchyClasses[] = $rootClassMetadata->name;
0 ignored issues
show
Bug introduced by
Accessing name on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
21
22 11
        $discriminators = [];
23 11
        foreach ($hierarchyClasses as $class) {
24 11
            $currentMetadata = $entityManager->getClassMetadata($class);
25 11
            $currentDiscriminator = $currentMetadata->discriminatorValue;
0 ignored issues
show
Bug introduced by
Accessing discriminatorValue on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
26
27 11
            if (null !== $currentDiscriminator) {
28 11
                $discriminators[$currentDiscriminator] = null;
29
            }
30
        }
31
32 11
        return $discriminators;
33
    }
34
}
35