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.
Passed
Push — master ( e9c651...e1baf6 )
by Christian
02:19
created

DeletableListener   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A loadClassMetadata() 0 19 5
A getSubscribedEvents() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\Doctrine\EventListener\ORM;
13
14
use Core23\Doctrine\Model\Traits\DeleteableTrait;
15
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
16
use Doctrine\ORM\Events;
17
use Doctrine\ORM\Mapping\ClassMetadata;
18
use Doctrine\ORM\Mapping\MappingException;
19
20
final class DeletableListener extends AbstractListener
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function getSubscribedEvents()
26
    {
27
        return [
28
            Events::loadClassMetadata,
29
        ];
30
    }
31
32
    /**
33
     * @param LoadClassMetadataEventArgs $eventArgs
34
     *
35
     * @throws MappingException
36
     */
37
    public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs): void
38
    {
39
        $meta = $eventArgs->getClassMetadata();
40
41
        if (!$meta instanceof ClassMetadata) {
0 ignored issues
show
introduced by
$meta is always a sub-type of Doctrine\ORM\Mapping\ClassMetadata.
Loading history...
42
            throw new \LogicException(sprintf('Class metadata was no ORM but %s', \get_class($meta)));
43
        }
44
45
        $reflClass = $meta->getReflectionClass();
46
47
        if (null === $reflClass || !$this->containsTrait($reflClass, DeleteableTrait::class)) {
48
            return;
49
        }
50
51
        if (!$meta->hasField('deletedAt')) {
52
            $meta->mapField([
53
                'type'      => 'datetime',
54
                'fieldName' => 'deletedAt',
55
                'nullable'  => true,
56
            ]);
57
        }
58
    }
59
}
60