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 // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
||
| 24 | class WordpressVersioning implements VersioningPlugin { |
||
| 25 | use PluginTrait; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Define any command line options the versioning plugin wants to accept. |
||
| 29 | * |
||
| 30 | * @return InputOption[] |
||
| 31 | */ |
||
| 32 | public function getOptions() { |
||
| 37 | |||
| 38 | /** |
||
| 39 | * Parse a WordPress-style version. |
||
| 40 | * |
||
| 41 | * @param string $version Version. |
||
| 42 | * @return array With components: |
||
| 43 | * - major: (float) Major version. |
||
| 44 | * - point: (int) Point version. |
||
| 45 | * - prerelease: (string|null) Pre-release string. |
||
| 46 | * - buildinfo: (string|null) Build metadata string. |
||
| 47 | * @throws InvalidArgumentException If the version number is not in a recognized format. |
||
| 48 | */ |
||
| 49 | private function parseVersion( $version ) { |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Check and normalize a version number. |
||
| 63 | * |
||
| 64 | * @param string $version Version string. |
||
| 65 | * @return string Normalized version. |
||
| 66 | * @throws InvalidArgumentException If the version number is not in a recognized format. |
||
| 67 | */ |
||
| 68 | public function normalizeVersion( $version ) { |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Determine the next version given a current version and a set of changes. |
||
| 98 | * |
||
| 99 | * @param string $version Current version. |
||
| 100 | * @param ChangeEntry[] $changes Changes. |
||
| 101 | * @param array $extra Extra components for the version. |
||
| 102 | * @return string |
||
| 103 | * @throws InvalidArgumentException If the version number is not in a recognized format, or other arguments are invalid. |
||
| 104 | */ |
||
| 105 | public function nextVersion( $version, array $changes, array $extra = array() ) { |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Extract the index and count from a prerelease string. |
||
| 139 | * |
||
| 140 | * @param string|null $s String. |
||
| 141 | * @return array Two elements: index and count. |
||
| 142 | * @throws InvalidArgumentException If the string is invalid. |
||
| 143 | */ |
||
| 144 | private function parsePrerelease( $s ) { |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Compare two version numbers. |
||
| 158 | * |
||
| 159 | * @param string $a First version. |
||
| 160 | * @param string $b Second version. |
||
| 161 | * @return int Less than, equal to, or greater than 0 depending on whether `$a` is less than, equal to, or greater than `$b`. |
||
| 162 | * @throws InvalidArgumentException If the version numbers are not in a recognized format. |
||
| 163 | */ |
||
| 164 | public function compareVersions( $a, $b ) { |
||
| 182 | |||
| 183 | } |
||
| 184 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: