PageDataMetadataProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 25
ccs 0
cts 9
cp 0
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createAll() 0 9 3
1
<?php
2
3
/*
4
 * This file is part of the Silverback API Components Bundle Project
5
 *
6
 * (c) Daniel West <[email protected]>
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 Silverback\ApiComponentsBundle\Metadata\Provider;
15
16
use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
17
use Silverback\ApiComponentsBundle\Entity\Core\PageDataInterface;
18
use Silverback\ApiComponentsBundle\Metadata\Factory\PageDataMetadataFactoryInterface;
19
use Silverback\ApiComponentsBundle\Metadata\PageDataMetadata;
20
21
/**
22
 * @author Daniel West <[email protected]>
23
 */
24
class PageDataMetadataProvider
25
{
26
    private ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory;
27
    private PageDataMetadataFactoryInterface $pageDataMetadataFactory;
28
29
    public function __construct(
30
        ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory,
31
        PageDataMetadataFactoryInterface $pageDataMetadataFactory
32
    ) {
33
        $this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
34
        $this->pageDataMetadataFactory = $pageDataMetadataFactory;
35
    }
36
37
    /**
38
     * @return PageDataMetadata[]|iterable
39
     */
40
    public function createAll(): iterable
41
    {
42
        foreach ($this->resourceNameCollectionFactory->create() as $pageDataResourceClass) {
43
            $reflectionClass = new \ReflectionClass($pageDataResourceClass);
44
            if (!$reflectionClass->implementsInterface(PageDataInterface::class)) {
45
                continue;
46
            }
47
48
            yield $this->pageDataMetadataFactory->create($pageDataResourceClass);
0 ignored issues
show
Bug Best Practice introduced by
The expression yield $this->pageDataMet...$pageDataResourceClass) returns the type Generator which is incompatible with the documented return type Silverback\ApiComponents...DataMetadata[]|iterable.
Loading history...
49
        }
50
    }
51
}
52