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 | abstract class RepositoryExecutor extends AbstractExecutor |
||
| 15 | { |
||
| 16 | use RepositoryUserSetterTrait; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Constant defining the default language code (used if not specified by the migration or on the command line) |
||
| 20 | */ |
||
| 21 | const DEFAULT_LANGUAGE_CODE = 'eng-GB'; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * The default Admin user Id, used when no Admin user is specified |
||
| 25 | */ |
||
| 26 | const ADMIN_USER_ID = 14; |
||
| 27 | |||
| 28 | /** Used if not specified by the migration */ |
||
| 29 | const USER_CONTENT_TYPE = 'user'; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array $dsl The parsed DSL instruction array |
||
| 33 | */ |
||
| 34 | //protected $dsl; |
||
| 35 | |||
| 36 | /** @var array $context The context (configuration) for the execution of the current step */ |
||
| 37 | //protected $context; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * The eZ Publish 5 API repository. |
||
| 41 | * |
||
| 42 | * @var \eZ\Publish\API\Repository\Repository |
||
| 43 | */ |
||
| 44 | protected $repository; |
||
| 45 | |||
| 46 | /** @var ReferenceResolverBagInterface $referenceResolver */ |
||
| 47 | protected $referenceResolver; |
||
| 48 | |||
| 49 | // to redefine in subclasses if they don't support all methods, or if they support more... |
||
| 50 | protected $supportedActions = array( |
||
| 51 | 'create', 'update', 'delete' |
||
| 52 | ); |
||
| 53 | |||
| 54 | public function setRepository(Repository $repository) |
||
| 58 | |||
| 59 | public function setReferenceResolver(ReferenceResolverBagInterface $referenceResolver) |
||
| 63 | |||
| 64 | public function execute(MigrationStep $step) |
||
| 98 | |||
| 99 | 9 | /** |
|
| 100 | 9 | * Method that each executor (subclass) has to implement. |
|
| 101 | 9 | * |
|
| 102 | 2 | * It is used to set references based on the DSL instructions executed in the current step, for later steps to reuse. |
|
| 103 | 2 | * |
|
| 104 | * @throws \InvalidArgumentException when trying to set a reference to an unsupported attribute. |
||
| 105 | 9 | * @param $object |
|
| 106 | * @return boolean |
||
| 107 | 9 | */ |
|
| 108 | abstract protected function setReferences($object, $step); |
||
| 109 | 9 | ||
| 110 | 9 | /** |
|
| 111 | 2 | * @param MigrationStep $step |
|
| 112 | 3 | * @return string |
|
| 113 | */ |
||
| 114 | protected function getLanguageCode($step) |
||
| 118 | 8 | ||
| 119 | /** |
||
| 120 | * @param array $context |
||
| 121 | * @return string |
||
| 122 | */ |
||
| 123 | protected function getLanguageCodeFromContext($context) |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @param MigrationStep $step |
||
| 130 | * @return string |
||
| 131 | */ |
||
| 132 | protected function getUserContentType($step) |
||
| 136 | |||
| 137 | protected function getUserContentTypeFromContext($context) |
||
| 141 | |||
| 142 | 9 | /** |
|
| 143 | * @param $context we have to return FALSE if that is set as adminUserLogin, whereas if NULL is set, we return the default admin |
||
| 144 | 9 | * @return int|string|false |
|
| 145 | 9 | */ |
|
| 146 | 9 | protected function getAdminUserIdentifierFromContext($context) |
|
| 154 | 2 | ||
| 155 | protected function setReferencesCommon($entity, $step) |
||
| 176 | |||
| 177 | protected function insureSingleEntity($entity, $step) |
||
| 192 | |||
| 193 | protected function getSelfName() |
||
| 199 | |||
| 200 | protected function getCollectionName($collection) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * Courtesy code to avoid reimplementing it in every subclass |
||
| 209 | * @deprecated will be moved into the reference resolver classes |
||
| 210 | */ |
||
| 211 | View Code Duplication | protected function resolveReferencesRecursively($match) |
|
| 222 | } |
||
| 223 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.