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 |
||
| 15 | class GridSourceManager |
||
| 16 | { |
||
| 17 | protected $sourcesByClass; |
||
| 18 | protected $sourcesByName; |
||
| 19 | |||
| 20 | protected $reader; |
||
| 21 | protected $cacheDir; |
||
| 22 | protected $debug; |
||
| 23 | |||
| 24 | /** @var AbstractManagerRegistry */ |
||
| 25 | protected $registry; |
||
| 26 | |||
| 27 | /** @var AbstractManagerRegistry */ |
||
| 28 | protected $mongodbRegistry; |
||
| 29 | |||
| 30 | protected $customManagerMappings; |
||
| 31 | |||
| 32 | protected $extraGridSources; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var array|null Null means all entities allowed, empty array means no entities allowed |
||
| 36 | */ |
||
| 37 | protected $reflectionAllowedEntities; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * GridSourceManager constructor. |
||
| 41 | * |
||
| 42 | * @param string $cacheDir |
||
| 43 | * @param bool $debug |
||
| 44 | */ |
||
| 45 | public function __construct(Reader $reader, $cacheDir, $debug = false) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @param array|string $allowedEntities Array of allowed entities or string '*' to allow all entities. Use empty array to specify no entities allowed for reflection. |
||
| 56 | */ |
||
| 57 | public function setReflectionAllowedEntities($allowedEntities) { |
||
| 60 | |||
| 61 | public function setRegistry(AbstractManagerRegistry $registry) |
||
| 65 | |||
| 66 | public function setMongodbRegistry(AbstractManagerRegistry $registry) |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | protected function getCacheDir() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return bool |
||
| 81 | */ |
||
| 82 | protected function getDebug() |
||
| 86 | |||
| 87 | public function add($id, GridSourceInterface $gridSource) |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param ObjectManager $manager |
||
| 94 | * @param $entityOrDocument |
||
| 95 | * |
||
| 96 | * @return DocumentGridSource|EntityGridSource|null |
||
| 97 | */ |
||
| 98 | protected function getGridSource($manager, $entityOrDocument) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Get a gridsource. |
||
| 132 | * |
||
| 133 | * @param string $id Entity or Document |
||
| 134 | * @param EntityManager|DocumentManager|null $manager (optional) Entity or Document manager to use (overrides default) |
||
| 135 | * |
||
| 136 | * @return GridSourceInterface|null |
||
| 137 | * |
||
| 138 | * @throws \Exception |
||
| 139 | */ |
||
| 140 | public function get($entityOrDocumentNameOrId) |
||
| 169 | |||
| 170 | public function all() |
||
| 174 | |||
| 175 | public function setEntityManager(EntityManager $entityManager) |
||
| 179 | |||
| 180 | public function setDocumentManager(DocumentManager $documentManager) |
||
| 184 | } |
||
| 185 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.