Failed Conditions
Pull Request — master (#6900)
by
unknown
10:39
created

GH6884Person   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A onPostUpdate() 0 5 1
1
<?php
0 ignored issues
show
introduced by
Missing declare(strict_types = 1).
Loading history...
2
3
namespace Doctrine\Tests\ORM\Functional\Ticket;
4
5
use Doctrine\ORM\Annotation as ORM;
6
use Doctrine\ORM\Event\LifecycleEventArgs;
7
use Doctrine\ORM\Events;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
use stdClass;
10
11
/**
12
 * @group 6884
13
 */
14
final class GH6884Test extends OrmFunctionalTestCase
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    protected function setUp(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
20
    {
21
        parent::setUp();
22
23
        $this->schemaTool->createSchema([$this->em->getClassMetadata(GH6884Person::class)]);
24
25
        $listener = $this->createPartialMock(stdClass::class, ['preUpdate']);
26
27
        $listener->expects($this->exactly(3))->method('preUpdate');
28
29
        $this->em->getEventManager()->addEventListener([Events::preUpdate], $listener);
30
31
        $this->em->getClassMetadata(GH6884Person::class)
32
                  ->addEntityListener(Events::postUpdate, GH6884Person::class, 'onPostUpdate');
0 ignored issues
show
Bug introduced by
The method addEntityListener() does not exist on Doctrine\Common\Persistence\Mapping\ClassMetadata. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
                  ->/** @scrutinizer ignore-call */ addEntityListener(Events::postUpdate, GH6884Person::class, 'onPostUpdate');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
33
    }
34
35
    public function testIssue(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
36
    {
37
        $person  = new GH6884Person();
38
        $person2 = new GH6884Person();
39
40
        $this->em->persist($person);
41
        $this->em->persist($person2);
42
        $this->em->flush();
43
44
        $person->isAlive  = true;
45
        $person2->isAlive = true;
46
47
        $this->em->flush();
48
    }
49
}
50
51
/**
52
 * @ORM\Entity()
53
 */
54
class GH6884Person
55
{
56
    /**
57
     * @ORM\Id()
58
     * @ORM\Column(type="integer")
59
     * @ORM\GeneratedValue()
60
     */
61
    public $id;
62
63
    /** @ORM\Column(type="boolean", nullable=false) */
64
    public $isAlive = false;
65
66
    /** @var bool */
67
    public $nonOrmProperty = false;
68
69
    public function onPostUpdate(GH6884Person $person, LifecycleEventArgs $eventArgs): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
70
    {
71
        $person->nonOrmProperty = true;
72
73
        $eventArgs->getEntityManager()->flush();
74
    }
75
}
76