PaymentRepository::findByIds()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Entity;
4
5
use Doctrine\Common\Persistence\ManagerRegistry;
6
use Doctrine\ORM\QueryBuilder;
7
use Knp\Component\Pager\Pagination\PaginationInterface;
8
use Knp\Component\Pager\PaginatorInterface;
9
use Lexik\Bundle\FormFilterBundle\Filter\FilterBuilderUpdaterInterface;
10
use Symfony\Component\Form\FormInterface;
11
use Symfony\Component\HttpFoundation\Request;
12
13
class PaymentRepository extends EntityRepository
14
{
15
    /**
16
     * @var FilterBuilderUpdaterInterface
17
     */
18
    protected $filterBuilderUpdater;
19
20
    public function __construct(ManagerRegistry $managerRegistry, PaginatorInterface $paginator, string $class, FilterBuilderUpdaterInterface $filterBuilderUpdater)
21
    {
22
        $this->filterBuilderUpdater = $filterBuilderUpdater;
23
24
        parent::__construct($managerRegistry, $paginator, $class);
25
    }
26
27
    /**
28
     * @param $id
29
     *
30
     * @return null|Payment
31
     */
32
    public function findByOrderIdOrAltapayId($id): ?Payment
33
    {
34
        /** @var Payment $payment */
35
        $payment = $this->findOneBy([
36
            'orderId' => $id,
37
        ]);
38
39
        if (!$payment) {
40
            /** @var Payment $payment */
41
            $payment = $this->findOneBy([
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $payment is correct as $this->findOneBy(array('altapayId' => $id)) (which targets Loevgaard\DandomainAltap...Repository::findOneBy()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
                'altapayId' => $id,
43
            ]);
44
        }
45
46
        return $payment;
47
    }
48
49
    /**
50
     * @param array $ids
51
     * @return Payment[]
52
     */
53
    public function findByIds(array $ids) : array
54
    {
55
        $qb = $this->getQueryBuilder('p');
56
        $qb->where($qb->expr()->in('p.id', ':ids'));
57
        $qb->setParameter('ids', $ids);
58
59
        return $qb->getQuery()->getResult();
60
    }
61
62
    public function findAllWithPagingAndFilter($page = 1, $itemsPerPage = 100, array $orderBy = [], FormInterface $filterForm, Request $request, QueryBuilder $qb = null): PaginationInterface
63
    {
64
        if (!$qb) {
65
            $qb = $this->getQueryBuilder('e');
66
        }
67
68
        if ($request->query->has($filterForm->getName())) {
69
            // manually bind values from the request
70
            $filterForm->submit($request->query->get($filterForm->getName()));
71
72
            // build the query from the given form object
73
            $this->filterBuilderUpdater->addFilterConditions($filterForm, $qb);
74
        }
75
76
        foreach ($orderBy as $field => $direction) {
77
            $qb->addOrderBy($field, $direction);
78
        }
79
80
        $objs = $this->paginator->paginate(
81
            $qb,
82
            $page,
83
            $itemsPerPage
84
        );
85
86
        return $objs;
87
    }
88
}
89