Completed
Push — master ( c5110b...a167e6 )
by Valentyn
13:46
created

CountryRepository::findAllByName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 0
cts 7
cp 0
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Countries\Repository;
6
7
use App\Countries\Entity\Country;
8
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
9
use Symfony\Bridge\Doctrine\RegistryInterface;
10
11
/**
12
 * @method Country|null find($id, $lockMode = null, $lockVersion = null)
13
 * @method Country|null findOneBy(array $criteria, array $orderBy = null)
14
 * @method Country[]    findAll()
15
 * @method Country[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
16
 */
17
class CountryRepository extends ServiceEntityRepository
18
{
19
    public function __construct(RegistryInterface $registry)
20
    {
21
        parent::__construct($registry, Country::class);
22
    }
23
24
    public function findOneByCode(string $code): ?Country
25
    {
26
        return $this->findOneBy([
27
            'code' => $code,
28
        ]);
29
    }
30
31
    public function findAllByName(string $name): array
32
    {
33
        return $this->createQueryBuilder('c')
34
            ->select('c')
35
            ->where('c.name LIKE :name')
36
            ->setParameter('name', "%{$name}%")
37
            ->getQuery()
38
            ->getResult();
39
    }
40
}
41