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 |
||
| 19 | class ORM extends Component implements ORMInterface |
||
| 20 | { |
||
| 21 | use LoggerTrait; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Memory section to store ORM schema. |
||
| 25 | */ |
||
| 26 | const MEMORY = 'orm.schema'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Normalized relation options. |
||
| 30 | */ |
||
| 31 | const R_TYPE = 0; |
||
| 32 | const R_TABLE = 1; |
||
| 33 | const R_DEFINITION = 2; |
||
| 34 | const R_DATABASE = 3; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Pivot table data location in Record fields. Pivot data only provided when record is loaded |
||
| 38 | * using many-to-many relation. |
||
| 39 | */ |
||
| 40 | const PIVOT_DATA = '@pivot'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Record mappers. |
||
| 44 | * |
||
| 45 | * @var RecordMapper[] |
||
| 46 | */ |
||
| 47 | private $mappers = []; |
||
|
|
|||
| 48 | |||
| 49 | /** |
||
| 50 | * @var EntityCache |
||
| 51 | */ |
||
| 52 | private $cache = null; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var ORMConfig |
||
| 56 | */ |
||
| 57 | protected $config = null; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @invisible |
||
| 61 | * |
||
| 62 | * @var DatabaseManager |
||
| 63 | */ |
||
| 64 | protected $databases = null; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Cached records schema. |
||
| 68 | * |
||
| 69 | * @var array|null |
||
| 70 | */ |
||
| 71 | protected $schema = null; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * @invisible |
||
| 75 | * |
||
| 76 | * @var FactoryInterface |
||
| 77 | */ |
||
| 78 | protected $factory = null; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @invisible |
||
| 82 | * |
||
| 83 | * @var HippocampusInterface |
||
| 84 | */ |
||
| 85 | protected $memory = null; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @param ORMConfig $config |
||
| 89 | * @param DatabaseManager $databases |
||
| 90 | * @param EntityCache $cache |
||
| 91 | * @param HippocampusInterface $memory |
||
| 92 | * @param FactoryInterface $factory |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function __construct( |
|
| 112 | |||
| 113 | /** |
||
| 114 | * @param EntityCache $cache |
||
| 115 | * @return $this |
||
| 116 | */ |
||
| 117 | public function setCache(EntityCache $cache) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return EntityCache |
||
| 126 | */ |
||
| 127 | public function entityCache() |
||
| 131 | |||
| 132 | /** |
||
| 133 | * {@inheritdoc} |
||
| 134 | */ |
||
| 135 | public function database($database) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * {@inheritdoc} |
||
| 142 | */ |
||
| 143 | public function schema($item, $property = null) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * {@inheritdoc} |
||
| 150 | */ |
||
| 151 | public function record($class, array $data, $cache = true) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritdoc} |
||
| 158 | */ |
||
| 159 | public function relation( |
||
| 168 | |||
| 169 | /** |
||
| 170 | * {@inheritdoc} |
||
| 171 | */ |
||
| 172 | public function selector($class, Loader $loader = null) |
||
| 176 | |||
| 177 | /** |
||
| 178 | * {@inheritdoc} |
||
| 179 | */ |
||
| 180 | public function loader($type, $container, array $definition, Loader $parent = null) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * {@inheritdoc} |
||
| 187 | */ |
||
| 188 | public function source($class) |
||
| 192 | |||
| 193 | /** |
||
| 194 | * {@inheritdoc} |
||
| 195 | */ |
||
| 196 | public function mapper($class) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * When ORM is cloned we are automatically cloning it's cache as well to create |
||
| 203 | * new isolated area. Basically we have cache enabled per selection. |
||
| 204 | * |
||
| 205 | * @see RecordSelector::getIterator() |
||
| 206 | */ |
||
| 207 | public function __clone() |
||
| 215 | |||
| 216 | |||
| 217 | } |
This check marks private properties in classes that are never used. Those properties can be removed.