CoffeeFactory::factory()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
rs 9.4285
nc 3
cc 3
eloc 11
nop 1
1
<?php
2
3
namespace Creational\FactoryMethod;
4
5
use Creational\FactoryMethod\Coffee\Coffee;
6
use Creational\FactoryMethod\Coffee\Espresso;
7
use Creational\FactoryMethod\Coffee\Latte;
8
use InvalidArgumentException;
9
10
class CoffeeFactory extends AbstractFactory
11
{
12
    protected function factory($type = null)
13
    {
14
        switch ($type) {
15
            case Coffee::STRONG:
16
                return new Espresso();
17
                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...
18
            case Coffee::MILKY:
19
                return new Latte();
20
                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...
21
            default:
22
                throw new InvalidArgumentException('Unknown type');
23
                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...
24
        }
25
    }
26
}
27