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 |
||
14 | class JsonDataNodeValidator |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @param JsonDataNode $data_node |
||
19 | * @return bool returns true if data array is safe to set, false if overwrite will occur |
||
20 | * @throws DomainException throws exception if WP_DEBUG is true |
||
21 | */ |
||
22 | public function dataArrayEmpty(JsonDataNode $data_node) |
||
31 | |||
32 | /** |
||
33 | * @param array $data data array to check for property key |
||
34 | * @param string $key value for the key being checked for |
||
35 | * @param string $type the type of key and/or the data being checked |
||
36 | * @return bool returns true if property is safe to write, false if overwrite will occur |
||
37 | * @throws DomainException throws exception if WP_DEBUG is true |
||
38 | */ |
||
39 | public function propertyNotSet(array $data, $key, $type = 'key') |
||
47 | |||
48 | |||
49 | /** |
||
50 | * @param string $key value for the key being checked for |
||
51 | * @param string $type the type of key and/or the data being checked |
||
52 | * @throws DomainException throws exception if WP_DEBUG is true |
||
53 | */ |
||
54 | public function overwriteError($key, $type) |
||
73 | |||
74 | |||
75 | /** |
||
76 | * @param string $property name for the key being checked for |
||
77 | * @param string $type the type of key and/or the data being checked |
||
78 | * @param bool $throw if true [default] and WP_DEBUG is also true, then will throw exceptions |
||
79 | * @return bool returns true if property is set, false if property is missing |
||
80 | * @throws DomainException throws exception if WP_DEBUG is true |
||
81 | */ |
||
82 | View Code Duplication | public function validateCriticalProperty($property, $type, $throw = true) |
|
104 | } |
||
105 |