Passed
Push — develop ( 63b8c4...391e10 )
by Marco
07:30
created

ResultSetMappingBuilder::addAllClassFields()   C

Complexity

Conditions 10
Paths 9

Size

Total Lines 53
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 28
CRAP Score 10.0296

Importance

Changes 0
Metric Value
cc 10
eloc 30
nc 9
nop 4
dl 0
loc 53
ccs 28
cts 30
cp 0.9333
crap 10.0296
rs 6.5333
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\ORM\Query;
6
7
use Doctrine\DBAL\Types\Type;
8
use Doctrine\ORM\EntityManagerInterface;
9
use Doctrine\ORM\Mapping\AssociationMetadata;
10
use Doctrine\ORM\Mapping\ClassMetadata;
11
use Doctrine\ORM\Mapping\FieldMetadata;
12
use Doctrine\ORM\Mapping\InheritanceType;
13
use Doctrine\ORM\Mapping\JoinColumnMetadata;
14
use Doctrine\ORM\Mapping\MappingException;
15
use Doctrine\ORM\Mapping\ToOneAssociationMetadata;
16
use Doctrine\ORM\Utility\PersisterHelper;
17
18
/**
19
 * A ResultSetMappingBuilder uses the EntityManager to automatically populate entity fields.
20
 *
21
 * @author Michael Ridgway <[email protected]>
22
 * @since 2.1
23
 */
