Passed
Pull Request — master (#6835)
by Angel Fernando Quiroz
10:09
created

PortfolioRepository::findItemsByUser()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 20
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
c 0
b 0
f 0
nc 4
nop 5
dl 0
loc 20
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Repository\Node;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Chamilo\CoreBundle\Entity\Portfolio;
11
use Chamilo\CoreBundle\Entity\Session;
12
use Chamilo\CoreBundle\Entity\User;
13
use Chamilo\CoreBundle\Repository\ResourceRepository;
14
use Doctrine\Persistence\ManagerRegistry;
15
16
class PortfolioRepository extends ResourceRepository
17
{
18
    public function __construct(ManagerRegistry $registry)
19
    {
20
        parent::__construct($registry, Portfolio::class);
21
    }
22
23
    public function findItemsByUser(
24
        User $user,
25
        ?Course $course,
26
        ?Session $session,
27
        ?array $orderBy = null,
28
        array $visibility = []
29
    ): array {
30
        $criteria = [];
31
        $criteria['user'] = $user;
32
33
        if ($course) {
34
            $criteria['course'] = $course;
35
            $criteria['session'] = $session;
36
        }
37
38
        if ($visibility) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $visibility of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39
            $criteria['visibility'] = $visibility;
40
        }
41
42
        return $this->findBy($criteria, $orderBy);
43
    }
44
}
45