Completed
Pull Request — master (#7405)
by Michael
68:49 queued 63:08
created

GH7366Entity::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional\Ticket;
6
7
use Doctrine\DBAL\LockMode;
8
use Doctrine\ORM\Annotation as ORM;
9
use Doctrine\ORM\TransactionRequiredException;
10
use Doctrine\Tests\OrmFunctionalTestCase;
11
12
final class GH7366Test extends OrmFunctionalTestCase
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17
    protected function setUp() : void
18
    {
19
        parent::setUp();
20
21
        $this->setUpEntitySchema(
22
            [
23
                GH7366Entity::class,
24
            ]
25
        );
26
27
        $this->em->persist(new GH7366Entity('baz'));
28
        $this->em->flush();
29
        $this->em->clear();
30
    }
31
32
    public function testOptimisticLockNoExceptionOnFind() : void
33
    {
34
        try {
35
            $entity = $this->em->find(GH7366Entity::class, 1, LockMode::OPTIMISTIC);
0 ignored issues
show
Unused Code introduced by
The call to Doctrine\Common\Persistence\ObjectManager::find() has too many arguments starting with Doctrine\DBAL\LockMode::OPTIMISTIC. ( Ignorable by Annotation )

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

35
            /** @scrutinizer ignore-call */ 
36
            $entity = $this->em->find(GH7366Entity::class, 1, LockMode::OPTIMISTIC);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
36
        } catch (TransactionRequiredException $e) {
37
            self::fail('EntityManager::find() threw TransactionRequiredException with LockMode::OPTIMISTIC');
38
        }
39
        self::assertEquals('baz', $entity->getName());
40
    }
41
}
42
43
/**
44
 * @ORM\Entity
45
 */
46
class GH7366Entity
47
{
48
    /**
49
     * @ORM\Id
50
     * @ORM\Column(type="integer")
51
     * @ORM\GeneratedValue
52
     * @var int
53
     */
54
    public $id;
55
56
    /**
57
     * @ORM\Column(type="integer")
58
     * @ORM\Version
59
     */
60
    protected $lockVersion = 1;
61
62
    /**
63
     * @ORM\Column(length=32)
64
     * @var string
65
     */
66
    protected $name;
67
68
69
    public function __construct(string $name)
70
    {
71
        $this->name = $name;
72
    }
73
74
    public function getName() : string
75
    {
76
        return $this->name;
77
    }
78
}
79