24
class ResultSetMappingBuilder extends ResultSetMapping
25
{
26
    /**
27
     * Picking this rename mode will register entity columns as is,
28
     * as they are in the database. This can cause clashes when multiple
29
     * entities are fetched that have columns with the same name.
30
     *
31
     * @var int
32
     */
33
    const COLUMN_RENAMING_NONE = 1;
34
35
    /**
36
     * Picking custom renaming allows the user to define the renaming
37
     * of specific columns with a rename array that contains column names as
38
     * keys and result alias as values.
39
     *
40
     * @var int
41
     */
42
    const COLUMN_RENAMING_CUSTOM = 2;
43
44
    /**
45
     * Incremental renaming uses a result set mapping internal counter to add a
46
     * number to each column result, leading to uniqueness. This only works if
47
     * you use {@see generateSelectClause()} to generate the SELECT clause for
48
     * you.
49
     *
50
     * @var int
51
     */
52
    const COLUMN_RENAMING_INCREMENT = 3;
53
54
    /**
55
     * @var int
56
     */
57
    private $sqlCounter = 0;
58
59
    /**
60
     * @var EntityManagerInterface
61
     */
62
    private $em;
63
64
    /**
65
     * Default column renaming mode.
66
     *
67
     * @var int
68
     */
69
    private $defaultRenameMode;
70
71
    /**
72
     * @param EntityManagerInterface $em
73
     * @param integer                $defaultRenameMode
74
     */
75 22
    public function __construct(EntityManagerInterface $em, $defaultRenameMode = self::COLUMN_RENAMING_NONE)
76
    {
77 22
        $this->em                = $em;
78 22
        $this->defaultRenameMode = $defaultRenameMode;
79 22
    }
80
81
    /**
82
     * Adds a root entity and all of its fields to the result set.
83
     *
84
     * @param string   $class          The class name of the root entity.
85
     * @param string   $alias          The unique alias to use for the root entity.
86
     * @param array    $renamedColumns Columns that have been renamed (tableColumnName => queryColumnName).
87
     * @param int|null $renameMode     One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).
88
     *
89
     * @return void
90
     */
91 16
    public function addRootEntityFromClassMetadata(
92
        string $class,
93
        string $alias,
94
        array $renamedColumns = [],
95
        int $renameMode = null
96
    )
97
    {
98 16
        $renameMode = $renameMode ?: (empty($renamedColumns) ? $this->defaultRenameMode : self::COLUMN_RENAMING_CUSTOM);
99
100 16
        $this->addEntityResult($class, $alias);
101 16
        $this->addAllClassFields($class, $alias, $renamedColumns, $renameMode);
102 15
    }
103
104
    /**
105
     * Adds a joined entity and all of its fields to the result set.
106
     *
107
     * @param string   $class          The class name of the joined entity.
108
     * @param string   $alias          The unique alias to use for the joined entity.
109
     * @param string   $parentAlias    The alias of the entity result that is the parent of this joined result.
110
     * @param string   $relation       The association field that connects the parent entity result
111
     *                                 with the joined entity result.
112
     * @param array    $renamedColumns Columns that have been renamed (tableColumnName => queryColumnName).
113
     * @param int|null $renameMode     One of the COLUMN_RENAMING_* constants or array for BC reasons (CUSTOM).
114
     *
115
     * @return void
116
     */
117 3
    public function addJoinedEntityFromClassMetadata(
118
        string $class,
119
        string $alias,
120
        string $parentAlias,
121
        string $relation,
122
        array $renamedColumns = [],
123
        int $renameMode = null
124
    )
125
    {
126 3
        $renameMode = $renameMode ?: (empty($renamedColumns) ? $this->defaultRenameMode : self::COLUMN_RENAMING_CUSTOM);
127
128 3
        $this->addJoinedEntityResult($class, $alias, $parentAlias, $relation);
129 3
        $this->addAllClassFields($class, $alias, $renamedColumns, $renameMode);
130 2
    }
131
132
    /**
133
     * Adds all fields of the given class to the result set mapping (columns and meta fields).
134
     *
135
     * @param string $class
136
     * @param string $alias
137
     * @param array  $customRenameColumns
138
     *
139
     * @return void
140
     *
141
     * @throws \InvalidArgumentException
142
     */
143 16
    protected function addAllClassFields(string $class, string $alias, array $customRenameColumns, int $renameMode) : void
144
    {
145
        /** @var ClassMetadata $classMetadata */
146 16
        $classMetadata = $this->em->getClassMetadata($class);
147 16
        $platform      = $this->em->getConnection()->getDatabasePlatform();
148
149 16
        if (! $this->isInheritanceSupported($classMetadata)) {
150 1
            throw new \InvalidArgumentException(
151 1
                'ResultSetMapping builder does not currently support your inheritance scheme.'
152
            );
153
        }
154
155 15
        foreach ($classMetadata->getDeclaredPropertiesIterator() as $property) {
156
            switch (true) {
157 15
                case ($property instanceof FieldMetadata):
158 15
                    $columnName  = $property->getColumnName();
159 15
                    $columnAlias = $platform->getSQLResultCasing(
160 15
                        $this->getColumnAlias($columnName, $renameMode, $customRenameColumns)
161
                    );
162
163 15
                    if (isset($this->fieldMappings[$columnAlias])) {
164 1
                        throw new \InvalidArgumentException(
165 1
                            sprintf("The column '%s' conflicts with another column in the mapper.", $columnName)
166
                        );
167
                    }
168
169 15
                    $this->addFieldResult($alias, $columnAlias, $property->getName());
170 15
                    break;
171
172 10
                case ($property instanceof ToOneAssociationMetadata && $property->isOwningSide()):
173 10
                    $targetClass = $this->em->getClassMetadata($property->getTargetEntity());
0 ignored issues
show
Bug introduced by
The method getTargetEntity() does not exist on Doctrine\ORM\Mapping\Property. It seems like you code against a sub-type of Doctrine\ORM\Mapping\Property such as Doctrine\ORM\Mapping\AssociationMetadata. ( Ignorable by Annotation )

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

173
                    $targetClass = $this->em->getClassMetadata($property->/** @scrutinizer ignore-call */ getTargetEntity());
Loading history...
174
175 10
                    foreach ($property->getJoinColumns() as $joinColumn) {
0 ignored issues
show
Bug introduced by
The method getJoinColumns() does not exist on Doctrine\ORM\Mapping\Property. It seems like you code against a sub-type of Doctrine\ORM\Mapping\Property such as Doctrine\ORM\Mapping\ToOneAssociationMetadata. ( Ignorable by Annotation )

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

175
                    foreach ($property->/** @scrutinizer ignore-call */ getJoinColumns() as $joinColumn) {
Loading history...
176
                        /** @var JoinColumnMetadata $joinColumn */
177 10
                        $columnName           = $joinColumn->getColumnName();
178 10
                        $referencedColumnName = $joinColumn->getReferencedColumnName();
179 10
                        $columnAlias          = $platform->getSQLResultCasing(
180 10
                            $this->getColumnAlias($columnName, $renameMode, $customRenameColumns)
181
                        );
182
183 10
                        if (isset($this->metaMappings[$columnAlias])) {
184
                            throw new \InvalidArgumentException(
185
                                sprintf("The column '%s' conflicts with another column in the mapper.", $columnName)
186
                            );
187
                        }
188
189 10
                        if (! $joinColumn->getType()) {
190 4
                            $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $targetClass, $this->em));
0 ignored issues
show
Bug introduced by
$targetClass of type Doctrine\Common\Persistence\Mapping\ClassMetadata is incompatible with the type Doctrine\ORM\Mapping\ClassMetadata expected by parameter $class of Doctrine\ORM\Utility\Per...lper::getTypeOfColumn(). ( Ignorable by Annotation )

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

190
                            $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, /** @scrutinizer ignore-type */ $targetClass, $this->em));
Loading history...
191
                        }
192
193 10
                        $this->addMetaResult($alias, $columnAlias, $columnName, $property->isPrimaryKey(), $joinColumn->getType());
194
                    }
195 15
                    break;
196
            }
