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.

JsonSerializableTrait   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 10
eloc 23
c 3
b 1
f 1
dl 0
loc 44
ccs 0
cts 33
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B jsonSerialize() 0 34 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Traits;
6
7
use DateTimeImmutable;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Proxy\Proxy;
10
use EdmondsCommerce\DoctrineStaticMeta\DoctrineStaticMeta;
11
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
12
use Ramsey\Uuid\UuidInterface;
13
use ReflectionException;
14
15
trait JsonSerializableTrait
16
{
17
    /**
18
     * @return array
19
     * @throws ReflectionException
20
     * @SuppressWarnings(PHPMD.CyclomaticComplexity)
21
     */
22
    public function jsonSerialize(): array
23
    {
24
        $dsm         = static::getDoctrineStaticMeta();
25
        $toSerialize = [];
26
        $getters     = $dsm->getGetters();
27
        foreach ($getters as $getter) {
28
            /** @var mixed $got */
29
            $got = $this->$getter();
30
            if ($got instanceof EntityInterface) {
31
                continue;
32
            }
33
            if ($got instanceof Collection) {
34
                continue;
35
            }
36
            if ($got instanceof Proxy) {
37
                continue;
38
            }
39
            if ($got instanceof UuidInterface) {
40
                $got = $got->toString();
41
            }
42
            if ($got instanceof DateTimeImmutable) {
43
                $got = $got->format('Y-m-d H:i:s');
44
            }
45
            if (method_exists($got, '__toString')) {
46
                $got = (string)$got;
47
            }
48
            if (null !== $got && false === is_scalar($got)) {
49
                continue;
50
            }
51
            $property               = $dsm->getPropertyNameFromGetterName($getter);
52
            $toSerialize[$property] = $got;
53
        }
54
55
        return $toSerialize;
56
    }
57
58
    abstract public static function getDoctrineStaticMeta(): DoctrineStaticMeta;
59
}
60