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

api-platform / core / 14635100171

24 Apr 2025 06:39AM UTC coverage: 8.271% (+0.02%) from 8.252%
14635100171

Pull #6904

github

web-flow
Merge c9cefd82e into a3e5e53ea
Pull Request #6904: feat(graphql): added support for graphql subscriptions to work for actions

0 of 73 new or added lines in 3 files covered. (0.0%)

1999 existing lines in 144 files now uncovered.

13129 of 158728 relevant lines covered (8.27%)

13.6 hits per line

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

92.86
/src/Doctrine/Common/Filter/OrderFilterTrait.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\Doctrine\Common\Filter;
15

16
use ApiPlatform\Doctrine\Common\PropertyHelperTrait;
17

18
/**
19
 * Trait for ordering the collection by given properties.
20
 *
21
 * @author Kévin Dunglas <dunglas@gmail.com>
22
 * @author Théo FIDRY <theo.fidry@gmail.com>
23
 * @author Alan Poulain <contact@alanpoulain.eu>
24
 */
25
trait OrderFilterTrait
26
{
27
    use PropertyHelperTrait;
28

29
    /**
30
     * @var string Keyword used to retrieve the value
31
     */
32
    protected string $orderParameterName;
33

34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function getDescription(string $resourceClass): array
38
    {
39
        $description = [];
247✔
40

41
        $properties = $this->getProperties();
247✔
42
        if (null === $properties && $fieldNames = $this->getClassMetadata($resourceClass)->getFieldNames()) {
247✔
43
            $properties = array_fill_keys($fieldNames, null);
×
44
        }
45

46
        foreach ($properties ?? [] as $property => $propertyOptions) {
247✔
47
            if (!$this->isPropertyMapped($property, $resourceClass)) {
247✔
48
                continue;
230✔
49
            }
50
            $propertyName = $this->normalizePropertyName($property);
245✔
51
            $description[\sprintf('%s[%s]', $this->orderParameterName, $propertyName)] = [
245✔
52
                'property' => $propertyName,
245✔
53
                'type' => 'string',
245✔
54
                'required' => false,
245✔
55
                'schema' => [
245✔
56
                    'type' => 'string',
245✔
57
                    'default' => strtolower($propertyOptions['default_direction'] ?? OrderFilterInterface::DIRECTION_ASC),
245✔
58
                    'enum' => [
245✔
59
                        strtolower(OrderFilterInterface::DIRECTION_ASC),
245✔
60
                        strtolower(OrderFilterInterface::DIRECTION_DESC),
245✔
61
                    ],
245✔
62
                ],
245✔
63
            ];
245✔
64
        }
65

66
        return $description;
245✔
67
    }
68

69
    abstract protected function getProperties(): ?array;
70

71
    abstract protected function normalizePropertyName(string $property): string;
72

73
    private function normalizeValue($value, string $property): ?string
74
    {
75
        if (empty($value) && null !== $defaultDirection = $this->getProperties()[$property]['default_direction'] ?? null) {
39✔
76
            // fallback to default direction
UNCOV
77
            $value = $defaultDirection;
2✔
78
        }
79

80
        $value = strtoupper($value);
39✔
81
        if (!\in_array($value, [self::DIRECTION_ASC, self::DIRECTION_DESC], true)) {
39✔
82
            return null;
×
83
        }
84

85
        return $value;
39✔
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

© 2025 Coveralls, Inc