197
        }
198 15
    }
199
200
    /**
201
     * Checks if inheritance if supported.
202
     *
203
     * @param ClassMetadata $metadata
204
     *
205
     * @return boolean
206
     */
207 16
    private function isInheritanceSupported(ClassMetadata $metadata)
208
    {
209 16
        if ($metadata->inheritanceType === InheritanceType::SINGLE_TABLE
210 16
            && in_array($metadata->getClassName(), $metadata->discriminatorMap, true)) {
211 2
            return true;
212
        }
213
214 15
        return ! in_array($metadata->inheritanceType, [InheritanceType::SINGLE_TABLE, InheritanceType::JOINED]);
215
    }
216
217
    /**
218
     * Gets column alias for a given column.
219
     *
220
     * @param string $columnName
221
     * @param int    $mode
222
     * @param array  $customRenameColumns
223
     *
224
     * @return string
225
     */
226 15
    private function getColumnAlias($columnName, $mode, array $customRenameColumns)
227
    {
228
        switch ($mode) {
229 15
            case self::COLUMN_RENAMING_INCREMENT:
230 2
                return $columnName . $this->sqlCounter++;
231
232 13
            case self::COLUMN_RENAMING_CUSTOM:
233 3
                return $customRenameColumns[$columnName] ?? $columnName;
234
235 12
            case self::COLUMN_RENAMING_NONE:
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
236 12
                return $columnName;
237
238
        }
239
    }
240
241
    /**
242
     * Adds the mappings of the results of native SQL queries to the result set.
243
     *
244
     * @param ClassMetadata $class
245
     * @param array         $queryMapping
246
     *
247
     * @return ResultSetMappingBuilder
248
     */
249 3
    public function addNamedNativeQueryMapping(ClassMetadata $class, array $queryMapping)
