Completed
Push — develop ( cba78f...09bcdb )
by Nicolas
12:47
created

Pool   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 39.22 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 2
dl 20
loc 51
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 9 2
A remove() 8 8 2
A get() 12 12 3
A run() 0 8 2

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 devtransition\jobbers;
4
5
use devtransition\jobbers\exception\DublciateException;
6
7
class Pool
8
{
9
10
    /**
11
     * @var Job[]
12
     */
13
    private $_jobs = [];
14
    private $_results = [];
15
16
    public function add(Job &$job)
17
    {
18
        if (isset($this->_jobs[$job->getId()])) {
19
            throw new DublciateException('job with given id already exists in pool');
20
        }
21
        $this->_jobs[$job->getId()] = $job;
22
        $this->_results[$job->getId()] = &$job->getResult();
23
        return true;
24
    }
25
26 View Code Duplication
    public function remove($id)
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...
27
    {
28
        if (!isset($this->_jobs[$id])) {
29
            throw new \InvalidArgumentException('id does not exist in pool');
30
        }
31
        unset($this->_jobs[$id]);
32
        return true;
33
    }
34
35 View Code Duplication
    public function &get($id = null)
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...
36
    {
37
        if ($id) {
38
            if (!isset($this->_jobs[$id])) {
39
                throw new \InvalidArgumentException('id does not exist in pool');
40
            }
41
            return $this->_results[$id];
42
        } else {
43
            // All
44
            return $this->_results;
45
        }
46
    }
47
48
    public function &run()
49
    {
50
        foreach ($this->_jobs as $id => $job) {
51
            $job->run();
52
        }
53
54
        return $this->_results;
55
    }
56
57
}