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 |
||
| 18 | class BasicContentContext implements Context |
||
| 19 | { |
||
| 20 | use RepositoryContext; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Default language. |
||
| 24 | */ |
||
| 25 | const DEFAULT_LANGUAGE = 'eng-GB'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Content path mapping. |
||
| 29 | */ |
||
| 30 | private $contentPaths = array(); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var eZ\Publish\API\Repository\ContentTypeService |
||
| 34 | */ |
||
| 35 | private $contentTypeService; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var eZ\Publish\API\Repository\ContentService |
||
| 39 | */ |
||
| 40 | private $contentService; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @injectService $repository @ezpublish.api.repository |
||
| 44 | * @injectService $contentTypeService @ezpublish.api.service.content_type |
||
| 45 | * @injectService $contentService @ezpublish.api.service.content |
||
| 46 | */ |
||
| 47 | public function __construct( |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Creates and publishes a Content. |
||
| 59 | * |
||
| 60 | * @param string $contentType |
||
| 61 | * @param array $fields |
||
| 62 | * @param mixed $parentLocationId |
||
| 63 | * |
||
| 64 | * @return mixed The content's main location id |
||
| 65 | */ |
||
| 66 | public function createContent($contentType, $fields, $parentLocationId) |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Publishes a content draft. |
||
| 78 | * |
||
| 79 | * @param eZ\Publish\API\Repository\Values\Content\Content $content |
||
| 80 | */ |
||
| 81 | public function publishDraft(Content $content) |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Creates a content draft. |
||
| 88 | * |
||
| 89 | * @param eZ\Publish\API\Repository\Values\Content\Location $parentLocationId |
||
| 90 | * @param string $contentTypeIdentifier |
||
| 91 | * @param string $languageCode |
||
| 92 | * @param array $fields Fields, as primitives understood by setField |
||
| 93 | * |
||
| 94 | * @return eZ\Publish\API\Repository\Values\Content\Content an unpublished Content draft |
||
| 95 | */ |
||
| 96 | public function createContentDraft($parentLocationId, $contentTypeIdentifier, $fields, $languageCode = null) |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Creates and publishes a content at a given path. |
||
| 112 | * Non-existing path items are created as folders named after the path element. |
||
| 113 | * |
||
| 114 | * @param string $path The content path |
||
| 115 | * @param array $fields |
||
| 116 | * @param mixed $contentType The content type identifier |
||
| 117 | * |
||
| 118 | * @return mixed location id of the created content |
||
| 119 | */ |
||
| 120 | public function createContentWithPath($path, $fields, $contentType) |
||
| 139 | |||
| 140 | /** |
||
| 141 | * Getter for contentPaths. |
||
| 142 | */ |
||
| 143 | public function getContentPath($name) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Maps the path of the content to it's name for later use. |
||
| 150 | */ |
||
| 151 | private function mapContentPath($path) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @Given a/an :path folder exists |
||
| 159 | */ |
||
| 160 | public function createBasicFolder($path) |
||
| 166 | |||
| 167 | /** |
||
| 168 | * @Given a/an :path article exists |
||
| 169 | */ |
||
| 170 | View Code Duplication | public function createBasicArticle($path) |
|
| 179 | |||
| 180 | /** |
||
| 181 | * @Given a/an :path article draft exists |
||
| 182 | */ |
||
| 183 | View Code Duplication | public function createArticleDraft($path) |
|
| 192 | |||
| 193 | private function getTitleFromPath($path) |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @return string |
||
| 202 | */ |
||
| 203 | private function getDummyXmlText() |
||
| 207 | } |
||
| 208 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..