Completed
Pull Request — 1.4 (#683)
by Paweł
08:30
created

TimestampableListener   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
wmc 4
lcom 0
cbo 2
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A updateField() 0 6 2
A isTimestampableCanceled() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content Bundle.
7
 *
8
 * Copyright 2018 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2018 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\ContentBundle\EventListener;
18
19
use SWP\Bundle\ContentBundle\Doctrine\TimestampableCancelInterface;
20
use Gedmo\Timestampable\TimestampableListener as GedmoTimestampableListener;
21
22
class TimestampableListener extends GedmoTimestampableListener
23
{
24
    protected function updateField($object, $eventAdapter, $meta, $field)
25
    {
26
        if (!$this->isTimestampableCanceled($object)) {
27
            parent::updateField($object, $eventAdapter, $meta, $field);
28
        }
29
    }
30
31
    private function isTimestampableCanceled($object): bool
32
    {
33
        if (!$object instanceof TimestampableCancelInterface) {
34
            return false;
35
        }
36
37
        return $object->isTimestampableCanceled();
38
    }
39
}
40