1
|
|
|
<?php |
2
|
|
|
namespace rtens\domin\reflection; |
3
|
|
|
|
4
|
|
|
use rtens\domin\reflection\types\TypeFactory; |
5
|
|
|
|
6
|
|
|
class GenericObjectAction extends ObjectAction { |
7
|
|
|
|
8
|
|
|
/** @var callable */ |
9
|
|
|
private $execute; |
10
|
|
|
|
11
|
|
|
/** @var GenericAction */ |
12
|
|
|
private $generic; |
13
|
|
|
|
14
|
|
View Code Duplication |
public function __construct($class, TypeFactory $types, CommentParser $parser, callable $execute) { |
|
|
|
|
15
|
|
|
parent::__construct($class, $types, $parser); |
16
|
|
|
$this->execute = $execute; |
17
|
|
|
$this->generic = new GenericAction($this); |
18
|
|
|
$this->generic |
19
|
|
|
->setCaption(parent::caption()) |
|
|
|
|
20
|
|
|
->setDescription(parent::description()) |
|
|
|
|
21
|
|
|
->setParameters(parent::parameters()) |
|
|
|
|
22
|
|
|
->setModifying(parent::isModifying()) |
|
|
|
|
23
|
|
|
->setExecute(function ($parameters) { |
24
|
|
|
return parent::execute($parameters); |
25
|
|
|
}) |
26
|
|
|
->setFill(function ($parameters) { |
27
|
|
|
return $parameters; |
28
|
|
|
}); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function generic() { |
32
|
|
|
return $this->generic; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
protected function executeWith($object) { |
36
|
|
|
return call_user_func($this->execute, $object); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function execute(array $parameters) { |
40
|
|
|
return $this->generic->execute($parameters); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function caption() { |
44
|
|
|
return $this->generic->caption(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function description() { |
48
|
|
|
return $this->generic->description(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function parameters() { |
52
|
|
|
return $this->generic->parameters(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function fill(array $parameters) { |
56
|
|
|
return $this->generic->fill(parent::fill($parameters)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function isModifying() { |
60
|
|
|
return $this->generic->isModifying(); |
61
|
|
|
} |
62
|
|
|
} |
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.