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 |
||
| 41 | class MetaFileVersionNode extends AbstractFile implements IPreviewNode, IProvidesAdditionalHeaders { |
||
| 42 | |||
| 43 | /** @var string */ |
||
| 44 | private $versionId; |
||
| 45 | /** @var MetaVersionCollection */ |
||
| 46 | private $parent; |
||
| 47 | /** @var IVersionedStorage */ |
||
| 48 | private $storage; |
||
| 49 | /** @var string */ |
||
| 50 | private $internalPath; |
||
| 51 | /** @var IRootFolder */ |
||
| 52 | private $root; |
||
| 53 | /** @var array */ |
||
| 54 | private $versionInfo; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * MetaFileVersionNode constructor. |
||
| 58 | * |
||
| 59 | * @param MetaVersionCollection $parent |
||
| 60 | * @param IRootFolder $root |
||
| 61 | * @param array $version |
||
| 62 | * @param Storage $storage |
||
| 63 | * @param string $internalPath |
||
| 64 | */ |
||
| 65 | public function __construct(MetaVersionCollection $parent, |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @inheritdoc |
||
| 78 | */ |
||
| 79 | public function getName() { |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @inheritdoc |
||
| 85 | */ |
||
| 86 | public function getSize() { |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @inheritdoc |
||
| 92 | */ |
||
| 93 | public function getContent() { |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @inheritdoc |
||
| 103 | */ |
||
| 104 | public function copy($targetPath) { |
||
| 105 | $target = $this->root->get($targetPath); |
||
| 106 | if ($target instanceof File && $target->getId() === $this->parent->getId()) { |
||
| 107 | if (!$target->isUpdateable()) { |
||
| 108 | throw new ForbiddenException("Cannot write to $targetPath", false); |
||
| 109 | } |
||
| 110 | return $this->storage->restoreVersion($this->internalPath, $this->versionId); |
||
| 111 | } |
||
| 112 | |||
| 113 | // for now we only allow restoring of a version |
||
| 114 | return false; |
||
| 115 | } |
||
| 116 | |||
| 117 | public function getMTime() { |
||
| 120 | |||
| 121 | public function getMimetype() { |
||
| 124 | |||
| 125 | public function getEtag() { |
||
| 128 | |||
| 129 | public function fopen($mode) { |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return array |
||
| 135 | */ |
||
| 136 | public function getHeaders() { |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @inheritdoc |
||
| 142 | */ |
||
| 143 | public function getContentDispositionFileName() { |
||
| 146 | |||
| 147 | public function getId() { |
||
| 150 | |||
| 151 | public function getPath() { |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param array $options |
||
| 157 | * @return IImage |
||
| 158 | * @since 10.1.0 |
||
| 159 | */ |
||
| 160 | View Code Duplication | public function getThumbnail($options) { |
|
| 176 | } |
||
| 177 |
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..