Passed
Push — master ( 3efddf...ac4561 )
by Angel Fernando Quiroz
07:17
created

SocialPostStateProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\State;
8
9
use ApiPlatform\Metadata\CollectionOperationInterface;
10
use ApiPlatform\Metadata\Operation;
11
use ApiPlatform\State\ProviderInterface;
12
use Chamilo\CoreBundle\Settings\SettingsManager;
13
use Symfony\Component\DependencyInjection\Attribute\Autowire;
14
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
15
16
class SocialPostStateProvider implements ProviderInterface
17
{
18
    public function __construct(
19
        #[Autowire(service: 'api_platform.doctrine.orm.state.item_provider')]
20
        private readonly ProviderInterface $itemProvider,
21
        #[Autowire(service: 'api_platform.doctrine.orm.state.collection_provider')]
22
        private readonly ProviderInterface $collectionProvider,
23
        private readonly SettingsManager $settingsManager,
24
    ) {}
25
26
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
27
    {
28
        if ('true' !== $this->settingsManager->getSetting('social.allow_social_tool')) {
29
            throw new AccessDeniedHttpException();
30
        }
31
32
        if ($operation instanceof CollectionOperationInterface) {
33
            return $this->collectionProvider->provide($operation, $uriVariables, $context);
34
        }
35
36
        return $this->itemProvider->provide($operation, $uriVariables, $context);
37
    }
38
}
39