TeaFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 17
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A factory() 0 14 3
1
<?php
2
3
namespace Creational\FactoryMethod;
4
5
use Creational\FactoryMethod\Tea\Green;
6
use Creational\FactoryMethod\Tea\Black;
7
use Creational\FactoryMethod\Tea\Tea;
8
use InvalidArgumentException;
9
10
class TeaFactory extends AbstractFactory
11
{
12
    protected function factory($type = null)
13
    {
14
        switch ($type) {
15
            case Tea::GREEN:
16
                return new Green();
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 Tea::BLACK:
19
                return new Black();
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