Passed
Pull Request — master (#6239)
by
unknown
08:01
created

DocumentLearningPathUsageAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 14
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CoreBundle\Controller\Api;
8
9
use Chamilo\CourseBundle\Repository\CLpItemRepository;
10
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
11
use Symfony\Component\HttpFoundation\JsonResponse;
12
use Symfony\Component\HttpKernel\Attribute\AsController;
13
14
#[AsController]
15
class DocumentLearningPathUsageAction extends AbstractController
16
{
17
    public function __construct(
18
        private CLpItemRepository $lpItemRepo
19
    ) {}
20
21
    public function __invoke($iid): JsonResponse
22
    {
23
        $lpUsages = $this->lpItemRepo->findLearningPathsUsingDocument((int) $iid);
24
25
        return new JsonResponse([
26
            'usedInLp' => !empty($lpUsages),
27
            'lpList' => $lpUsages,
28
        ]);
29
    }
30
}
31