ImportRotator   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 54
ccs 0
cts 23
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getEventDispatcher() 0 4 1
A rotate() 0 17 3
1
<?php
2
3
namespace TreeHouse\IoBundle\Import;
4
5
use Symfony\Bridge\Doctrine\RegistryInterface;
6
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7
use TreeHouse\IoBundle\Entity\Feed;
8
use TreeHouse\IoBundle\Entity\ImportRepository;
9
use TreeHouse\IoBundle\Import\Event\ImportEvent;
10
11
class ImportRotator
12
{
13
    /**
14
     * @var RegistryInterface
15
     */
16
    protected $doctrine;
17
18
    /**
19
     * @var EventDispatcherInterface
20
     */
21
    protected $eventDispatcher;
22
23
    /**
24
     * @param RegistryInterface        $doctrine
25
     * @param EventDispatcherInterface $dispatcher
26
     */
27
    public function __construct(RegistryInterface $doctrine, EventDispatcherInterface $dispatcher)
28
    {
29
        $this->doctrine = $doctrine;
30
        $this->eventDispatcher = $dispatcher;
31
    }
32
33
    /**
34
     * @return EventDispatcherInterface
35
     */
36
    public function getEventDispatcher()
37
    {
38
        return $this->eventDispatcher;
39
    }
40
41
    /**
42
     * Rotates imported feeds.
43
     *
44
     * @param Feed $feed The feed to rotate imports for
45
     * @param int  $max  The number of imports to keep
46
     */
47
    public function rotate(Feed $feed, $max = 4)
48
    {
49
        /** @var ImportRepository $repo */
50
        $repo = $this->doctrine->getRepository('TreeHouseIoBundle:Import');
51
        $imports = $repo->findCompletedByFeed($feed);
52
53
        if (sizeof($imports) <= $max) {
54
            return;
55
        }
56
57
        $manager = $this->doctrine->getManager();
58
        foreach (array_slice($imports, $max) as $import) {
59
            $this->eventDispatcher->dispatch(ImportEvents::IMPORT_ROTATE, new ImportEvent($import));
0 ignored issues
show
Documentation introduced by
new \TreeHouse\IoBundle\...nt\ImportEvent($import) is of type object<TreeHouse\IoBundl...port\Event\ImportEvent>, but the function expects a null|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
            $manager->remove($import);
61
            $manager->flush();
62
        }
63
    }
64
}
65