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 |
||
| 24 | class AirlockAuthenticationKeyConsultantProvider implements UserProviderInterface |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var \Graviton\RestBundle\Model\ModelInterface |
||
| 28 | */ |
||
| 29 | private $documentModel; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param \Graviton\RestBundle\Model\ModelInterface $contract contract to use as documentModel |
||
| 33 | */ |
||
| 34 | public function __construct(ModelInterface $contract) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Loads the user for the given username. |
||
| 41 | * |
||
| 42 | * This method must throw UsernameNotFoundException if the user is not |
||
| 43 | * found. |
||
| 44 | * |
||
| 45 | * @param string $username the consultants username |
||
| 46 | * |
||
| 47 | * @return \Symfony\Component\Security\Core\User\UserInterface |
||
| 48 | * |
||
| 49 | * @see \Symfony\Component\Security\Core\Exception\UsernameNotFoundException |
||
| 50 | * |
||
| 51 | * @throws \Symfony\Component\Security\Core\Exception\UsernameNotFoundException if the user is not found |
||
| 52 | */ |
||
| 53 | public function loadUserByUsername($username) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Finds a contract based on the provided ApiKey. |
||
| 66 | * |
||
| 67 | * @param string $apiKey key from airlock |
||
| 68 | * |
||
| 69 | * @return string |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function getUsernameForApiKey($apiKey) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Refreshes the user for the account interface. |
||
| 84 | * |
||
| 85 | * It is up to the implementation to decide if the user data should be |
||
| 86 | * totally reloaded (e.g. from the database), or if the UserInterface |
||
| 87 | * object can just be merged into some internal array of users / identity |
||
| 88 | * map. |
||
| 89 | * |
||
| 90 | * @param \Symfony\Component\Security\Core\User\UserInterface $user user to refresh |
||
| 91 | * |
||
| 92 | * @return \Symfony\Component\Security\Core\User\UserInterface |
||
| 93 | * |
||
| 94 | * @throws \Symfony\Component\Security\Core\Exception\UnsupportedUserException if the account is not supported |
||
| 95 | */ |
||
| 96 | public function refreshUser(UserInterface $user) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Whether this provider supports the given user class. |
||
| 107 | * |
||
| 108 | * @param string $class class to check for support |
||
| 109 | * |
||
| 110 | * @return bool |
||
| 111 | */ |
||
| 112 | public function supportsClass($class) |
||
| 116 | } |
||
| 117 |
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: