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

api-platform / core / 10557514433

26 Aug 2024 09:45AM UTC coverage: 7.704% (-0.003%) from 7.707%
10557514433

push

github

web-flow
feat(laravel): provide a trait in addition to the annotation (#6543)

* feat(laravel): provide a trait in addition to the annotation

* fix

* fix

* add support for ApiProperty and refactoring

* fix Eloquent property collection

* fix PHPStan

8 of 179 new or added lines in 11 files covered. (4.47%)

2 existing lines in 2 files now uncovered.

12489 of 162109 relevant lines covered (7.7%)

22.98 hits per line

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

0.0
/src/Laravel/Metadata/ConcernsPropertyNameCollectionMetadataFactory.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\Metadata;
15

16
use ApiPlatform\Laravel\IsApiResource;
17
use ApiPlatform\Metadata\ApiProperty;
18
use ApiPlatform\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
19
use ApiPlatform\Metadata\Property\PropertyNameCollection;
20

21
/**
22
 * Handles property defined with the {@see IsApiResource} concern.
23
 *
24
 * @author Kévin Dunglas <kevin@dunglas.dev>
25
 */
26
final class ConcernsPropertyNameCollectionMetadataFactory implements PropertyNameCollectionFactoryInterface
27
{
28
    public function __construct(
29
        private readonly ?PropertyNameCollectionFactoryInterface $decorated = null,
30
    ) {
NEW
31
    }
×
32

33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @param class-string $resourceClass
37
     */
38
    public function create(string $resourceClass, array $options = []): PropertyNameCollection
39
    {
NEW
40
        $propertyNameCollection = $this->decorated?->create($resourceClass, $options);
×
NEW
41
        if (!method_exists($resourceClass, 'apiResource')) {
×
NEW
42
            return $propertyNameCollection ?? new PropertyNameCollection();
×
43
        }
44

NEW
45
        $refl = new \ReflectionClass($resourceClass);
×
NEW
46
        $method = $refl->getMethod('apiResource');
×
NEW
47
        if (!$method->isPublic() || !$method->isStatic()) {
×
NEW
48
            return $propertyNameCollection ?? new PropertyNameCollection();
×
49
        }
50

NEW
51
        $metadataCollection = $method->invoke(null);
×
NEW
52
        if (!\is_array($metadataCollection)) {
×
NEW
53
            $metadataCollection = [$metadataCollection];
×
54
        }
55

NEW
56
        $properties = $propertyNameCollection ? array_flip(iterator_to_array($propertyNameCollection)) : [];
×
57

NEW
58
        foreach ($metadataCollection as $apiProperty) {
×
NEW
59
            if (!$apiProperty instanceof ApiProperty) {
×
NEW
60
                continue;
×
61
            }
62

NEW
63
            if (null !== $propertyName = $apiProperty->getProperty()) {
×
NEW
64
                $properties[$propertyName] = true;
×
65
            }
66
        }
67

NEW
68
        return new PropertyNameCollection(array_keys($properties));
×
69
    }
70
}
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