BackendRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addSearch() 0 4 2
A search() 0 12 2
A count() 0 6 1
1
<?php
2
3
namespace App\Repositories;
4
5
use Doctrine\MongoDB\Query\Builder;
6
use Doctrine\ODM\MongoDB\DocumentRepository;
7
8
class BackendRepository extends DocumentRepository
9
{
10
    public function search(int $page = 1, string $query = null, int $size = 20)
11
    {
12
        $skip = ($page * $size) - $size;
13
        $skip = $skip < 0 ? 0 : $skip;
14
15
        $qb = $this->createQueryBuilder()
16
            ->limit($size)
17
            ->skip($skip);
18
19
        $this->addSearch($qb, $query);
20
21
        return $qb->getQuery()->execute();
22
    }
23
24
    public function count(string $query = null)
25
    {
26
        $qb = $this->createQueryBuilder()->count();
27
        $this->addSearch($qb, $query);
28
29
        return $qb->getQuery()->execute();
30
    }
31
32
    private function addSearch(Builder $qb, string $query = null, string $type = null): void
0 ignored issues
show
Unused Code introduced by
The parameter $type 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

32
    private function addSearch(Builder $qb, string $query = null, /** @scrutinizer ignore-unused */ string $type = null): void

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...
33
    {
34
        if ($query) {
35
            $qb->field('domain')->equals(new \MongoRegex(sprintf('/%s/', $query)));
0 ignored issues
show
Deprecated Code introduced by
The class MongoRegex has been deprecated: This extension that defines this class is deprecated. Instead, the MongoDB extension should be used. Alternatives to this class include: MongoRegex ( Ignorable by Annotation )

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

35
            $qb->field('domain')->equals(/** @scrutinizer ignore-deprecated */ new \MongoRegex(sprintf('/%s/', $query)));
Loading history...
36
        }
37
    }
38
}
39