Passed
Pull Request — master (#2819)
by Han Hui
03:28
created

ToggleableOperationAttributeTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A isOperationAttributeDisabled() 0 9 2
1
<?php
2
3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <[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 ApiPlatform\Core\Metadata\Resource;
15
16
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
17
18
/**
19
 * @internal
20
 */
21
trait ToggleableOperationAttributeTrait
22
{
23
    /**
24
     * @var ResourceMetadataFactoryInterface|null
25
     */
26
    private $resourceMetadataFactory;
27
28
    private function isOperationAttributeDisabled(array $attributes, string $attribute, bool $default = false, bool $resourceFallback = true): bool
29
    {
30
        if (null === $this->resourceMetadataFactory) {
31
            return $default;
32
        }
33
34
        $resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);
35
36
        return !((bool) $resourceMetadata->getOperationAttribute($attributes, $attribute, !$default, $resourceFallback));
37
    }
38
}
39