PlanRepository::getLocalPlans()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the wow-apps/symfony-proxybonanza project
4
 * https://github.com/wow-apps/symfony-proxybonanza
5
 *
6
 * (c) 2016 WoW-Apps
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WowApps\ProxybonanzaBundle\Repository;
13
14
use WowApps\ProxybonanzaBundle\Entity\Plan;
15
16
/**
17
 * Class PlanRepository
18
 * @author Alexey Samara <[email protected]>
19
 * @package wow-apps/symfony-proxybonanza
20
 */
21
class PlanRepository extends AbstractRepository
22
{
23
    public function empty()
24
    {
25
        $queryBuilder = $this->pdoDB->createQueryBuilder();
0 ignored issues
show
Bug introduced by
The method createQueryBuilder() does not exist on Doctrine\DBAL\Driver\PDOConnection. ( Ignorable by Annotation )

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

25
        /** @scrutinizer ignore-call */ 
26
        $queryBuilder = $this->pdoDB->createQueryBuilder();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
26
        $queryBuilder->delete(Plan::TABLE_NAME);
27
        $queryBuilder->execute();
28
    }
29
30
    /**
31
     * @param \ArrayObject|Plan[] $pbPlans
32
     * @return bool
33
     */
34
    public function insertPlans(\ArrayObject $pbPlans): bool
35
    {
36
        if (!$pbPlans->count()) {
37
            return false;
38
        }
39
40
        foreach ($pbPlans as $pbPlan) {
41
            $this->entityManager->persist($pbPlan);
42
        }
43
44
        $this->entityManager->flush();
45
46
        return true;
47
    }
48
49
    /**
50
     * @param int $planId
51
     * @return Plan
52
     */
53
    public function getLocalPlan(int $planId): Plan
54
    {
55
        /** @var Plan $pbPlan */
56
        $pbPlan = $this->findOneBy(['id' => $planId]);
57
        return $pbPlan;
58
    }
59
60
    /**
61
     * @return \ArrayObject|Plan[]
62
     */
63
    public function getLocalPlans(): \ArrayObject
64
    {
65
        $pbPlans = new \ArrayObject();
66
67
        /** @var Plan $plan */
68
        foreach ($this->findAll() as $plan) {
69
            $pbPlans->offsetSet($plan->getId(), $plan);
70
        }
71
72
        return $pbPlans;
73
    }
74
}
75