for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Creational\FactoryMethod;
use Creational\FactoryMethod\Tea\Green;
use Creational\FactoryMethod\Tea\Black;
use Creational\FactoryMethod\Tea\Tea;
use InvalidArgumentException;
class TeaFactory extends AbstractFactory
{
protected function factory($type = null)
switch ($type) {
case Tea::GREEN:
return new Green();
break;
break
The break statement is not necessary if it is preceded for example by a return statement:
switch ($x) { case 1: return 'foo'; break; // This break is not necessary and can be left off. }
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.
case Tea::BLACK:
return new Black();
default:
throw new InvalidArgumentException('Unknown type');
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.
Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.
return
die
exit
function fx() { try { doSomething(); return true; } catch (\Exception $e) { return false; } return false; }
In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.
return false
}
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.