Completed
Push — master ( 2fe979...097c86 )
by diego
06:23
created

Dummy   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 79
Duplicated Lines 3.8 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 9
Bugs 2 Features 1
Metric Value
wmc 12
c 9
b 2
f 1
lcom 1
cbo 1
dl 3
loc 79
ccs 0
cts 25
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
B getConfiguration() 3 13 5
A start() 0 3 1
B processEntry() 0 23 4
A getRandomResult() 0 4 1
A end() 0 3 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
namespace HDNET\Importr\Service\Targets;
3
4
use HDNET\Importr\Domain\Model\Strategy;
5
6
/**
7
 * Description of ExtbaseModel
8
 *
9
 * @author tim
10
 */
11
class Dummy extends AbstractTarget implements TargetInterface
12
{
13
14
    protected $possibleResults = [
15
        TargetInterface::RESULT_IGNORED,
16
        TargetInterface::RESULT_INSERT,
17
        TargetInterface::RESULT_ERROR,
18
        TargetInterface::RESULT_UNSURE,
19
        TargetInterface::RESULT_UPDATE,
20
    ];
21
22
    /**
23
     * @return array
24
     */
25
    public function getConfiguration()
26
    {
27
        $configuration = parent::getConfiguration();
28 View Code Duplication
        if (!isset($configuration['sleepSeconds']) || !is_numeric($configuration['sleepSeconds'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
29
            $configuration['sleepSeconds'] = 1;
30
        }
31
32
        if (!isset($configuration['result']) || !is_numeric($configuration['result'])) {
33
            $configuration['result'] = TargetInterface::RESULT_UNSURE;
34
        }
35
36
        return $configuration;
37
    }
38
39
    /**
40
     * @param Strategy $strategy
41
     *
42
     * @return void
43
     */
44
    public function start(Strategy $strategy)
45
    {
46
    }
47
48
    /**
49
     * @param array $entry
50
     *
51
     * @throws \Exception
52
     * @return int|void
53
     */
54
    public function processEntry(array $entry)
55
    {
56
        $configuration = $this->getConfiguration();
57
        if ($configuration['sleepSeconds'] > 0) {
58
            sleep($configuration['sleepSeconds']);
59
        }
60
61
        if ($configuration['result'] == 'random') {
62
            $configuration['result'] = $this->getRandomResult();
63
        }
64
65
        if (!in_array($configuration['result'], $this->possibleResults)) {
66
            throw new \Exception(
67
                'Invalid result param "' . $configuration['result'] . '". Have to be one of: ' . var_export(
68
                    $results,
69
                    true
70
                ),
71
                12617283
72
            );
73
        }
74
75
        return $configuration['result'];
76
    }
77
78
    /**
79
     * @return int
80
     */
81
    protected function getRandomResult()
82
    {
83
        return $this->possibleResults[rand(0, sizeof($this->possibleResults) - 1)];
84
    }
85
86
    public function end()
87
    {
88
    }
89
}
90