Passed
Pull Request — 2.4 (#2757)
by Han Hui
03:24
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
trait ToggleableOperationAttributeTrait
19
{
20
    /**
21
     * @var ResourceMetadataFactoryInterface|null
22
     */
23
    private $resourceMetadataFactory;
24
25
    private function isOperationAttributeDisabled(array $attributes, string $attribute, bool $default = false, bool $resourceFallback = true): bool
26
    {
27
        if (null === $this->resourceMetadataFactory) {
28
            return $default;
29
        }
30
31
        $resourceMetadata = $this->resourceMetadataFactory->create($attributes['resource_class']);
32
33
        return !((bool) $resourceMetadata->getOperationAttribute($attributes, $attribute, !$default, $resourceFallback));
34
    }
35
}
36