Test Failed
Pull Request — main (#139)
by Daniel
16:46
created

PageDataMetadataStateProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 23
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A provide() 0 7 2
A supports() 0 3 1
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\DataProvider\StateProvider;
15
16
use ApiPlatform\Metadata\CollectionOperationInterface;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\State\ProviderInterface;
19
use Silverback\ApiComponentsBundle\Metadata\Factory\PageDataMetadataFactoryInterface;
20
use Silverback\ApiComponentsBundle\Metadata\PageDataMetadata;
21
use Silverback\ApiComponentsBundle\Metadata\Provider\PageDataMetadataProvider;
22
23
/**
24
 * @author Daniel West <[email protected]>
25
 */
26
class PageDataMetadataStateProvider implements ProviderInterface
27
{
28
    private PageDataMetadataFactoryInterface $pageDataMetadataFactory;
29
    private PageDataMetadataProvider $pageDataMetadataProvider;
30
31
    public function __construct(PageDataMetadataFactoryInterface $pageDataMetadataFactory, PageDataMetadataProvider $pageDataMetadataProvider)
32
    {
33
        $this->pageDataMetadataFactory = $pageDataMetadataFactory;
34
        $this->pageDataMetadataProvider = $pageDataMetadataProvider;
35
    }
36
37
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
38
    {
39
        if ($operation instanceof CollectionOperationInterface) {
40
            return $this->pageDataMetadataProvider->createAll();
41
        }
42
43
        return $this->pageDataMetadataFactory->create($uriVariables['resourceClass']);
44
    }
45
46
    public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, array $context = []): bool
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    public function supports(string $resourceClass, array $uriVariables = [], ?string $operationName = null, /** @scrutinizer ignore-unused */ array $context = []): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $operationName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    public function supports(string $resourceClass, array $uriVariables = [], /** @scrutinizer ignore-unused */ ?string $operationName = null, array $context = []): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $uriVariables is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

46
    public function supports(string $resourceClass, /** @scrutinizer ignore-unused */ array $uriVariables = [], ?string $operationName = null, array $context = []): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        return PageDataMetadata::class === $resourceClass;
49
    }
50
}
51