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   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B jsonSerialize() 0 34 9
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
}