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 |
||
| 41 | abstract class ConfigHandler extends BaseConfigHandler implements LegacyConfigHandlerInterface |
||
| 42 | { |
||
| 43 | /** |
||
| 44 | * @var string An absolute filesystem path to a validation filename. |
||
| 45 | */ |
||
| 46 | protected $validationFile = null; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var string A class name of the class which should be used to parse |
||
| 50 | * Input files of this config handler. |
||
| 51 | */ |
||
| 52 | protected $parser = null; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Retrieve the parameter node values of the given item's parameters element. |
||
| 56 | * |
||
| 57 | * @param ConfigValueHolder $itemNode The node that contains a parameters child. |
||
| 58 | * @param array $oldValues As associative array of parameters that will |
||
| 59 | * be overwritten if appropriate. |
||
| 60 | * @param boolean $literalize Whether or not values should be literalized. |
||
| 61 | * |
||
| 62 | * @return array An associative array of parameters |
||
| 63 | * |
||
| 64 | * @author Dominik del Bondio <[email protected]> |
||
| 65 | * @since 0.11.0 |
||
| 66 | */ |
||
| 67 | protected function getItemParameters($itemNode, $oldValues = array(), $literalize = true) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Initialize this ConfigHandler. |
||
| 99 | * |
||
| 100 | * @param string $validationFile The path to a validation file for this config handler. |
||
| 101 | * @param string $parser The parser class to use. |
||
| 102 | * @param array $parameters An associative array of initialization parameters. |
||
| 103 | * |
||
| 104 | * @throws <b>InitializationException</b> If an error occurs while |
||
| 105 | * initializing the |
||
| 106 | * ConfigHandler |
||
| 107 | * |
||
| 108 | * @author Dominik del Bondio <[email protected]> |
||
| 109 | * @since 0.9.0 |
||
| 110 | */ |
||
| 111 | public function initialize($validationFile = null, $parser = null, $parameters = array()) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Retrieves the stored validation filename. |
||
| 120 | * |
||
| 121 | * @return string An absolute filesystem path to a validation filename. |
||
| 122 | * |
||
| 123 | * @author Dominik del Bondio <[email protected]> |
||
| 124 | * @since 0.11.0 |
||
| 125 | */ |
||
| 126 | public function getValidationFile() |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Builds a proper regular expression from the input pattern to test against |
||
| 133 | * the given subject. This is for "environment" and "context" attributes of |
||
| 134 | * configuration blocks in the files. |
||
| 135 | * |
||
| 136 | * @param string $pattern A regular expression chunk without delimiters/anchors. |
||
| 137 | * @param string $subject The subject to test against |
||
| 138 | * |
||
| 139 | * @return bool Whether or not the subject matched the pattern. |
||
| 140 | * |
||
| 141 | * @see XmlConfigParser::testPattern() |
||
| 142 | * |
||
| 143 | * @author David Zülke <[email protected]> |
||
| 144 | * @since 0.11.0 |
||
| 145 | */ |
||
| 146 | public static function testPattern($pattern, $subject) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Returns a properly ordered array of ConfigValueHolder configuration |
||
| 153 | * elements for given env and context. |
||
| 154 | * |
||
| 155 | * @param ConfigValueHolder $configurations The root config element |
||
| 156 | * @param string $environment An environment name. |
||
| 157 | * @param string $context A context name. |
||
| 158 | * @param bool $autoloadParser Whether the parser class should be |
||
| 159 | * autoloaded or not. |
||
| 160 | * |
||
| 161 | * @return ConfigValueHolder[] An array of ConfigValueHolder configuration elements. |
||
| 162 | * |
||
| 163 | * @author David Zülke <[email protected]> |
||
| 164 | * @since 0.11.0 |
||
| 165 | */ |
||
| 166 | public function orderConfigurations(ConfigValueHolder $configurations, $environment = null, $context = null, $autoloadParser = true) |
||
| 199 | } |
||
| 200 |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.