| Conditions | 1 |
| Paths | 1 |
| Total Lines | 123 |
| Code Lines | 78 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 45 | public function provideCompareVersions() : array |
||
| 46 | { |
||
| 47 | return [ |
||
| 48 | // major |
||
| 49 | [ |
||
| 50 | Version::fromString('1.0.0'), |
||
| 51 | Version::fromString('2.0.0'), |
||
| 52 | -1, |
||
| 53 | '::compare() major version. 1.0.0 is lower than 2.0.0', |
||
| 54 | ], |
||
| 55 | [ |
||
| 56 | Version::fromString('2.0.0'), |
||
| 57 | Version::fromString('1.0.0'), |
||
| 58 | 1, |
||
| 59 | '::compare() major version. 2.0.0 is greater than 1.0.0', |
||
| 60 | ], |
||
| 61 | [ |
||
| 62 | Version::fromString('10.0.0'), |
||
| 63 | Version::fromString('2.0.0'), |
||
| 64 | 1, |
||
| 65 | '::compare() major version compares numerically. 10.0.0 is greater than 2.0.0', |
||
| 66 | ], |
||
| 67 | // minor |
||
| 68 | [ |
||
| 69 | Version::fromString('2.0.0'), |
||
| 70 | Version::fromString('2.10.0'), |
||
| 71 | -1, |
||
| 72 | '::compare() minor version. 2.0.0 is lower than 2.10.0', |
||
| 73 | ], |
||
| 74 | [ |
||
| 75 | Version::fromString('2.10.0'), |
||
| 76 | Version::fromString('2.0.0'), |
||
| 77 | 1, |
||
| 78 | '::compare() minor version. 2.10.0 is greater than 2.0.0', |
||
| 79 | ], |
||
| 80 | [ |
||
| 81 | Version::fromString('2.10.0'), |
||
| 82 | Version::fromString('2.2.0'), |
||
| 83 | 1, |
||
| 84 | '::compare() minor version compares numerically. 2.10.0 is greater than 2.2.0', |
||
| 85 | ], |
||
| 86 | // patch |
||
| 87 | [ |
||
| 88 | Version::fromString('2.0.0'), |
||
| 89 | Version::fromString('2.0.10'), |
||
| 90 | -1, |
||
| 91 | '::compare() patch version. 2.0.0 is lower than 2.0.10', |
||
| 92 | ], |
||
| 93 | [ |
||
| 94 | Version::fromString('2.0.10'), |
||
| 95 | Version::fromString('2.0.0'), |
||
| 96 | 1, |
||
| 97 | '::compare() patch version. 2.0.10 is greater than 2.0.0', |
||
| 98 | ], |
||
| 99 | [ |
||
| 100 | Version::fromString('2.0.10'), |
||
| 101 | Version::fromString('2.0.2'), |
||
| 102 | 1, |
||
| 103 | '::compare() patch version. 2.0.10 is greater than 2.0.2', |
||
| 104 | ], |
||
| 105 | [ |
||
| 106 | Version::fromString('2.0.0'), |
||
| 107 | Version::fromString('2.0.0+build'), |
||
| 108 | 0, |
||
| 109 | '::compare() build differs. versions should be equals.', |
||
| 110 | ], |
||
| 111 | // pre release |
||
| 112 | [ |
||
| 113 | Version::fromString('2.0.0'), |
||
| 114 | Version::fromString('2.0.0-alpha'), |
||
| 115 | 1, |
||
| 116 | '::compare() second version has a pre-release, the first not', |
||
| 117 | ], |
||
| 118 | [ |
||
| 119 | Version::fromString('2.0.0-alpha'), |
||
| 120 | Version::fromString('2.0.0'), |
||
| 121 | -1, |
||
| 122 | '::compare() first version has a pre-release, the second not', |
||
| 123 | ], |
||
| 124 | [ |
||
| 125 | Version::fromString('2.0.0-alpha.1'), |
||
| 126 | Version::fromString('2.0.0-alpha'), |
||
| 127 | 1, |
||
| 128 | '::compare() first has two pre-release identifiers, second only has one', |
||
| 129 | ], |
||
| 130 | [ |
||
| 131 | Version::fromString('2.0.0-alpha'), |
||
| 132 | Version::fromString('2.0.0-alpha.1'), |
||
| 133 | -1, |
||
| 134 | '::compare() second has two pre-release identifiers, first only has one', |
||
| 135 | ], |
||
| 136 | [ |
||
| 137 | Version::fromString('2.0.0-1'), |
||
| 138 | Version::fromString('2.0.0-beta'), |
||
| 139 | -1, |
||
| 140 | '::compare() a numeric identifier is lower than an alphabetical one', |
||
| 141 | ], |
||
| 142 | [ |
||
| 143 | Version::fromString('2.0.0-beta'), |
||
| 144 | Version::fromString('2.0.0-1'), |
||
| 145 | 1, |
||
| 146 | '::compare() an alphabetical identifier is greater than a numeric one', |
||
| 147 | ], |
||
| 148 | [ |
||
| 149 | Version::fromString('2.0.0-alpha.1'), |
||
| 150 | Version::fromString('2.0.0-alpha.beta'), |
||
| 151 | -1, |
||
| 152 | '::compare() a numeric identifier is lower than an alphabetical one even when multiple identifiers given', |
||
| 153 | ], |
||
| 154 | [ |
||
| 155 | Version::fromString('2.0.0-alpha.10'), |
||
| 156 | Version::fromString('2.0.0-alpha.2'), |
||
| 157 | 1, |
||
| 158 | '::compare() an alphabetical identifier is greater than a numeric one even when multiple identifiers given', |
||
| 159 | ], |
||
| 160 | [ |
||
| 161 | Version::fromString('2.0.0-alpha+build127'), |
||
| 162 | Version::fromString('2.0.0-alpha+build128'), |
||
| 163 | 0, |
||
| 164 | '::compare() two versions that only differs with their build are equals.', |
||
| 165 | ], |
||
| 166 | ]; |
||
| 167 | } |
||
| 168 | } |
||
| 169 |