Completed
Pull Request — master (#40)
by Matthew
17:20
created

BaseDoctrineJobManager   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 87
Duplicated Lines 27.59 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 24
loc 87
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A getFetchCount() 12 12 3
A getSaveCount() 12 12 3
A getObjectManager() 0 4 1
A getRepository() 0 4 1
A flush() 0 4 1
A deleteJob() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Dtc\QueueBundle\Doctrine;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Doctrine\Common\Persistence\ObjectRepository;
7
use Dtc\QueueBundle\Manager\ArchivableJobManager;
8
use Dtc\QueueBundle\Manager\JobTimingManager;
9
use Dtc\QueueBundle\Manager\RunManager;
10
11
abstract class BaseDoctrineJobManager extends ArchivableJobManager
12
{
13
    /** Number of jobs to prune / reset / gather at a time */
14
    const FETCH_COUNT_MIN = 100;
15
    const FETCH_COUNT_MAX = 500;
16
    const SAVE_COUNT_MIN = 10;
17
    const SAVE_COUNT_MAX = 100;
18
19
    /**
20
     * @var ObjectManager
21
     */
22
    protected $objectManager;
23
24
    /**
25
     * DoctrineJobManager constructor.
26
     *
27 20
     * @param RunManager       $runManager
28
     * @param JobTimingManager $jobTimingManager
29
     * @param ObjectManager    $objectManager
30
     * @param $jobClass
31
     * @param $jobArchiveClass
32
     */
33
    public function __construct(
34 20
        RunManager $runManager,
35 20
        JobTimingManager $jobTimingManager,
36 20
        ObjectManager $objectManager,
37
        $jobClass,
38
        $jobArchiveClass
39
    ) {
40
        $this->objectManager = $objectManager;
41 57
        parent::__construct($runManager, $jobTimingManager, $jobClass, $jobArchiveClass);
42
    }
43 57
44 View Code Duplication
    protected function getFetchCount($totalCount)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $fetchCount = intval($totalCount / 10);
47
        if ($fetchCount < self::FETCH_COUNT_MIN) {
48
            $fetchCount = self::FETCH_COUNT_MIN;
49 27
        }
50
        if ($fetchCount > self::FETCH_COUNT_MAX) {
51 27
            $fetchCount = self::FETCH_COUNT_MAX;
52
        }
53
54 15
        return $fetchCount;
55
    }
56 15
57 15 View Code Duplication
    protected function getSaveCount($totalCount)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59 20
        $saveCount = intval($totalCount / 10);
60
        if ($saveCount < self::SAVE_COUNT_MIN) {
61 20
            $saveCount = self::SAVE_COUNT_MIN;
62 20
        }
63 20
        if ($saveCount > self::SAVE_COUNT_MAX) {
64 20
            $saveCount = self::SAVE_COUNT_MAX;
65
        }
66
67
        return $saveCount;
68
    }
69
70
    /**
71
     * @return ObjectManager
72
     */
73
    public function getObjectManager()
74
    {
75
        return $this->objectManager;
76
    }
77
78
    /**
79
     * @return ObjectRepository
80
     */
81
    public function getRepository()
82
    {
83
        return $this->getObjectManager()->getRepository($this->getJobClass());
84
    }
85
86
    protected function flush()
87
    {
88
        $this->getObjectManager()->flush();
89
    }
90
91
    public function deleteJob(\Dtc\QueueBundle\Model\Job $job)
92
    {
93
        $objectManager = $this->getObjectManager();
94
        $objectManager->remove($job);
95
        $objectManager->flush();
96
    }
97
}
98