• 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/Metadata/Factory/Property/ClassLevelAttributePropertyNameCollectionFactory.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\Metadata\Factory\Property;
15

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

20
/**
21
 * Gathers "virtual" properties created using the ApiProperty attribute at class level.
22
 */
23
final class ClassLevelAttributePropertyNameCollectionFactory implements PropertyNameCollectionFactoryInterface
24
{
25
    public function __construct(
26
        private readonly ?PropertyNameCollectionFactoryInterface $decorated = null,
27
    ) {
28
    }
×
29

30
    public function create(string $resourceClass, array $options = []): PropertyNameCollection
31
    {
NEW
32
        $parentPropertyNameCollection = $this->decorated?->create($resourceClass, $options);
×
33
        if (!class_exists($resourceClass)) {
×
NEW
34
            return $parentPropertyNameCollection ?? new PropertyNameCollection();
×
35
        }
36

NEW
37
        $properties = $parentPropertyNameCollection ? iterator_to_array($parentPropertyNameCollection) : [];
×
38

39
        $refl = new \ReflectionClass($resourceClass);
×
40
        $attributes = $refl->getAttributes(ApiProperty::class);
×
41
        foreach ($attributes as $attribute) {
×
42
            $instance = $attribute->newInstance();
×
43
            if ($property = $instance->getProperty()) {
×
44
                $properties[] = $property;
×
45
            }
46
        }
47

48
        return new PropertyNameCollection($properties);
×
49
    }
50
}
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