Completed
Push — master ( af13d1...2fe979 )
by diego
03:25
created

Dummy::processEntry()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 7
Bugs 1 Features 1
Metric Value
c 7
b 1
f 1
dl 0
loc 23
ccs 0
cts 12
cp 0
rs 8.7972
cc 4
eloc 13
nc 8
nop 1
crap 20
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
        $configuration['sleepSeconds'] = (isset($configuration['sleepSeconds'])) ? (int)$configuration['sleepSeconds'] : 1;
29
        $configuration['result'] = (isset($configuration['result'])) ? (int)$configuration['result'] : 'unsure';
30
        return $configuration;
31
    }
32
33
    /**
34
     * @param Strategy $strategy
35
     *
36
     * @return void
37
     */
38
    public function start(Strategy $strategy)
39
    {
40
    }
41
42
    /**
43
     * @param array $entry
44
     *
45
     * @throws \Exception
46
     * @return int|void
47
     */
48
    public function processEntry(array $entry)
49
    {
50
        $configuration = $this->getConfiguration();
51
        if ($configuration['sleepSeconds'] > 0) {
52
            sleep($configuration['sleepSeconds']);
53
        }
54
55
        if ($configuration['result'] == 'random') {
56
            $configuration['result'] = $this->possibleResults[rand(0, sizeof($this->possibleResults) - 1)];
57
        }
58
59
        if (!in_array($configuration['result'], $this->possibleResults)) {
60
            throw new \Exception(
61
                'Invalid result param "' . $configuration['result'] . '". Have to be one of: ' . var_export(
62
                    $results,
63
                    true
64
                ),
65
                12617283
66
            );
67
        }
68
69
        return $configuration['result'];
70
    }
71
72
    public function end()
73
    {
74
    }
75
}
76