AdvertRepository::findDepartment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 9
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\AdSearch;
6
use App\Entity\Advert;
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\ORM\Query;
9
use Doctrine\ORM\QueryBuilder;
10
use Symfony\Bridge\Doctrine\RegistryInterface;
11
12
/**
13
 * @method Advert|null find($id, $lockMode = null, $lockVersion = null)
14
 * @method Advert|null findOneBy(array $criteria, array $orderBy = null)
15
 * @method Advert[]    findAll()
16
 * @method Advert[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
17
 */
18
class AdvertRepository extends ServiceEntityRepository
19
{
20
    public function __construct(RegistryInterface $registry)
21
    {
22
        parent::__construct($registry, Advert::class);
23
    }
24
25
    // /**
26
    //  * @return Advert[] Returns an array of Advert objects
27
    //  */
28
    /*
29
    public function findByExampleField($value)
30
    {
31
        return $this->createQueryBuilder('a')
32
            ->andWhere('a.exampleField = :val')
33
            ->setParameter('val', $value)
34
            ->orderBy('a.id', 'ASC')
35
            ->setMaxResults(10)
36
            ->getQuery()
37
            ->getResult()
38
        ;
39
    }
40
    */
41
42
    /*
43
    public function findOneBySomeField($value): ?Advert
44
    {
45
        return $this->createQueryBuilder('a')
46
            ->andWhere('a.exampleField = :val')
47
            ->setParameter('val', $value)
48
            ->getQuery()
49
            ->getOneOrNullResult()
50
        ;
51
    }
52
    */
53
54
    public function findDepartment($department)
55
    {
56
        $query = $this->createQueryBuilder('a')
57
            ->andWhere('a.department = :d')
58
            ->setParameter('d', $department)
59
            ->getQuery()
60
            ->getResult();
61
62
        return $query;
63
64
    }
65
66
    /**
67
     * @param string|null $term
68
     */
69
    public function getWithSearchQueryBuilder(?string $term): QueryBuilder
0 ignored issues
show
Unused Code introduced by
The parameter $term is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

69
    public function getWithSearchQueryBuilder(/** @scrutinizer ignore-unused */ ?string $term): QueryBuilder

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        $qb = $this->createQueryBuilder('a');
72
73
        return $qb
74
            ->orderBy('a.date', 'DESC')
75
            ;
76
    }
77
78
    /**
79
     * @param string|null $term
80
     */
81
    public function getByDepartmentQueryBuilder(?string $department): QueryBuilder
82
    {
83
        $qb = $this->createQueryBuilder('a')
84
            ->andWhere('a.department LIKE :department')
85
            ->setParameter('department', $department)
86
            ->getQuery()
87
            ->getResult();
88
89
        return $qb;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $qb could return the type array which is incompatible with the type-hinted return Doctrine\ORM\QueryBuilder. Consider adding an additional type-check to rule them out.
Loading history...
90
    }
91
92
}
93