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 (#197)
by joseph
21:01
created

EntityDebugDumper   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 46.3%

Importance

Changes 0
Metric Value
eloc 41
dl 0
loc 68
ccs 25
cts 54
cp 0.463
rs 10
c 0
b 0
f 0
wmc 14

1 Method

Rating   Name   Duplication   Size   Complexity  
C dump() 0 55 14
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Testing;
4
5
use Doctrine\Common\Collections\Collection;
6
use Doctrine\Common\Util\Debug;
7
use Doctrine\ORM\EntityManagerInterface;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
9
10
/**
11
 * @SuppressWarnings(PHPMD.NPathComplexity)
12
 */
13
class EntityDebugDumper
14
{
15
    /**
16
     * @param EntityInterface        $entity
17
     * @param EntityManagerInterface $entityManager
18
     * @param int                    $level
19
     *
20
     * @return string
21
     * @throws \ReflectionException
22
     * @SuppressWarnings(PHPMD.StaticAccess)
23
     * @SuppressWarnings(PHPMD.ElseExpression)
24
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
25
     */
26 1
    public function dump(EntityInterface $entity, ?EntityManagerInterface $entityManager = null, int $level = 0): string
27
    {
28 1
        $dump          = [];
29 1
        $fieldMappings = [];
30 1
        if (null !== $entityManager) {
31
            $metaData      = $entityManager->getClassMetadata(\get_class($entity));
32
            $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...
33
        }
34 1
        foreach ($entity::getDoctrineStaticMeta()->getGetters() as $getter) {
35
            try {
36 1
                $got = $entity->$getter();
37
            } catch (\TypeError $e) {
38
                $got = '( *TypeError*: ' . $e->getMessage() . ' )';
39
            }
40 1
            $fieldName = \lcfirst(\preg_replace('%^(get|is)%', '', $getter));
41 1
            if (\is_numeric($got)
42 1
                || (isset($fieldMappings[$fieldName]) && 'decimal' === $fieldMappings[$fieldName]['type'])
43
            ) {
44 1
                $dump[$getter] = (float)$got;
45 1
                continue;
46
            }
47 1
            if ($got instanceof \Doctrine\ORM\Proxy\Proxy) {
48
                $dump[$getter] = 'Proxy class ';
49
                continue;
50
            }
51 1
            if ($got instanceof EntityInterface) {
52
                if ($level === 2) {
53
                    $dump[$getter] = '(max depth of 2 reached)';
54
                    continue;
55
                }
56
                $dump[$getter] = $this->dump($got, $entityManager, ++$level);
57
                continue;
58
            }
59 1
            if ($got instanceof Collection) {
60 1
                $dump[$getter] = [];
61 1
                foreach ($got as $item) {
62 1
                    if ($item instanceof EntityInterface) {
63 1
                        $dump[$getter][] = get_class($item) . ': ' . $item->getId();
0 ignored issues
show
Bug introduced by
Are you sure $item->getId() of type Ramsey\Uuid\UuidInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

63
                        $dump[$getter][] = get_class($item) . ': ' . /** @scrutinizer ignore-type */ $item->getId();
Loading history...
64 1
                        continue;
65
                    }
66
                    throw new \RuntimeException('Got unexpected object ' .
67
                                                get_class($got) .
68
                                                ' in collection from ' .
69
                                                $getter);
70
                }
71 1
                continue;
72
            }
73 1
            if (method_exists($got, '__toString')) {
74 1
                $dump[$getter] = $got->__toString();
75 1
                continue;
76
            }
77 1
            $dump[$getter] = Debug::export($got, 2);
78
        }
79
80 1
        return (string)print_r($dump, true);
81
    }
82
}
83