for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of Zippy.
*
* (c) Alchemy <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Zippy\Parser;
use Alchemy\Zippy\Exception\InvalidArgumentException;
class ParserFactory
{
private static $zipDateFormat = 'Y-m-d H:i';
/**
* @param string $format Date format used to parse ZIP file listings
public static function setZipDateFormat($format)
self::$zipDateFormat = $format;
}
* Maps the corresponding parser to the selected adapter
* @param string $adapterName An adapter name
* @return ParserInterface
* @throws InvalidArgumentException In case no parser were found
public static function create($adapterName)
switch ($adapterName) {
case 'gnu-tar':
return new GNUTarOutputParser();
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 'bsd-tar':
return new BSDTarOutputParser();
case 'zip':
return new ZipOutputParser(self::$zipDateFormat);
default:
throw new InvalidArgumentException(sprintf('No parser available for %s adapter', $adapterName));
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.