DocumentFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 22
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 16 4
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: marek
5
 * Date: 19.11.15
6
 * Time: 09:47.
7
 */
8
namespace Madkom\RegistryApplication\Domain\CarManagement;
9
10
use Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\EmptyDocumentTypeException;
11
use Madkom\RegistryApplication\Domain\CarManagement\CarExceptions\UnknownDocumentTypeException;
12
use Madkom\RegistryApplication\Domain\CarManagement\Insurances\InsuranceDocument;
13
14
class DocumentFactory
15
{
16
    const CAR_DOCUMENT = 1;
17
    const INSURANCE_DOCUMENT = 2;
18
19
    public function create($type, $id, $title, $description, $source)
20
    {
21
        switch ($type) {
22
            case self::CAR_DOCUMENT:
23
                return new CarDocument($id, $title, $description, $source);
0 ignored issues
show
Unused Code introduced by
The call to CarDocument::__construct() has too many arguments starting with $description.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
24
            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...
25
            case self::INSURANCE_DOCUMENT:
26
                return new InsuranceDocument($id, $title, $description, $source);
27
            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...
28
            case null:
29
                throw new EmptyDocumentTypeException('Document type must not be empty.');
30
            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...
31
            default:
32
                throw new UnknownDocumentTypeException('Unknown document type: '.$type);
33
        }
34
    }
35
}
36