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 namespace Limoncello\Validation\Rules\Comparisons; |
||
26 | final class ScalarInValues extends BaseOneValueComparision |
||
27 | { |
||
28 | /** |
||
29 | * @param mixed $scalars |
||
30 | */ |
||
31 | public function __construct(array $scalars) |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | View Code Duplication | public static function compare($value, ContextInterface $context): bool |
|
54 | |||
55 | /** |
||
56 | * @param mixed $value |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | private static function isValidType($value): bool |
||
64 | } |
||
65 |
Late static binding only has effect in subclasses. A
final
class cannot be extended anymore so late static binding cannot occurr. Consider replacingstatic::
withself::
.To learn more about late static binding, please refer to the PHP core documentation.