Completed
Pull Request — master (#132)
by
unknown
01:33
created

ParserFactory::setZipDateFormat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Zippy.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Alchemy\Zippy\Parser;
13
14
use Alchemy\Zippy\Exception\InvalidArgumentException;
15
16
class ParserFactory
17
{
18
19
    private static $zipDateFormat = 'Y-m-d H:i';
20
21
    /**
22
     * @param string $format Date format used to parse ZIP file listings
23
     */
24
    public static function setZipDateFormat($format)
25
    {
26
        self::$zipDateFormat = $format;
27
    }
28
29
    /**
30
     * Maps the corresponding parser to the selected adapter
31
     *
32
     * @param   string $adapterName An adapter name
33
     *
34
     * @return ParserInterface
35
     *
36
     * @throws InvalidArgumentException In case no parser were found
37
     */
38
    public static function create($adapterName)
39
    {
40
        switch ($adapterName) {
41
            case 'gnu-tar':
42
                return new GNUTarOutputParser();
43
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

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.

Loading history...
44
            case 'bsd-tar':
45
                return new BSDTarOutputParser();
46
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

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.

Loading history...
47
            case 'zip':
48
                return new ZipOutputParser(self::$zipDateFormat);
49
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

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.

Loading history...
50
51
            default:
52
                throw new InvalidArgumentException(sprintf('No parser available for %s adapter', $adapterName));
53
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

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.

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.

Loading history...
54
        }
55
    }
56
}
57