• 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/ConcernsResourceMetadataCollectionFactory.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\Resource\Factory\MetadataCollectionFactoryTrait;
18
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
19
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
20

21
/**
22
 * Creates a resource metadata from {@see IsApiResource} concerns.
23
 *
24
 * @author Kévin Dunglas <kevin@dunglas.dev>
25
 */
26
final class ConcernsResourceMetadataCollectionFactory implements ResourceMetadataCollectionFactoryInterface
27
{
28
    use MetadataCollectionFactoryTrait;
29

30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function create(string $resourceClass): ResourceMetadataCollection
34
    {
NEW
35
        $resourceMetadataCollection = $this->decorated?->create($resourceClass) ?? new ResourceMetadataCollection(
×
NEW
36
            $resourceClass
×
NEW
37
        );
×
38

NEW
39
        if (!method_exists($resourceClass, 'apiResource')) {
×
NEW
40
            return $resourceMetadataCollection;
×
41
        }
42

NEW
43
        $metadataCollection = $resourceClass::apiResource();
×
NEW
44
        if (!\is_array($metadataCollection)) {
×
NEW
45
            $metadataCollection = [$metadataCollection];
×
46
        }
47

NEW
48
        foreach ($this->buildResourceOperations($metadataCollection, $resourceClass) as $resource) {
×
NEW
49
            $resourceMetadataCollection[] = $resource;
×
50
        }
51

NEW
52
        return $resourceMetadataCollection;
×
53
    }
54
}
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