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 |
||
38 | abstract class Job implements IJob { |
||
39 | |||
40 | /** @var int $id */ |
||
41 | protected $id; |
||
42 | |||
43 | /** @var int $lastRun */ |
||
44 | protected $lastRun; |
||
45 | |||
46 | /** @var mixed $argument */ |
||
47 | protected $argument; |
||
48 | |||
49 | /** @var ITimeFactory */ |
||
50 | protected $time; |
||
51 | |||
52 | /** |
||
53 | * @since 15.0.0 |
||
54 | */ |
||
55 | public function __construct(ITimeFactory $time) { |
||
58 | |||
59 | /** |
||
60 | * The function to prepare the execution of the job. |
||
61 | |||
62 | * |
||
63 | * @param IJobList $jobList |
||
64 | * @param ILogger|null $logger |
||
65 | * |
||
66 | * @since 15.0.0 |
||
67 | */ |
||
68 | public function execute($jobList, ILogger $logger = null) { |
||
91 | |||
92 | /** |
||
93 | * @since 15.0.0 |
||
94 | */ |
||
95 | final public function setId($id) { |
||
98 | |||
99 | /** |
||
100 | * @since 15.0.0 |
||
101 | */ |
||
102 | final public function setLastRun($lastRun) { |
||
105 | |||
106 | /** |
||
107 | * @since 15.0.0 |
||
108 | */ |
||
109 | public function setArgument($argument) { |
||
112 | |||
113 | /** |
||
114 | * @since 15.0.0 |
||
115 | */ |
||
116 | final public function getId(): int { |
||
119 | |||
120 | /** |
||
121 | * @since 15.0.0 |
||
122 | */ |
||
123 | final public function getLastRun(): int { |
||
126 | |||
127 | /** |
||
128 | * @since 15.0.0 |
||
129 | */ |
||
130 | public function getArgument() { |
||
133 | |||
134 | /** |
||
135 | * The actual function that is called to run the job |
||
136 | * |
||
137 | * @param $argument |
||
138 | * @return mixed |
||
139 | * |
||
140 | * @since 15.0.0 |
||
141 | */ |
||
142 | abstract protected function run($argument); |
||
143 | } |
||
144 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: