| Conditions | 1 |
| Paths | 1 |
| Total Lines | 137 |
| 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 |
||
| 95 | public function provideExecute() { |
||
| 96 | $date = gmdate( 'Y-m-d' ); |
||
| 97 | $defaultOptions = array( |
||
| 98 | 'changelog' => "# Changelog\n\n## 1.0.1 - 2021-02-23\n\nPrologue for v1.0.1\n\n### Added\n- Stuff.\n\n### Removed\n- Other stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n", |
||
| 99 | 'changes' => array( |
||
| 100 | 'a-change' => "Significance: patch\nType: fixed\n\nFixed a thing.\n", |
||
| 101 | ), |
||
| 102 | ); |
||
| 103 | |||
| 104 | return array( |
||
| 105 | 'Normal run' => array( |
||
| 106 | array(), |
||
| 107 | $defaultOptions, |
||
| 108 | array(), |
||
| 109 | 0, |
||
| 110 | array( '/^$/' ), |
||
| 111 | true, |
||
| 112 | "# Changelog\n\n## 1.0.2 - $date\n### Fixed\n- Fixed a thing.\n\n## 1.0.1 - 2021-02-23\n\nPrologue for v1.0.1\n\n### Added\n- Stuff.\n\n### Removed\n- Other stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n", |
||
| 113 | ), |
||
| 114 | 'Debug run' => array( |
||
| 115 | array(), |
||
| 116 | array( 'verbosity' => OutputInterface::VERBOSITY_DEBUG ) + $defaultOptions, |
||
| 117 | array(), |
||
| 118 | 0, |
||
| 119 | array( |
||
| 120 | '{^Reading changelog from /.*/CHANGELOG.md\\.\\.\\.$}m', |
||
| 121 | '{^Reading changes from /.*/changelog\\.\\.\\.$}m', |
||
| 122 | '{^Deduplicating changes from the last 1 version\\(s\\)\\.\\.\\.$}m', |
||
| 123 | '{^Checking if any changes have content\\.\\.\\.$}m', |
||
| 124 | '{^Yes, a-change has content\\.$}m', |
||
| 125 | '{^Latest version from changelog is 1\\.0\\.1\\.$}m', |
||
| 126 | '{^Next version is 1\\.0\\.2\\.$}m', |
||
| 127 | '{^Creating new changelog entry\\.$}m', |
||
| 128 | '{^Writing changelog to /.*/CHANGELOG.md\\.\\.\\.$}m', |
||
| 129 | '{^Deleted change file a-change\\.$}m', |
||
| 130 | ), |
||
| 131 | true, |
||
| 132 | "# Changelog\n\n## 1.0.2 - $date\n### Fixed\n- Fixed a thing.\n\n## 1.0.1 - 2021-02-23\n\nPrologue for v1.0.1\n\n### Added\n- Stuff.\n\n### Removed\n- Other stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n", |
||
| 133 | ), |
||
| 134 | 'Run with extra command line args' => array( |
||
| 135 | array( |
||
| 136 | '--prerelease' => 'dev', |
||
| 137 | '--buildinfo' => 'g1234567', |
||
| 138 | '--prologue' => 'Prologue for the new entry', |
||
| 139 | '--epilogue' => 'Epilogue for the new entry', |
||
| 140 | '--link' => 'https://example.org/link', |
||
| 141 | ), |
||
| 142 | $defaultOptions, |
||
| 143 | array(), |
||
| 144 | 0, |
||
| 145 | array( '/^$/' ), |
||
| 146 | true, |
||
| 147 | "# Changelog\n\n## [1.0.2-dev+g1234567] - $date\n\nPrologue for the new entry\n\n### Fixed\n- Fixed a thing.\n\nEpilogue for the new entry\n\n## 1.0.1 - 2021-02-23\n\nPrologue for v1.0.1\n\n### Added\n- Stuff.\n\n### Removed\n- Other stuff.\n\nEpilogue for v1.0.1\n\n## 1.0.0 - 2021-02-23\n\n- Initial release.\n\n[1.0.2-dev+g1234567]: https://example.org/link\n", |
||
| 148 | ), |
||
| 149 | |||
| 150 | 'Invalid formatter' => array( |
||
| 151 | array(), |
||
| 152 | array( 'composer.json' => array( 'formatter' => 'bogus' ) ), |
||
| 153 | array(), |
||
| 154 | WriteCommand::FATAL_EXIT, |
||
| 155 | array( '/^Unknown formatter plugin "bogus"$/' ), |
||
| 156 | ), |
||
| 157 | 'Invalid versioning' => array( |
||
| 158 | array(), |
||
| 159 | array( 'composer.json' => array( 'versioning' => 'bogus' ) ), |
||
| 160 | array(), |
||
| 161 | WriteCommand::FATAL_EXIT, |
||
| 162 | array( '/^Unknown versioning plugin "bogus"$/' ), |
||
| 163 | ), |
||
| 164 | |||
| 165 | 'No changelog file, interactive' => array( |
||
| 166 | array(), |
||
| 167 | array( 'changelog' => null ) + $defaultOptions, |
||
| 168 | array( 'N' ), |
||
| 169 | WriteCommand::ASKED_EXIT, |
||
| 170 | array( '{^Changelog file /.*/CHANGELOG\.md does not exist! Proceed\? \[y/N\]}m' ), |
||
| 171 | ), |
||
| 172 | 'No changelog file, interactive (2)' => array( |
||
| 173 | array(), |
||
| 174 | array( 'changelog' => null ) + $defaultOptions, |
||
| 175 | array( 'Y' ), |
||
| 176 | WriteCommand::FATAL_EXIT, |
||
| 177 | array( '/Changelog file contains no entries! Use --use-version to specify the initial version\.$/m' ), |
||
| 178 | ), |
||
| 179 | 'No changelog file, interactive (3)' => array( |
||
| 180 | array( '--use-version' => '1.0.0' ), |
||
| 181 | array( 'changelog' => null ) + $defaultOptions, |
||
| 182 | array( 'Y' ), |
||
| 183 | 0, |
||
| 184 | array(), |
||
| 185 | true, |
||
| 186 | "## 1.0.0 - $date\n### Fixed\n- Fixed a thing.\n", |
||
| 187 | ), |
||
| 188 | 'No changelog file, non-interactive' => array( |
||
| 189 | array(), |
||
| 190 | array( |
||
| 191 | 'interactive' => false, |
||
| 192 | 'changelog' => null, |
||
| 193 | ) + $defaultOptions, |
||
| 194 | array(), |
||
| 195 | WriteCommand::ASKED_EXIT, |
||
| 196 | array( '{^Changelog file /.*/CHANGELOG\.md does not exist!$}m' ), |
||
| 197 | ), |
||
| 198 | 'No changelog file, non-interactive, --yes' => array( |
||
| 199 | array( '--yes' => true ), |
||
| 200 | array( |
||
| 201 | 'interactive' => false, |
||
| 202 | 'changelog' => null, |
||
| 203 | ) + $defaultOptions, |
||
| 204 | array(), |
||
| 205 | WriteCommand::FATAL_EXIT, |
||
| 206 | array( |
||
| 207 | '{^<warning>Changelog file /.*/CHANGELOG\.md does not exist! Continuing anyway\.$}m', |
||
| 208 | '/Changelog file contains no entries! Use --use-version to specify the initial version\.$/m', |
||
| 209 | ), |
||
| 210 | ), |
||
| 211 | 'No changelog file, non-interactive, --yes (2)' => array( |
||
| 212 | array( |
||
| 213 | '--yes' => true, |
||
| 214 | '--use-version' => '1.0.0', |
||
| 215 | ), |
||
| 216 | array( |
||
| 217 | 'interactive' => false, |
||
| 218 | 'changelog' => null, |
||
| 219 | ) + $defaultOptions, |
||
| 220 | array(), |
||
| 221 | 0, |
||
| 222 | array( |
||
| 223 | '{^<warning>Changelog file /.*/CHANGELOG\.md does not exist! Continuing anyway\.$}m', |
||
| 224 | ), |
||
| 225 | true, |
||
| 226 | "## 1.0.0 - $date\n### Fixed\n- Fixed a thing.\n", |
||
| 227 | ), |
||
| 228 | |||
| 229 | // TODO: More tests. |
||
| 230 | ); |
||
| 231 | } |
||
| 232 | |||
| 234 |