PageDataMetadataProvider::createAll()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 9
ccs 0
cts 6
cp 0
crap 12
rs 10
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