Passed
Push — master ( 745178...3deda8 )
by Alexey
03:44
created

ProxiesRepository   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
B insertProxies() 0 21 5
A getLocalProxies() 0 16 3
A empty() 0 5 1
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
use WowApps\ProxybonanzaBundle\Entity\Proxy;
16
17
/**
18
 * Class ProxiesRepository
19
 * @author Alexey Samara <[email protected]>
20
 * @package wow-apps/symfony-proxybonanza
21
 */
22
class ProxiesRepository extends AbstractRepository
23
{
24
    public function empty()
25
    {
26
        $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

26
        /** @scrutinizer ignore-call */ 
27
        $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...
27
        $queryBuilder->delete(Proxy::TABLE_NAME);
28
        $queryBuilder->execute();
29
    }
30
31
    /**
32
     * @param \ArrayObject|Plan[] $pbPlans
33
     * @return bool
34
     */
35
    public function insertProxies(\ArrayObject $pbPlans): bool
36
    {
37
        if (!$pbPlans->count()) {
38
            return false;
39
        }
40
41
        /** @var Plan $pbPlan */
42
        foreach ($pbPlans as $pbPlan) {
43
            if (!$pbPlan->getProxy()->count()) {
44
                continue;
45
            }
46
47
            /** @var Proxy $proxy */
48
            foreach ($pbPlan->getProxy() as $proxy) {
49
                $this->entityManager->persist($proxy);
50
            }
51
        }
52
53
        $this->entityManager->flush();
54
55
        return true;
56
    }
57
58
    /**
59
     * @param Plan|null $pbPlan
60
     * @return \ArrayObject|Proxy[]
61
     */
62
    public function getLocalProxies(Plan $pbPlan = null): \ArrayObject
63
    {
64
        $proxies = new \ArrayObject();
65
66
        if (is_null($pbPlan)) {
67
            $doctrineResult = $this->findAll();
68
        } else {
69
            $doctrineResult = $this->findBy(['proxyPlan' => $pbPlan->getId()]);
70
        }
71
72
        /** @var Proxy $proxy */
73
        foreach ($doctrineResult as $proxy) {
74
            $proxies->offsetSet($proxy->getProxyId(), $proxy);
75
        }
76
77
        return $proxies;
78
    }
79
}
80