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 |
||
| 43 | class MemberRepository extends EntityRepository implements UserProviderInterface |
||
| 44 | { |
||
| 45 | /** |
||
| 46 | * @var EncoderFactoryInterface |
||
| 47 | */ |
||
| 48 | private $encoder_factory; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @param EncoderFactoryInterface $encoder_factory |
||
| 52 | */ |
||
| 53 | 242 | public function setEncoderFactorty(EncoderFactoryInterface $encoder_factory) |
|
| 54 | { |
||
| 55 | 242 | $this->encoder_factory = $encoder_factory; |
|
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Loads the user for the given username. |
||
| 60 | * |
||
| 61 | * This method must throw UsernameNotFoundException if the user is not |
||
| 62 | * found. |
||
| 63 | * |
||
| 64 | * @param string $username The username |
||
| 65 | * |
||
| 66 | * @return UserInterface |
||
| 67 | * |
||
| 68 | * @see UsernameNotFoundException |
||
| 69 | * |
||
| 70 | * @throws UsernameNotFoundException if the user is not found |
||
| 71 | */ |
||
| 72 | 53 | public function loadUserByUsername($username) |
|
| 94 | |||
| 95 | /** |
||
| 96 | * Refreshes the user for the account interface. |
||
| 97 | * |
||
| 98 | * It is up to the implementation to decide if the user data should be |
||
| 99 | * totally reloaded (e.g. from the database), or if the UserInterface |
||
| 100 | * object can just be merged into some internal array of users / identity |
||
| 101 | * map. |
||
| 102 | * |
||
| 103 | * @param UserInterface $user |
||
| 104 | * |
||
| 105 | * @return UserInterface |
||
| 106 | * |
||
| 107 | * @throws UnsupportedUserException if the account is not supported |
||
| 108 | */ |
||
| 109 | 51 | View Code Duplication | public function refreshUser(UserInterface $user) |
| 117 | |||
| 118 | /** |
||
| 119 | * Whether this provider supports the given user class. |
||
| 120 | * |
||
| 121 | * @param string $class |
||
| 122 | * |
||
| 123 | * @return bool |
||
| 124 | */ |
||
| 125 | 1 | public function supportsClass($class) |
|
| 129 | |||
| 130 | /** |
||
| 131 | * @param \Eccube\Entity\Member $Member |
||
| 132 | * |
||
| 133 | * @return void |
||
| 134 | */ |
||
| 135 | 3 | View Code Duplication | public function up(\Eccube\Entity\Member $Member) |
| 164 | |||
| 165 | /** |
||
| 166 | * @param \Eccube\Entity\Member $Member |
||
| 167 | * @return bool |
||
| 168 | */ |
||
| 169 | 3 | View Code Duplication | public function down(\Eccube\Entity\Member $Member) |
| 199 | |||
| 200 | /** |
||
| 201 | * @param \Eccube\Entity\Member $Member |
||
| 202 | * @return bool |
||
| 203 | */ |
||
| 204 | 3 | View Code Duplication | public function save(\Eccube\Entity\Member $Member) |
| 234 | |||
| 235 | /** |
||
| 236 | * @param \Eccube\Entity\Member $Member |
||
| 237 | * @return bool |
||
| 238 | */ |
||
| 239 | 3 | View Code Duplication | public function delete(\Eccube\Entity\Member $Member) |
| 268 | |||
| 269 | /** |
||
| 270 | * saltを生成する |
||
| 271 | * |
||
| 272 | * @param $byte |
||
| 273 | * @return string |
||
| 274 | */ |
||
| 275 | public function createSalt($byte) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * 入力されたパスワードをSaltと暗号化する |
||
| 284 | * |
||
| 285 | * @param $app |
||
| 286 | * @param \Eccube\Entity\Member $Member |
||
| 287 | * @return mixed |
||
| 288 | */ |
||
| 289 | public function encryptPassword(\Eccube\Entity\Member $Member) |
||
| 295 | } |
||
| 296 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.