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

api-platform / core / 17054099799

18 Aug 2025 10:28PM UTC coverage: 22.386% (-0.2%) from 22.612%
17054099799

Pull #7150

github

web-flow
Merge 973c71211 into 2d501b315
Pull Request #7150: fix: array shape in ProviderInterface

11062 of 49414 relevant lines covered (22.39%)

11.75 hits per line

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

0.0
/src/Laravel/Eloquent/Serializer/SerializerContextBuilder.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\Laravel\Eloquent\Serializer;
15

16
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
17
use ApiPlatform\State\SerializerContextBuilderInterface;
18
use Illuminate\Database\Eloquent\Model;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter;
21
use Symfony\Component\Serializer\NameConverter\SnakeCaseToCamelCaseNameConverter;
22
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
23

24
final class SerializerContextBuilder implements SerializerContextBuilderInterface
25
{
26
    /**
27
     * @param class-string $nameConverterClass
28
     */
29
    public function __construct(
30
        private readonly SerializerContextBuilderInterface $decorated,
31
        private readonly PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory,
32
        private readonly ?string $nameConverterClass = null,
33
    ) {
34
    }
×
35

36
    /**
37
     * @param array<string, mixed> $extractedAttributes
38
     */
39
    public function createFromRequest(Request $request, bool $normalization, ?array $extractedAttributes = null): array
40
    {
41
        $context = $this->decorated->createFromRequest($request, $normalization, $extractedAttributes);
×
42
        if (!isset($context['resource_class']) || !is_a($context['resource_class'], Model::class, true)) {
×
43
            return $context;
×
44
        }
45

46
        if (SnakeCaseToCamelCaseNameConverter::class === $this->nameConverterClass) {
×
47
            $context[SnakeCaseToCamelCaseNameConverter::REQUIRE_CAMEL_CASE_PROPERTIES] = true;
×
48
        } elseif (CamelCaseToSnakeCaseNameConverter::class === $this->nameConverterClass) {
×
49
            $context[CamelCaseToSnakeCaseNameConverter::REQUIRE_SNAKE_CASE_PROPERTIES] = true;
×
50
        }
51

52
        if (!isset($context[AbstractNormalizer::ATTRIBUTES])) {
×
53
            // isWritable/isReadable is checked later on
54
            $context[AbstractNormalizer::ATTRIBUTES] = iterator_to_array($this->propertyNameCollectionFactory->create($context['resource_class'], ['serializer_groups' => $context['groups'] ?? null]));
×
55
        }
56

57
        return $context;
×
58
    }
59
}
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