Skip to content

Instantly share code, notes, and snippets.

@rtuin
Created March 22, 2016 11:13
Show Gist options
  • Save rtuin/f4b3de6fae6645ba35a5 to your computer and use it in GitHub Desktop.
Save rtuin/f4b3de6fae6645ba35a5 to your computer and use it in GitHub Desktop.
<?php
foreach ($someArray as $value) {
if (isSomething($value)) {
$output->writeln("It's true!");
} else {
$output->writeln("It's false!");
}
}
// phpmd: The method x uses an else expression. Else is never necessary and you can simplify the code to work without else.
// Oh sure, let me refactor that!
foreach ($someArray as $value) {
if (isSomething($value)) {
$output->writeln("It's true!");
continue;
}
$output->writeln("It's false!");
}
// Meh...
@fvdb
Copy link

fvdb commented Mar 22, 2016

Cheat!

$output->writeln(isSomething($value) ? "It's true!" : "It's false!");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment