Method   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 4
dl 0
loc 84
rs 10
c 0
b 0
f 0
ccs 20
cts 20
cp 1

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getName() 0 4 1
A getParameters() 0 4 1
A getHeaderParameter() 0 6 1
A getNoHeaderParameters() 0 6 1
A getNoHeaderParametersNodes() 0 4 1
A getReturn() 0 4 1
A getHeaderReturn() 0 8 2
A getReturnNode() 0 4 1
1
<?php
2
/**
3
 * Copyright (C) 2013-2020
4
 * Piotr Olaszewski <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
namespace WSDL\Builder;
25
26
use Ouzo\Utilities\Arrays;
27
use Ouzo\Utilities\Functions;
28
use Ouzo\Utilities\Optional;
29
use WSDL\Parser\Node;
30
31
/**
32
 * Method
33
 *
34
 * @author Piotr Olaszewski <[email protected]>
35
 */
36
class Method
37
{
38
    /**
39
     * @var string
40
     */
41
    private $name;
42
    /**
43
     * @var Parameter[]
44
     */
45
    private $parameters;
46
    /**
47
     * @var Parameter
48
     */
49
    private $return;
50
51
    /**
52
     * @param string $name
53
     * @param Parameter[] $parameters
54
     * @param Parameter|null $return
55
     */
56 6
    public function __construct(string $name, array $parameters, Parameter $return = null)
57
    {
58 6
        $this->name = $name;
59 6
        $this->parameters = $parameters;
60 6
        $this->return = $return;
61 6
    }
62
63
    public function getName(): string
64
    {
65
        return $this->name;
66 1
    }
67
68 1
    /**
69
     * @return Parameter[]
70
     */
71
    public function getParameters(): array
72
    {
73
        return $this->parameters;
74 1
    }
75
76 1
    public function getHeaderParameter(): ?Parameter
77
    {
78
        return Arrays::find($this->parameters, function (Parameter $parameter) {
79
            return $parameter->isHeader();
80
        });
81
    }
82 1
83
    /**
84
     * @return Parameter[]
85 1
     */
86 1
    public function getNoHeaderParameters(): array
87
    {
88
        return Arrays::filter($this->parameters, function (Parameter $parameter) {
89
            return !$parameter->isHeader();
90
        });
91
    }
92
93
    /**
94 1
     * @return Node[]
95 1
     */
96 1
    public function getNoHeaderParametersNodes(): array
97
    {
98
        return Arrays::map($this->getNoHeaderParameters(), Functions::extractExpression('getNode()'));
99
    }
100
101
    public function getReturn(): ?Parameter
102 1
    {
103
        return $this->return;
104 1
    }
105
106
    public function getHeaderReturn(): ?Parameter
107
    {
108
        if (Optional::fromNullable($this->return)->isHeader()->or(false)) {
109
            return $this->return;
110 1
        }
111
112 1
        return null;
113
    }
114
115
    public function getReturnNode(): ?Node
116
    {
117
        return Optional::fromNullable($this->return)->getNode()->or(null);
118 1
    }
119
}
120