| Conditions | 1 |
| Paths | 1 |
| Total Lines | 138 |
| 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 // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
||
| 74 | public function provideExecute() { |
||
| 75 | $composerWithTypes = array( |
||
| 76 | 'extra' => array( |
||
| 77 | 'changelogger' => array( |
||
| 78 | 'types' => array( |
||
| 79 | 'foo' => 'Foo', |
||
| 80 | 'bar' => 'Bar', |
||
| 81 | ), |
||
| 82 | ), |
||
| 83 | ), |
||
| 84 | ); |
||
| 85 | $composerWithNoTypes = array( |
||
| 86 | 'extra' => array( |
||
| 87 | 'changelogger' => array( |
||
| 88 | 'types' => (object) array(), |
||
| 89 | ), |
||
| 90 | ), |
||
| 91 | ); |
||
| 92 | |||
| 93 | return array( |
||
| 94 | 'Normal run' => array( |
||
| 95 | array(), |
||
| 96 | array(), |
||
| 97 | 1, |
||
| 98 | <<<'EOF' |
||
| 99 | /base/path/changelog/custom-type:2: Type must be "security", "added", "changed", "deprecated", "removed", or "fixed". |
||
| 100 | <warning>/base/path/changelog/duplicate-headers:3: Duplicate header "Type", previously seen on line 2. |
||
| 101 | /base/path/changelog/no-entry-not-patch:5: Changelog entry may only be empty when Significance is "patch". |
||
| 102 | /base/path/changelog/no-type: File does not contain a Type header. |
||
| 103 | <warning>/base/path/changelog/unknown-header:3: Unrecognized header "Bogus". |
||
| 104 | /base/path/changelog/wrong-header-values:1: Significance must be "patch", "minor", or "major". |
||
| 105 | /base/path/changelog/wrong-header-values:2: Type must be "security", "added", "changed", "deprecated", "removed", or "fixed". |
||
| 106 | /base/path/changelog/wrong-headers: File does not contain a Significance header. |
||
| 107 | /base/path/changelog/wrong-headers: File does not contain a Type header. |
||
| 108 | <warning>/base/path/changelog/wrong-headers:1: Unrecognized header "Significants". |
||
| 109 | <warning>/base/path/changelog/wrong-headers:2: Unrecognized header "Typo". |
||
| 110 | EOF |
||
| 111 | , |
||
| 112 | ), |
||
| 113 | 'Verbose run' => array( |
||
| 114 | array( '-v' ), |
||
| 115 | array( 'verbosity' => OutputInterface::VERBOSITY_VERBOSE ), |
||
| 116 | 1, |
||
| 117 | <<<'EOF' |
||
| 118 | Checking /base/path/changelog/custom-type... |
||
| 119 | /base/path/changelog/custom-type:2: Type must be "security", "added", "changed", "deprecated", "removed", or "fixed". |
||
| 120 | Checking /base/path/changelog/duplicate-headers... |
||
| 121 | <warning>/base/path/changelog/duplicate-headers:3: Duplicate header "Type", previously seen on line 2. |
||
| 122 | Checking /base/path/changelog/good... |
||
| 123 | Checking /base/path/changelog/no-entry-is-patch... |
||
| 124 | Checking /base/path/changelog/no-entry-not-patch... |
||
| 125 | /base/path/changelog/no-entry-not-patch:5: Changelog entry may only be empty when Significance is "patch". |
||
| 126 | Checking /base/path/changelog/no-type... |
||
| 127 | /base/path/changelog/no-type: File does not contain a Type header. |
||
| 128 | Checking /base/path/changelog/unknown-header... |
||
| 129 | <warning>/base/path/changelog/unknown-header:3: Unrecognized header "Bogus". |
||
| 130 | Checking /base/path/changelog/wrong-header-values... |
||
| 131 | /base/path/changelog/wrong-header-values:1: Significance must be "patch", "minor", or "major". |
||
| 132 | /base/path/changelog/wrong-header-values:2: Type must be "security", "added", "changed", "deprecated", "removed", or "fixed". |
||
| 133 | Checking /base/path/changelog/wrong-headers... |
||
| 134 | /base/path/changelog/wrong-headers: File does not contain a Significance header. |
||
| 135 | /base/path/changelog/wrong-headers: File does not contain a Type header. |
||
| 136 | <warning>/base/path/changelog/wrong-headers:1: Unrecognized header "Significants". |
||
| 137 | <warning>/base/path/changelog/wrong-headers:2: Unrecognized header "Typo". |
||
| 138 | Found 7 error(s) and 4 warning(s) |
||
| 139 | EOF |
||
| 140 | , |
||
| 141 | ), |
||
| 142 | 'Specific file' => array( |
||
| 143 | array( 'files' => array( 'changelog/good' ) ), |
||
| 144 | array(), |
||
| 145 | 0, |
||
| 146 | '', |
||
| 147 | ), |
||
| 148 | 'Only warnings' => array( |
||
| 149 | array( 'files' => array( 'changelog/unknown-header' ) ), |
||
| 150 | array(), |
||
| 151 | 1, |
||
| 152 | '<warning>changelog/unknown-header:3: Unrecognized header "Bogus".', |
||
| 153 | ), |
||
| 154 | 'Only warnings, non-strict' => array( |
||
| 155 | array( |
||
| 156 | '--no-strict' => true, |
||
| 157 | 'files' => array( 'changelog/unknown-header' ), |
||
| 158 | ), |
||
| 159 | array(), |
||
| 160 | 0, |
||
| 161 | '<warning>changelog/unknown-header:3: Unrecognized header "Bogus".', |
||
| 162 | ), |
||
| 163 | 'Multiple specific files' => array( |
||
| 164 | array( 'files' => array( 'changelog/.', 'changelog/..', 'changelog/.gitkeep' ) ), |
||
| 165 | array(), |
||
| 166 | 1, |
||
| 167 | <<<'EOF' |
||
| 168 | changelog/.: Expected a file, got dir. |
||
| 169 | changelog/..: Expected a file, got dir. |
||
| 170 | changelog/.gitkeep: File does not contain a Significance header. |
||
| 171 | changelog/.gitkeep: File does not contain a Type header. |
||
| 172 | EOF |
||
| 173 | , |
||
| 174 | ), |
||
| 175 | 'Custom types' => array( |
||
| 176 | array( 'files' => array( 'changelog/good', 'changelog/custom-type', 'changelog/no-type' ) ), |
||
| 177 | array( 'composer.json' => $composerWithTypes ), |
||
| 178 | 1, |
||
| 179 | <<<'EOF' |
||
| 180 | changelog/good:2: Type must be "foo" or "bar". |
||
| 181 | changelog/no-type: File does not contain a Type header. |
||
| 182 | EOF |
||
| 183 | , |
||
| 184 | ), |
||
| 185 | 'No types' => array( |
||
| 186 | array( 'files' => array( 'changelog/good', 'changelog/custom-type', 'changelog/no-type' ) ), |
||
| 187 | array( 'composer.json' => $composerWithNoTypes ), |
||
| 188 | 0, |
||
| 189 | '', |
||
| 190 | ), |
||
| 191 | 'GH Actions output' => array( |
||
| 192 | array( '--gh-action' => true ), |
||
| 193 | array(), |
||
| 194 | 1, |
||
| 195 | <<<'EOF' |
||
| 196 | ::error file=/base/path/changelog/custom-type,line=2::Type must be "security", "added", "changed", "deprecated", "removed", or "fixed". |
||
| 197 | ::warning file=/base/path/changelog/duplicate-headers,line=3::Duplicate header "Type", previously seen on line 2. |
||
| 198 | ::error file=/base/path/changelog/no-entry-not-patch,line=5::Changelog entry may only be empty when Significance is "patch". |
||
| 199 | ::error file=/base/path/changelog/no-type::File does not contain a Type header. |
||
| 200 | ::warning file=/base/path/changelog/unknown-header,line=3::Unrecognized header "Bogus". |
||
| 201 | ::error file=/base/path/changelog/wrong-header-values,line=1::Significance must be "patch", "minor", or "major". |
||
| 202 | ::error file=/base/path/changelog/wrong-header-values,line=2::Type must be "security", "added", "changed", "deprecated", "removed", or "fixed". |
||
| 203 | ::error file=/base/path/changelog/wrong-headers::File does not contain a Significance header. |
||
| 204 | ::error file=/base/path/changelog/wrong-headers::File does not contain a Type header. |
||
| 205 | ::warning file=/base/path/changelog/wrong-headers,line=1::Unrecognized header "Significants". |
||
| 206 | ::warning file=/base/path/changelog/wrong-headers,line=2::Unrecognized header "Typo". |
||
| 207 | EOF |
||
| 208 | , |
||
| 209 | ), |
||
| 210 | ); |
||
| 211 | } |
||
| 212 | |||
| 214 |