Failed Conditions
Pull Request — master (#7807)
by Christian
09:57
created

GH7804Dto   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 12
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getTitle() 0 3 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\Tests\OrmFunctionalTestCase;
7
8
final class GH7804 extends OrmFunctionalTestCase
9
{
10
    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...
11
    {
12
        parent::setUp();
13
14
        $this->setUpEntitySchema([
15
            GH7804Entity::class,
16
        ]);
17
    }
18
19
    public function testPositiveQuery(): void
0 ignored issues
show
introduced by
There must be exactly 1 whitespace between closing parenthesis and return type colon.
Loading history...
20
    {
21
        $qb = $this->em->createQueryBuilder();
22
23
        $qb->from(GH7804Entity::class, 'te1')
24
            ->select('te1.title as t')
25
            ->addGroupBy('t');
26
27
        self::assertSQLEquals(
28
            'select t0."title" as c0 from "te1" t0 group by t0."title"',
29
            $qb->getQuery()->getSQL()
30
        );
31
    }
32
33
    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...
34
    {
35
        $qb = $this->em->createQueryBuilder();
36
37
        $qb->from(GH7804Entity::class, 'te1')
38
            ->select(
39
                sprintf('new %s(te1.title as t)', GH7804Dto::class)
0 ignored issues
show
introduced by
Function sprintf() should not be referenced via a fallback global name, but via a use statement.
Loading history...
40
            )
41
            ->addGroupBy('t');
42
43
        self::assertSQLEquals(
44
            'select t0."title" as c0 from "te1" t0 group by t0."title"',
45
            $qb->getQuery()->getSQL()
46
        );
47
    }
48
}
49
50
/**
51
 * @ORM\Entity
52
 * @ORM\Table(name="te1")
53
 */
54
class GH7804Entity
55
{
56
    /**
57
     * @ORM\Id
58
     * @ORM\Column(type="integer")
59
     * @ORM\GeneratedValue
60
     */
61
    public $id;
62
63
    /** @ORM\Column */
64
    public $title;
65
66
    /**
67
     * @param $title
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
68
     */
69
    public function __construct($title)
0 ignored issues
show
introduced by
Method \Doctrine\Tests\ORM\Functional\Ticket\GH7804Entity::__construct() does not need documentation comment.
Loading history...
70
    {
71
        $this->title = $title;
72
    }
73
}
74
75
final class GH7804Dto
76
{
77
    private $title;
78
79
    public function __construct($title)
80
    {
81
        $this->title = $title;
82
    }
83
84
    public function getTitle()
85
    {
86
        return $this->title;
87
    }
88
}
89