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

api-platform / core / 10739011304

06 Sep 2024 01:11PM UTC coverage: 7.159% (-0.5%) from 7.645%
10739011304

push

github

web-flow
 feat(laravel): eloquent filters (search, date, equals, or) (#6593)

* feat(laravel): Eloquent filters search date or

* feat(laravel): eloquent filters order range equals afterdate

* fix(laravel): order afterDate filters

* temp

* test(laravel): filter with eloquent

---------

Co-authored-by: Nathan <nathan@les-tilleuls.coop>

0 of 144 new or added lines in 16 files covered. (0.0%)

4792 existing lines in 155 files now uncovered.

11736 of 163930 relevant lines covered (7.16%)

22.8 hits per line

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

16.67
/src/GraphQl/Serializer/ObjectNormalizer.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\GraphQl\Serializer;
15

16
use ApiPlatform\Metadata\IdentifiersExtractorInterface;
17
use ApiPlatform\Metadata\IriConverterInterface;
18
use ApiPlatform\Metadata\Util\ClassInfoTrait;
19
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
20
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
21

22
/**
23
 * Decorates the output with GraphQL metadata when appropriate, but otherwise just
24
 * passes through to the decorated normalizer.
25
 */
26
final class ObjectNormalizer implements NormalizerInterface
27
{
28
    use ClassInfoTrait;
29

30
    public const FORMAT = 'graphql';
31
    public const ITEM_RESOURCE_CLASS_KEY = '#itemResourceClass';
32
    public const ITEM_IDENTIFIERS_KEY = '#itemIdentifiers';
33

34
    public function __construct(private readonly NormalizerInterface $decorated, private readonly IriConverterInterface $iriConverter, private readonly IdentifiersExtractorInterface $identifiersExtractor)
35
    {
UNCOV
36
    }
2,258✔
37

38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
42
    {
43
        return self::FORMAT === $format && $this->decorated->supportsNormalization($data, $format, $context);
1✔
44
    }
45

46
    public function getSupportedTypes($format): array
47
    {
UNCOV
48
        return self::FORMAT === $format ? $this->decorated->getSupportedTypes($format) : [];
1,939✔
49
    }
50

51
    /**
52
     * {@inheritdoc}
53
     *
54
     * @throws UnexpectedValueException
55
     */
56
    public function normalize(mixed $object, ?string $format = null, array $context = []): array|string|int|float|bool|\ArrayObject|null
57
    {
58
        if (isset($context['api_resource'])) {
×
59
            $originalResource = $context['api_resource'];
×
60
            unset($context['api_resource']);
×
61
        }
62

63
        $data = $this->decorated->normalize($object, $format, $context);
×
64
        if (!\is_array($data)) {
×
65
            throw new UnexpectedValueException('Expected data to be an array.');
×
66
        }
67

68
        if (!isset($originalResource)) {
×
69
            return $data;
×
70
        }
71

72
        if (isset($data['id'])) {
×
73
            $data['_id'] = $data['id'];
×
74
            $data['id'] = $this->iriConverter->getIriFromResource($originalResource);
×
75
        }
76

77
        if (!($context['no_resolver_data'] ?? false)) {
×
78
            $data[self::ITEM_RESOURCE_CLASS_KEY] = $this->getObjectClass($originalResource);
×
79
            $data[self::ITEM_IDENTIFIERS_KEY] = $this->identifiersExtractor->getIdentifiersFromItem($originalResource);
×
80
        }
81

82
        return $data;
×
83
    }
84
}
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

© 2024 Coveralls, Inc