Passed
Push — dependabot/npm_and_yarn/cross-... ( ad80c0...c9e4a1 )
by
unknown
15:20 queued 04:46
created

SkillTreeStateProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 16
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A provide() 0 10 2
A __construct() 0 3 1
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\Operation;
10
use ApiPlatform\State\ProviderInterface;
11
use Chamilo\CoreBundle\Entity\Skill;
12
use Chamilo\CoreBundle\Repository\SkillRepository;
13
use Doctrine\Common\Collections\Collection;
14
15
/**
16
 * @implements ProviderInterface<Skill>
17
 */
18
readonly class SkillTreeStateProvider implements ProviderInterface
19
{
20
    public function __construct(
21
        private SkillRepository $skillRepo,
22
    ) {}
23
24
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|Collection
25
    {
26
        /** @var Skill $root */
27
        $root = $this->skillRepo->findOneBy([], ['id' => 'ASC']);
28
29
        if (!$root) {
0 ignored issues
show
introduced by
$root is of type Chamilo\CoreBundle\Entity\Skill, thus it always evaluated to true.
Loading history...
30
            return [];
31
        }
32
33
        return $root->getChildSkills();
34
    }
35
}
36