GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#101)
by joseph
18:59
created

EntityDebugDumper   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 59.26%

Importance

Changes 0
Metric Value
wmc 11
eloc 27
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 16
cts 27
cp 0.5926

1 Method

Rating   Name   Duplication   Size   Complexity  
B dump() 0 37 11
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing;
4
5
use Doctrine\Common\Util\Debug;
6
use Doctrine\ORM\EntityManagerInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
8
9
class EntityDebugDumper
10
{
11
    /**
12
     * @param EntityInterface        $entity
13
     * @param EntityManagerInterface $entityManager
14
     * @param int                    $level
15
     *
16
     * @return string
17
     * @SuppressWarnings(PHPMD.StaticAccess)
18
     * @SuppressWarnings(PHPMD.ElseExpression)
19
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
20
     */
21 1
    public function dump(EntityInterface $entity, ?EntityManagerInterface $entityManager = null, int $level = 0): string
22
    {
23 1
        $dump          = [];
24 1
        $fieldMappings = [];
25 1
        if (null !== $entityManager) {
26
            $metaData      = $entityManager->getClassMetadata(\get_class($entity));
27
            $fieldMappings = $metaData->fieldMappings;
0 ignored issues
show
Bug introduced by
Accessing fieldMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
28
        }
29 1
        foreach ($entity->getGetters() as $getter) {
30 1
            $got       = $entity->$getter();
31 1
            $fieldName = \lcfirst(\preg_replace('%^(get|is)%', '', $getter));
32 1
            if (\is_numeric($got)
33 1
                || (isset($fieldMappings[$fieldName]) && 'decimal' === $fieldMappings[$fieldName]['type'])
34
            ) {
35 1
                $dump[$getter] = (float)$got;
36 1
                continue;
37
            }
38 1
            if ($got instanceof \Doctrine\ORM\Proxy\Proxy) {
39
                $dump[$getter] = 'Proxy class ';
40
                continue;
41
            }
42 1
            if (method_exists($got, '__toString')) {
43
                $dump[$getter] = $got->__toString();
44
                continue;
45
            }
46 1
            if (\is_object($got) && $got instanceof EntityInterface) {
47
                if ($level === 2) {
48
                    $dump[$getter] = '(max depth of 2 reached)';
49
                    continue;
50
                }
51
                $dump[$getter] = $this->dump($got, $entityManager, ++$level);
52
                continue;
53
            }
54 1
            $dump[$getter] = Debug::export($got, 2);
55
        }
56
57 1
        return (string)print_r($dump, true);
58
    }
59
}
60