1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (C) 2013-2015 |
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\Parser; |
25
|
|
|
|
26
|
|
|
use Ouzo\Utilities\Arrays; |
27
|
|
|
use Ouzo\Utilities\Functions; |
28
|
|
|
use WSDL\Types\Type; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* MethodParser |
32
|
|
|
* |
33
|
|
|
* @author Piotr Olaszewski <[email protected]> |
34
|
|
|
*/ |
35
|
|
|
class MethodParser |
36
|
|
|
{ |
37
|
|
|
/** |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
private $name; |
41
|
|
|
/** |
42
|
|
|
* @var string |
43
|
|
|
*/ |
44
|
|
|
private $doc; |
45
|
|
|
/** |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
private $rawParameters; |
49
|
|
|
/** |
50
|
|
|
* @var string |
51
|
|
|
*/ |
52
|
|
|
private $rawReturn; |
53
|
|
|
|
54
|
39 |
|
public function __construct($name, $doc) |
55
|
|
|
{ |
56
|
39 |
|
$this->name = $name; |
57
|
39 |
|
$this->doc = $doc; |
58
|
39 |
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
1 |
|
public function description() |
64
|
|
|
{ |
65
|
1 |
|
preg_match('#@desc (.+)#', $this->doc, $groupMatches); |
66
|
1 |
|
$trimGroupMatches = Arrays::map($groupMatches, Functions::trim()); |
67
|
1 |
|
return Arrays::getValue($trimGroupMatches, 1, ''); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return Type[] |
72
|
|
|
*/ |
73
|
30 |
|
public function parameters() |
74
|
|
|
{ |
75
|
30 |
|
preg_match_all('#@param (.+)#', $this->doc, $groupMatches); |
76
|
30 |
|
$this->rawParameters = $groupMatches[1]; |
77
|
30 |
|
return ParameterParser::create($groupMatches[1], $this->getName()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @return Type |
82
|
|
|
*/ |
83
|
17 |
|
public function returning() |
84
|
|
|
{ |
85
|
17 |
|
preg_match_all('#@return (.+)#', $this->doc, $groupMatches); |
86
|
17 |
|
$this->rawReturn = $groupMatches[1]; |
87
|
17 |
|
return ParameterParser::create($groupMatches[1], $this->getName()); |
88
|
|
|
|
89
|
|
|
preg_match('#@return (.+)#', $this->doc, $groupMatches); |
|
|
|
|
90
|
|
|
$trimGroupMatches = array_map('trim', $groupMatches); |
91
|
|
|
if (isset($trimGroupMatches[1])) { |
92
|
|
|
$this->rawReturn = $trimGroupMatches[1]; |
93
|
|
|
} |
94
|
|
|
$parameterParser = new ParameterParser($this->rawReturn, $this->getName()); |
95
|
|
|
return $parameterParser->parse(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return string |
100
|
|
|
*/ |
101
|
|
|
public function getDoc() |
102
|
|
|
{ |
103
|
|
|
return $this->doc; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return string |
108
|
|
|
*/ |
109
|
37 |
|
public function getName() |
110
|
|
|
{ |
111
|
37 |
|
return $this->name; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return array |
116
|
|
|
*/ |
117
|
1 |
|
public function getRawParameters() |
118
|
|
|
{ |
119
|
1 |
|
$this->parameters(); |
120
|
1 |
|
return $this->rawParameters; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
1 |
|
public function getRawReturn() |
127
|
|
|
{ |
128
|
1 |
|
$this->returning(); |
129
|
1 |
|
return $this->rawReturn; |
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
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
orexit
statements that have been added for debug purposes.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.