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 |
||
| 22 | class AuthenticationManager extends Base |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * Event names. |
||
| 26 | * |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | const EVENT_SUCCESS = 'auth.success'; |
||
| 30 | const EVENT_FAILURE = 'auth.failure'; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * List of authentication providers. |
||
| 34 | * |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | private $providers = []; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Register a new authentication provider. |
||
| 41 | * |
||
| 42 | * @param AuthenticationProviderInterface $provider |
||
| 43 | * |
||
| 44 | * @return AuthenticationManager |
||
| 45 | */ |
||
| 46 | public function register(AuthenticationProviderInterface $provider) |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Register a new authentication provider. |
||
| 55 | * |
||
| 56 | * @param string $name |
||
| 57 | * |
||
| 58 | * @return AuthenticationProviderInterface|OAuthAuthenticationProviderInterface|PasswordAuthenticationProviderInterface|PreAuthenticationProviderInterface|OAuthAuthenticationProviderInterface |
||
| 59 | */ |
||
| 60 | public function getProvider($name) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Execute providers that are able to validate the current session. |
||
| 71 | * |
||
| 72 | * @return bool |
||
| 73 | */ |
||
| 74 | public function checkCurrentSession() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * Execute pre-authentication providers. |
||
| 93 | * |
||
| 94 | * @return bool |
||
| 95 | */ |
||
| 96 | public function preAuthentication() |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Execute username/password authentication providers. |
||
| 111 | * |
||
| 112 | * @param string $username |
||
| 113 | * @param string $password |
||
| 114 | * @param bool $fireEvent |
||
| 115 | * |
||
| 116 | * @return bool |
||
| 117 | */ |
||
| 118 | public function passwordAuthentication($username, $password, $fireEvent = true) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Perform OAuth2 authentication. |
||
| 142 | * |
||
| 143 | * @param string $name |
||
| 144 | * |
||
| 145 | * @return bool |
||
| 146 | */ |
||
| 147 | public function oauthAuthentication($name) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Get the last Post-Authentication provider. |
||
| 164 | * |
||
| 165 | * @return PostAuthenticationProviderInterface |
||
| 166 | */ |
||
| 167 | public function getPostAuthenticationProvider() |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Filter registered providers by interface type. |
||
| 180 | * |
||
| 181 | * @param string $interface |
||
| 182 | * |
||
| 183 | * @return array |
||
| 184 | */ |
||
| 185 | private function filterProviders($interface) |
||
| 193 | } |
||
| 194 |
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.