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 |
||
| 21 | class SectionHandler extends AbstractHandler implements SectionHandlerInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * @see eZ\Publish\SPI\Persistence\Content\Section\Handler |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function create($name, $identifier) |
|
| 27 | { |
||
| 28 | $this->logger->logCall(__METHOD__, array('name' => $name, 'identifier' => $identifier)); |
||
| 29 | $section = $this->persistenceHandler->sectionHandler()->create($name, $identifier); |
||
| 30 | $this->cache->getItem('section', $section->id)->set($section); |
||
| 31 | |||
| 32 | return $section; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @see eZ\Publish\SPI\Persistence\Content\Section\Handler |
||
| 37 | */ |
||
| 38 | View Code Duplication | public function update($id, $name, $identifier) |
|
| 39 | { |
||
| 40 | $this->logger->logCall(__METHOD__, array('section' => $id, 'name' => $name, 'identifier' => $identifier)); |
||
| 41 | $this->cache |
||
| 42 | ->getItem('section', $id) |
||
| 43 | ->set($section = $this->persistenceHandler->sectionHandler()->update($id, $name, $identifier)); |
||
| 44 | |||
| 45 | return $section; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @see eZ\Publish\SPI\Persistence\Content\Section\Handler |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function load($id) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Get all section data. |
||
| 65 | * |
||
| 66 | * @return \eZ\Publish\SPI\Persistence\Content\Section[] |
||
| 67 | */ |
||
| 68 | public function loadAll() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Get section data by identifier. |
||
| 77 | * |
||
| 78 | * @param string $identifier |
||
| 79 | * |
||
| 80 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If section is not found |
||
| 81 | * |
||
| 82 | * @return \eZ\Publish\SPI\Persistence\Content\Section |
||
| 83 | */ |
||
| 84 | public function loadByIdentifier($identifier) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @see eZ\Publish\SPI\Persistence\Content\Section\Handler |
||
| 93 | */ |
||
| 94 | public function delete($id) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @see eZ\Publish\SPI\Persistence\Content\Section\Handler |
||
| 106 | */ |
||
| 107 | public function assign($sectionId, $contentId) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Number of content assignments a Section has. |
||
| 121 | * |
||
| 122 | * @param mixed $sectionId |
||
| 123 | * |
||
| 124 | * @return int |
||
| 125 | */ |
||
| 126 | public function assignmentsCount($sectionId) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Number of role policies using a Section in limitations. |
||
| 135 | * |
||
| 136 | * @param mixed $sectionId |
||
| 137 | * |
||
| 138 | * @return int |
||
| 139 | */ |
||
| 140 | public function policiesCount($sectionId) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @see eZ\Publish\SPI\Persistence\User\Handler::countRoleAssignmentsUsingSection |
||
| 149 | */ |
||
| 150 | public function countRoleAssignmentsUsingSection($sectionId) |
||
| 156 | } |
||
| 157 |