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 |
||
28 | class FieldRenderingExtension extends Twig_Extension |
||
29 | { |
||
30 | /** |
||
31 | * @var FieldBlockRendererInterface|\eZ\Publish\Core\MVC\Symfony\Templating\Twig\FieldBlockRenderer |
||
32 | */ |
||
33 | private $fieldBlockRenderer; |
||
34 | |||
35 | /** |
||
36 | * @var ContentTypeService |
||
37 | */ |
||
38 | private $contentTypeService; |
||
39 | |||
40 | /** |
||
41 | * @var ParameterProviderRegistryInterface |
||
42 | */ |
||
43 | private $parameterProviderRegistry; |
||
44 | |||
45 | /** |
||
46 | * @var TranslationHelper |
||
47 | */ |
||
48 | private $translationHelper; |
||
49 | |||
50 | /** |
||
51 | * Hash of field type identifiers (i.e. "ezstring"), indexed by field definition identifier. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | private $fieldTypeIdentifiers = []; |
||
56 | |||
57 | public function __construct( |
||
58 | FieldBlockRendererInterface $fieldBlockRenderer, |
||
59 | ContentTypeService $contentTypeService, |
||
60 | ParameterProviderRegistryInterface $parameterProviderRegistry, |
||
61 | TranslationHelper $translationHelper |
||
62 | ) { |
||
63 | $this->fieldBlockRenderer = $fieldBlockRenderer; |
||
|
|||
64 | $this->contentTypeService = $contentTypeService; |
||
65 | $this->parameterProviderRegistry = $parameterProviderRegistry; |
||
66 | $this->translationHelper = $translationHelper; |
||
67 | } |
||
68 | |||
69 | public function getName() |
||
73 | |||
74 | public function getFunctions() |
||
95 | |||
96 | /** |
||
97 | * Renders the HTML for the settings for the given field definition |
||
98 | * $definition. |
||
99 | * |
||
100 | * @param \eZ\Publish\API\Repository\Values\ContentType\FieldDefinition $fieldDefinition |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function renderFieldDefinitionSettings(FieldDefinition $fieldDefinition, array $params = []) |
||
108 | |||
109 | /** |
||
110 | * Renders the HTML for a given field. |
||
111 | * |
||
112 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
113 | * @param string $fieldIdentifier Identifier for the field we want to render |
||
114 | * @param array $params An array of parameters to pass to the field view |
||
115 | * |
||
116 | * @return string The HTML markup |
||
117 | * |
||
118 | * @throws InvalidArgumentException |
||
119 | */ |
||
120 | public function renderField(Content $content, $fieldIdentifier, array $params = []) |
||
135 | |||
136 | /** |
||
137 | * Generates the array of parameter to pass to the field template. |
||
138 | * |
||
139 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
140 | * @param \eZ\Publish\API\Repository\Values\Content\Field $field the Field to display |
||
141 | * @param array $params An array of parameters to pass to the field view |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | private function getRenderFieldBlockParameters(Content $content, Field $field, array $params = []) |
||
184 | |||
185 | /** |
||
186 | * Returns the field type identifier for $field. |
||
187 | * |
||
188 | * @param \eZ\Publish\API\Repository\Values\Content\Content $content |
||
189 | * @param \eZ\Publish\API\Repository\Values\Content\Field $field |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | private function getFieldTypeIdentifier(Content $content, Field $field) |
||
207 | } |
||
208 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.