Passed
Pull Request — master (#2819)
by Han Hui
04:01
created

isOperationAttributeDisabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 4
dl 0
loc 9
rs 10
c 0
b 0
f 0
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