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'])) { |
|
|
|
|
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
|
|
|
|
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.