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
Push — master ( 0b4676...ecfcbd )
by joseph
17s queued 14s
created

JsonSerializableTrait::jsonSerialize()   B

Complexity

Conditions 9
Paths 20

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 9
eloc 22
c 2
b 0
f 1
nc 20
nop 0
dl 0
loc 34
ccs 0
cts 32
cp 0
crap 90
rs 8.0555
1
<?php declare(strict_types=1);
2
3
4
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Traits;
5
6
7
use Doctrine\Common\Collections\Collection;
8
use Doctrine\ORM\Proxy\Proxy;
9
use EdmondsCommerce\DoctrineStaticMeta\DoctrineStaticMeta;
10
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
11
use Ramsey\Uuid\UuidInterface;
12
13
trait JsonSerializableTrait
14
{
15
    public function jsonSerialize(): array
16
    {
17
        $dsm         = static::getDoctrineStaticMeta();
18
        $toSerialize = [];
19
        $getters     = $dsm->getGetters();
20
        foreach ($getters as $getter) {
21
            /** @var mixed $got */
22
            $got = $this->$getter();
23
            if ($got instanceof EntityInterface) {
24
                continue;
25
            }
26
            if ($got instanceof Collection) {
27
                continue;
28
            }
29
            if ($got instanceof Proxy) {
30
                continue;
31
            }
32
            if ($got instanceof UuidInterface) {
33
                $got = $got->toString();
34
            }
35
            if ($got instanceof \DateTimeImmutable) {
36
                $got = $got->format('Y-m-d H:i:s');
37
            }
38
            if (method_exists($got, '__toString')) {
39
                $got = (string)$got;
40
            }
41
            if (false === is_scalar($got)) {
42
                continue;
43
            }
44
            $property               = $dsm->getPropertyNameFromGetterName($getter);
45
            $toSerialize[$property] = $got;
46
        }
47
48
        return $toSerialize;
49
    }
50
51
    abstract public static function getDoctrineStaticMeta(): DoctrineStaticMeta;
52
53
54
}