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 |
||
| 19 | final class ManifestStrategy implements StrategyInterface |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var array |
||
| 23 | */ |
||
| 24 | private static $requiredKeys = array('sha1', 'version', 'url'); |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $manifestUrl; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $manifest; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | private $availableVersions; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | private $localVersion; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var bool |
||
| 48 | */ |
||
| 49 | private $allowMajor = false; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var bool |
||
| 53 | */ |
||
| 54 | private $allowUnstable = false; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * ManifestStrategy constructor. |
||
| 58 | * |
||
| 59 | * @param string $localVersion The local version. |
||
| 60 | * @param string $manifestUrl The URL to a JSON manifest file. The |
||
| 61 | * manifest contains an array of objects, each |
||
| 62 | * containing a 'version', 'sha1', and 'url'. |
||
| 63 | * @param bool $allowMajor Whether to allow updating between major |
||
| 64 | * versions. |
||
| 65 | * @param bool $allowUnstable Whether to allow updating to an unstable |
||
| 66 | * version. Ignored if $localVersion is unstable |
||
| 67 | * and there are no new stable versions. |
||
| 68 | */ |
||
| 69 | public function __construct($localVersion, $manifestUrl, $allowMajor = false, $allowUnstable = false) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | public function getCurrentLocalVersion(Updater $updater) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | */ |
||
| 88 | public function download(Updater $updater) |
||
| 122 | |||
| 123 | /** |
||
| 124 | * {@inheritdoc} |
||
| 125 | */ |
||
| 126 | public function getCurrentRemoteVersion(Updater $updater) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Gets available versions to update to. |
||
| 148 | * |
||
| 149 | * @return array An array keyed by the version name, whose elements are arrays |
||
| 150 | * containing version information ('name', 'sha1', and 'url'). |
||
| 151 | */ |
||
| 152 | private function getAvailableVersions() |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Download and decode the JSON manifest file. |
||
| 170 | * |
||
| 171 | * @return array |
||
| 172 | */ |
||
| 173 | private function retrieveManifest() |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Filter a list of versions to those that match the current local version. |
||
| 199 | * |
||
| 200 | * @param string[] $versions |
||
| 201 | * |
||
| 202 | * @return string[] |
||
| 203 | */ |
||
| 204 | private function filterByLocalMajorVersion(array $versions) |
||
| 213 | } |
||
| 214 |
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..