250
    {
251 3
        if (isset($queryMapping['resultClass'])) {
252 1
            $entityClass = ($queryMapping['resultClass'] === '__CLASS__')
253 1
                ? $class
254 1
                : $this->em->getClassMetadata($queryMapping['resultClass'])
255
            ;
256
257 1
            $this->addEntityResult($entityClass->getClassName(), 'e0');
0 ignored issues
show
Bug introduced by
The method getClassName() 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

257
            $this->addEntityResult($entityClass->/** @scrutinizer ignore-call */ getClassName(), 'e0');

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...
258 1
            $this->addNamedNativeQueryEntityResultMapping($entityClass, [], 'e0');
0 ignored issues
show
Bug introduced by
It seems like $entityClass can also be of type Doctrine\Common\Persistence\Mapping\ClassMetadata; however, parameter $classMetadata of Doctrine\ORM\Query\Resul...ryEntityResultMapping() does only seem to accept Doctrine\ORM\Mapping\ClassMetadata, maybe add an additional type check? ( Ignorable by Annotation )

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

258
            $this->addNamedNativeQueryEntityResultMapping(/** @scrutinizer ignore-type */ $entityClass, [], 'e0');
Loading history...
259
260 1
            return $this;
261
        }
262
263 2
        return $this->addNamedNativeQueryResultSetMapping($class, $queryMapping['resultSetMapping']);
264
    }
265
266
    /**
267
     * Adds the result set mapping of the results of native SQL queries to the result set.
268
     *
269
     * @param ClassMetadata $class
270
     * @param string        $resultSetMappingName
271
     *
272
     * @return ResultSetMappingBuilder
273
     */
274 2
    public function addNamedNativeQueryResultSetMapping(ClassMetadata $class, $resultSetMappingName)
275
    {
276 2
        $counter        = 0;
277 2
        $resultMapping  = $class->getSqlResultSetMapping($resultSetMappingName);
278 2
        $rootAlias      = 'e' . $counter;
279
280 2
        if (isset($resultMapping['entities'])) {
281 2
            foreach ($resultMapping['entities'] as $key => $entityMapping) {
282 2
                $entityMapping['entityClass'] = ($entityMapping['entityClass'] === '__CLASS__')
283 2
                    ? $class->getClassName()
284 1
                    : $entityMapping['entityClass']
285
                ;
286
287 2
                $classMetadata = $this->em->getClassMetadata($entityMapping['entityClass']);
288
289 2
                if ($class->getClassName() === $classMetadata->getClassName()) {
290 2
                    $this->addEntityResult($classMetadata->getClassName(), $rootAlias);
291 2
                    $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $rootAlias);
0 ignored issues
show
Bug introduced by
$classMetadata of type Doctrine\Common\Persistence\Mapping\ClassMetadata is incompatible with the type Doctrine\ORM\Mapping\ClassMetadata expected by parameter $classMetadata of Doctrine\ORM\Query\Resul...ryEntityResultMapping(). ( Ignorable by Annotation )

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

291
                    $this->addNamedNativeQueryEntityResultMapping(/** @scrutinizer ignore-type */ $classMetadata, $entityMapping, $rootAlias);
Loading history...
292
                } else {
293 1
                    $joinAlias = 'e' . ++$counter;
294
295 1
                    $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $joinAlias);
296
297 1
                    foreach ($class->getDeclaredPropertiesIterator() as $fieldName => $association) {
298 1
                        if (! ($association instanceof AssociationMetadata)) {
299
                            continue;
300
                        }
301
302 1
                        if ($association->getTargetEntity() !== $classMetadata->getClassName()) {
303
                            continue;
304
                        }
305
306 2
                        $this->addJoinedEntityResult($association->getTargetEntity(), $joinAlias, $rootAlias, $fieldName);
307
                    }
308
                }
309
            }
310
        }
311
312 2
        if (isset($resultMapping['columns'])) {
313 2
            foreach ($resultMapping['columns'] as $entityMapping) {
314
                // @todo guilhermeblanco Collect type information from mapped column
315 2
                $this->addScalarResult($entityMapping['name'], $entityMapping['name'], Type::getType('string'));
316
            }
317
        }
318
319 2
        return $this;
320
    }
321
322
    /**
323
     * Adds the entity result mapping of the results of native SQL queries to the result set.
324
     *
325
     * @param ClassMetadata $classMetadata
326
     * @param array         $entityMapping
327
     * @param string        $alias
328
     *
329
     * @return ResultSetMappingBuilder
330
     *
331
     * @throws MappingException
332
     * @throws \InvalidArgumentException
333
     */
334 3
    public function addNamedNativeQueryEntityResultMapping(ClassMetadata $classMetadata, array $entityMapping, $alias)
335
    {
336 3
        $platform = $this->em->getConnection()->getDatabasePlatform();
337
338
        // Always fetch discriminator column. It's required for Proxy loading. We only adjust naming if provided
339 3
        if ($classMetadata->discriminatorColumn) {
340
            $discrColumn     = $classMetadata->discriminatorColumn;
341
            $discrColumnName = $entityMapping['discriminatorColumn'] ?? $discrColumn->getColumnName();
342
            $discrColumnType = $discrColumn->getType();
343
344
            $this->setDiscriminatorColumn($alias, $discrColumnName);
345
            $this->addMetaResult($alias, $discrColumnName, $discrColumnName, false, $discrColumnType);
346
        }
347
348 3
        if (isset($entityMapping['fields']) && ! empty($entityMapping['fields'])) {
349 1
            foreach ($entityMapping['fields'] as $field) {
350 1
                $fieldName = $field['name'];
351 1
                $relation  = null;
352
353 1
                if (strpos($fieldName, '.') !== false) {
354
                    list($relation, $fieldName) = explode('.', $fieldName);
355
                }
356
357 1
                $property = $classMetadata->getProperty($fieldName);
358
359 1
                if (! $relation && $property instanceof FieldMetadata) {
360 1
                    $this->addFieldResult($alias, $field['column'], $fieldName, $classMetadata->getClassName());
361
362 1
                    continue;
363
                }
364
365
                $property = $classMetadata->getProperty($relation);
366
367
                if (! $property) {
368
                    throw new \InvalidArgumentException(
369
                        "Entity '".$classMetadata->getClassName()."' has no field '".$relation."'. "
370
                    );
371
                }
372
373
                if ($property instanceof AssociationMetadata) {
374
                    if (! $relation) {
375
                        $this->addFieldResult($alias, $field['column'], $fieldName, $classMetadata->getClassName());
376
377
                        continue;
378
                    }
379
380
                    $joinAlias   = $alias.$relation;
0 ignored issues
show
Bug introduced by
Are you sure $relation of type void can be used in concatenation? ( Ignorable by Annotation )

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

380
                    $joinAlias   = $alias./** @scrutinizer ignore-type */ $relation;
Loading history...
381
                    $parentAlias = $alias;
382
383
                    $this->addJoinedEntityResult($property->getTargetEntity(), $joinAlias, $parentAlias, $relation);
0 ignored issues
show
Bug introduced by
$relation of type void is incompatible with the type string expected by parameter $relation of Doctrine\ORM\Query\Resul...addJoinedEntityResult(). ( Ignorable by Annotation )

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

383
                    $this->addJoinedEntityResult($property->getTargetEntity(), $joinAlias, $parentAlias, /** @scrutinizer ignore-type */ $relation);
Loading history...
384 1
                    $this->addFieldResult($joinAlias, $field['column'], $fieldName);
385
                }
386
            }
387
        } else {
388 2
            foreach ($classMetadata->getDeclaredPropertiesIterator() as $property) {
389
                switch (true) {
390 2
                    case ($property instanceof FieldMetadata):
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
391 2
                        $columnName  = $property->getColumnName();
392 2
                        $columnAlias = $platform->getSQLResultCasing($columnName);
393
394 2
                        if (isset($this->fieldMappings[$columnAlias])) {
395
                            throw new \InvalidArgumentException(
396
                                sprintf("The column '%s' conflicts with another column in the mapper.", $columnName)
397
                            );
398
                        }
399
400 2
                        $this->addFieldResult($alias, $columnAlias, $property->getName());
401 2
                        break;
402
403 2
                    case ($property instanceof ToOneAssociationMetadata && $property->isOwningSide()):
0 ignored issues
show
Coding Style introduced by
case statements should be defined using a colon.

As per the PSR-2 coding standard, case statements should not be wrapped in curly braces. There is no need for braces, since each case is terminated by the next break.

There is also the option to use a semicolon instead of a colon, this is discouraged because many programmers do not even know it works and the colon is universal between programming languages.

switch ($expr) {
    case "A": { //wrong
        doSomething();
        break;
    }
    case "B"; //wrong
        doSomething();
        break;
    case "C": //right
        doSomething();
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
404 2
                        $targetClass = $this->em->getClassMetadata($property->getTargetEntity());
405
406 2
                        foreach ($property->getJoinColumns() as $joinColumn) {
407
                            /** @var JoinColumnMetadata $joinColumn */
408 2
                            $columnName           = $joinColumn->getColumnName();
409 2
                            $referencedColumnName = $joinColumn->getReferencedColumnName();
410 2
                            $columnAlias          = $platform->getSQLResultCasing($columnName);
411
412 2
                            if (isset($this->metaMappings[$columnAlias])) {
413
                                throw new \InvalidArgumentException(
414
                                    sprintf("The column '%s' conflicts with another column in the mapper.", $columnName)
415
                                );
416
                            }
417
418 2
                            if (! $joinColumn->getType()) {
419 1
                                $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, $targetClass, $this->em));
0 ignored issues
show
Bug introduced by
$targetClass of type Doctrine\Common\Persistence\Mapping\ClassMetadata is incompatible with the type Doctrine\ORM\Mapping\ClassMetadata expected by parameter $class of Doctrine\ORM\Utility\Per...lper::getTypeOfColumn(). ( Ignorable by Annotation )

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

419
                                $joinColumn->setType(PersisterHelper::getTypeOfColumn($referencedColumnName, /** @scrutinizer ignore-type */ $targetClass, $this->em));
Loading history...
420
                            }
421
422 2
                            $this->addMetaResult($alias, $columnAlias, $columnName, $property->isPrimaryKey(), $joinColumn->getType());
423
                        }
424 2
                        break;
425
                }
426
            }
427
        }
428
429 3
        return $this;
430
    }
431
432
    /**
433
     * Generates the Select clause from this ResultSetMappingBuilder.
434
     *
435
     * Works only for all the entity results. The select parts for scalar
436
     * expressions have to be written manually.
437
     *
438
     * @param array $tableAliases
439
     *
440
     * @return string
441
     */
442 6
    public function generateSelectClause($tableAliases = [])
443
    {
444 6
        $sql = "";
445
446 6
        foreach ($this->columnOwnerMap as $columnName => $dqlAlias) {
447 6
            $tableAlias = $tableAliases[$dqlAlias] ?? $dqlAlias;
448
449 6
            if ($sql) {
450 6
                $sql .= ", ";
451
            }
452
453 6
            $sql .= $tableAlias . ".";
454
455 6
            if (isset($this->fieldMappings[$columnName])) {
456 6
                $class = $this->em->getClassMetadata($this->declaringClasses[$columnName]);
457 6
                $field = $this->fieldMappings[$columnName];
458 6
                $sql  .= $class->getProperty($field)->getColumnName();
0 ignored issues
show
Bug introduced by
The method getProperty() 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

458
                $sql  .= $class->/** @scrutinizer ignore-call */ getProperty($field)->getColumnName();

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...
459 6
            } elseif (isset($this->metaMappings[$columnName])) {
460 5
                $sql .= $this->metaMappings[$columnName];
461 1
            } elseif (isset($this->discriminatorColumns[$dqlAlias])) {
462 1
                $sql .= $this->discriminatorColumns[$dqlAlias];
463
            }
464
465 6
            $sql .= " AS " . $columnName;
466
        }
467
468 6
        return $sql;
469
    }
470
471
    /**
472
     * @return string
473
     */
474 1
    public function __toString()
475
    {
476 1
        return $this->generateSelectClause([]);
477
    }
478
}
479