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::dump()   B

Complexity

Conditions 11
Paths 14

Size

Total Lines 37
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 19.1817

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 37
rs 7.3166
c 0
b 0
f 0
ccs 16
cts 27
cp 0.5926
cc 11
nc 14
nop 3
crap 19.1817

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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