Completed
Push — master ( fcd315...e54b6a )
by John
02:20
created

Path   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 70
Duplicated Lines 8.57 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 6
loc 70
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 4 1
A getOperations() 0 4 1
A getOperation() 6 13 2
A getPathParameters() 0 4 1
createOperation() 0 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\ApiDescriptions package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace KleijnWeb\ApiDescriptions\Description;
10
11
use KleijnWeb\ApiDescriptions\Description\Visitor\VisiteeMixin;
12
13
/**
14
 * @author John Kleijn <[email protected]>
15
 */
16
abstract class Path implements Element
17
{
18
    use VisiteeMixin;
19
20
    /**
21
     * @var string
22
     */
23
    protected $path;
24
25
    /**
26
     * @var Operation[]
27
     */
28
    protected $operations;
29
30
    /**
31
     * @var Parameter[]
32
     */
33
    protected $pathParameters = [];
34
35
    /**
36
     * @return string
37
     */
38
    public function getPath(): string
39
    {
40
        return $this->path;
41
    }
42
43
    /**
44
     * @return Operation[]
45
     */
46
    public function getOperations(): array
47
    {
48
        return $this->operations;
49
    }
50
51
    /**
52
     * @param string $method
53
     *
54
     * @return Operation
55
     */
56
    public function getOperation(string $method): Operation
57
    {
58
        $method = strtolower($method);
59
60 View Code Duplication
        if (!isset($this->operations[$method])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
            throw new \InvalidArgumentException(
62
                "Path '$this->path' does not support '$method'" .
63
                " (supports " . implode(', ', array_keys($this->operations)) . ')'
64
            );
65
        }
66
67
        return $this->operations[$method];
68
    }
69
70
    /**
71
     * @return Parameter[]
72
     */
73
    public function getPathParameters(): array
74
    {
75
        return $this->pathParameters;
76
    }
77
78
    /**
79
     * @param string    $method
80
     * @param \stdClass $operationDefinition
81
     *
82
     * @return Operation
83
     */
84
    abstract protected function createOperation(string $method, \stdClass $operationDefinition): Operation;
85
}
86