• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

php-bug-catcher / bug-catcher / 20456731454

23 Dec 2025 09:21AM UTC coverage: 85.729% (-3.4%) from 89.142%
20456731454

push

github

web-flow
Merge pull request #17 from php-bug-catcher/selection

Added selection functionality to logs for batch proccesing

2 of 16 new or added lines in 3 files covered. (12.5%)

20 existing lines in 5 files now uncovered.

829 of 967 relevant lines covered (85.73%)

13.08 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/src/Extension/DQL/TypeFunction.php
1
<?php
2
namespace BugCatcher\Extension\DQL;
3

4
use Doctrine\ORM\Mapping\ClassMetadataInfo;
5
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
6
use Doctrine\ORM\Query\Parser;
7
use Doctrine\ORM\Query\QueryException;
8
use Doctrine\ORM\Query\SqlWalker;
9
use Doctrine\ORM\Query\TokenType;
10

11
/**
12
 * Provides a way to access an entity's discriminator field in DQL
13
 * queries.
14
 *
15
 * Assuming the same "Person" entity from Doctrine's documentation on
16
 * Inheritence Mapping, which has a discriminator field named "discr":
17
 *
18
 * Using the TYPE() function, DQL will interpret this:
19
 *
20
 * <pre>'SELECT TYPE(p) FROM Person p'</pre>
21
 *
22
 * as if you had written this:
23
 *
24
 * <pre>'SELECT p.discr FROM Person p'</pre>
25
 *
26
 * This conversion happens at the SQL level, so the ORM is no longer
27
 * part of the picture at that point.
28
 *
29
 * Normally, if you try to access the discriminator field in a DQL
30
 * Query, Doctrine will complain that the field does not exist on the
31
 * entity. This makes sense from an ORM point-of-view, but having
32
 * access to the discriminator field allows us to, for example:
33
 *
34
 * - get the type when we only have an ID
35
 * - query within a subset of all the available types
36
 */
37
final class TypeFunction extends FunctionNode
38
{
39
        /**
40
         * @var string
41
         */
42
        public $dqlAlias;
43

44
        /**
45
         * @param SqlWalker $sqlWalker
46
         * @return string
47
         */
48
        public function getSql(SqlWalker $sqlWalker): string {
49
                $qComp = $sqlWalker->getQueryComponent($this->dqlAlias);
2✔
50
                /** @var ClassMetadataInfo $class */
51
                $class      = $qComp['metadata'];
2✔
52
                $tableAlias = $sqlWalker->getSQLTableAlias($class->getTableName(), $this->dqlAlias);
2✔
53

54
                if (!isset($class->discriminatorColumn['name'])) {
2✔
55
                        throw QueryException::semanticalError(
2✔
56
                                'TYPE() only supports entities with a discriminator column.'
2✔
57
                        );
2✔
58
                }
59

UNCOV
60
                return $tableAlias . '.' . $class->discriminatorColumn['name'];
×
61
        }
62

63
        /**
64
         * @param Parser $parser
65
         */
66
        public function parse(Parser $parser): void {
67
                $parser->match(TokenType::T_IDENTIFIER);
2✔
68
                $parser->match(TokenType::T_OPEN_PARENTHESIS);
2✔
69

70
                $this->dqlAlias = $parser->IdentificationVariable();
2✔
71

72
                $parser->match(TokenType::T_CLOSE_PARENTHESIS);
2✔
73
        }
74
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc