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

api-platform / core / 6067528200

04 Sep 2023 12:12AM UTC coverage: 36.875% (-21.9%) from 58.794%
6067528200

Pull #5791

github

web-flow
Merge 64157e578 into d09cfc9d2
Pull Request #5791: fix: strip down any sql function name

3096 of 3096 new or added lines in 205 files covered. (100.0%)

9926 of 26918 relevant lines covered (36.87%)

6.5 hits per line

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

0.0
/src/Elasticsearch/Util/FieldDatatypeTrait.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Elasticsearch\Util;
15

16
use ApiPlatform\Metadata\Exception\PropertyNotFoundException;
17
use ApiPlatform\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
18
use ApiPlatform\Metadata\ResourceClassResolverInterface;
19
use Symfony\Component\PropertyInfo\Type;
20

21
/**
22
 * Field datatypes helpers.
23
 *
24
 * @internal
25
 *
26
 * @experimental
27
 *
28
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
29
 */
30
trait FieldDatatypeTrait
31
{
32
    private readonly PropertyMetadataFactoryInterface $propertyMetadataFactory;
33

34
    private readonly ResourceClassResolverInterface $resourceClassResolver;
35

36
    /**
37
     * Is the decomposed given property of the given resource class potentially mapped as a nested field in Elasticsearch?
38
     */
39
    private function isNestedField(string $resourceClass, string $property): bool
40
    {
41
        return null !== $this->getNestedFieldPath($resourceClass, $property);
×
42
    }
43

44
    /**
45
     * Get the nested path to the decomposed given property (e.g.: foo.bar.baz => foo.bar).
46
     */
47
    private function getNestedFieldPath(string $resourceClass, string $property): ?string
48
    {
49
        $properties = explode('.', $property);
×
50
        $currentProperty = array_shift($properties);
×
51

52
        if (!$properties) {
×
53
            return null;
×
54
        }
55

56
        try {
57
            $propertyMetadata = $this->propertyMetadataFactory->create($resourceClass, $currentProperty);
×
58
        } catch (PropertyNotFoundException) {
×
59
            return null;
×
60
        }
61

62
        $types = $propertyMetadata->getBuiltinTypes() ?? [];
×
63

64
        foreach ($types as $type) {
×
65
            if (
66
                Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
×
67
                && null !== ($nextResourceClass = $type->getClassName())
×
68
                && $this->resourceClassResolver->isResourceClass($nextResourceClass)
×
69
            ) {
70
                $nestedPath = $this->getNestedFieldPath($nextResourceClass, implode('.', $properties));
×
71

72
                return null === $nestedPath ? $nestedPath : "$currentProperty.$nestedPath";
×
73
            }
74

75
            if (
76
                null !== ($type = $type->getCollectionValueTypes()[0] ?? null)
×
77
                && Type::BUILTIN_TYPE_OBJECT === $type->getBuiltinType()
×
78
                && null !== ($className = $type->getClassName())
×
79
                && $this->resourceClassResolver->isResourceClass($className)
×
80
            ) {
81
                return $currentProperty;
×
82
            }
83
        }
84

85
        return null;
×
86
    }
87
}
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

© 2026 Coveralls, Inc