GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 5eec76...4a16d9 )
by Tomas
06:12
created

ParameterParser::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
ccs 7
cts 7
cp 1
cc 2
eloc 6
nc 2
nop 2
crap 2
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 as OuzoArrays;
27
use WSDL\Types\Arrays;
28
use WSDL\Types\Object;
29
use WSDL\Types\Simple;
30
31
/**
32
 * ParameterParser
33
 *
34
 * @author Piotr Olaszewski <[email protected]>
35
 */
36
class ParameterParser
37
{
38
    private $_strategy;
39
    private $_parameter;
40
    private $_type;
41
    private $_name;
42
    private $_methodName;
43
    private $_optional;
44
45 47
    public function __construct($parameter, $methodName = '')
46
    {
47 47
        $this->_parameter = trim($parameter);
48 47
        $this->_methodName = $methodName;
49 47
    }
50
51 46
    public function parse()
52
    {
53 46
        return $this->_detectType();
54
    }
55
56 46
    private function _detectType()
57
    {
58 46
        $this->_parseAndSetType();
59 46
        $this->_parseAndSetName();
60 46
        $this->_parseAndSetOptional();
61
62 46
        switch ($this->_strategy) {
63 46
            case 'object':
64 21
                return new Object($this->getType(), $this->getName(), $this->complexTypes(), $this->getOptional());
65 46
            case 'wrapper':
66 7
                return $this->_createWrapperObject();
67 44
            case 'array':
68 21
                return $this->_createArrayObject();
69 38
            default:
70 38
                return new Simple($this->getType(), $this->getName(), $this->getOptional());
71 38
        }
72
    }
73
74 46
    private function _parseAndSetType()
75
    {
76 46
        if (preg_match('#^(\w*)\[\]#', $this->_parameter, $type)) {
77 21
            $this->_type = $type[1];
78 21
            $this->_strategy = 'array';
79 21
        } else {
80 40
            preg_match('#(\w+)#', $this->_parameter, $type);
81 40
            if (isset($type[1])) {
82 40
                $this->_type = $type[1];
83 40
                $this->_strategy = $type[1];
84 40
            } else {
85
                $this->_type = 'void';
86
                $this->_strategy = 'void';
87
            }
88
        }
89 46
    }
90
91 46
    private function _parseAndSetName()
92
    {
93 46
        preg_match('#\\$(\w+)#', $this->_parameter, $name);
94 46
        $this->_name = OuzoArrays::getValue($name, 1, '');
95 46
    }
96
97 46
    private function _parseAndSetOptional()
98
    {
99 46
        preg_match('#\\$(\w+)#', $this->_parameter, $name);
100 46
        $this->_optional  = !!preg_match('#@optional#', $this->_parameter, $matches);
101 46
    }
102
103 7
    private function _createWrapperObject()
104
    {
105 7
        $wrapper = $this->wrapper();
106 7
        $object = null;
107 7
        if ($wrapper->getComplexTypes()) {
108 7
            $object = new Object($this->getType(), $this->getName(), $wrapper->getComplexTypes(), $this->getOptional());
109 7
        }
110 7
        return new Object($this->getType(), $this->getName(), $object, $this->getOptional());
111
    }
112
113 21
    private function _createArrayObject()
114
    {
115 21
        $object = null;
116 21
        if ($this->_type == 'wrapper') {
117 9
            $complex = $this->wrapper()->getComplexTypes();
118 9
            $object = new Object($this->getType(), $this->getName(), $complex, $this->getOptional());
119 21
        } elseif ($this->isComplex()) {
120 5
            $complex = $this->complexTypes();
121 5
            $object = new Object($this->getType(), $this->getName(), $complex, $this->getOptional());
122 5
        }
123 21
        return new Arrays($this->getType(), $this->getName(), $object, $this->getOptional());
124
    }
125
126 47
    public function getType()
127
    {
128 47
        return $this->_type;
129
    }
130
131 46
    public function getName()
132
    {
133 46
        return $this->_name;
134
    }
135
136 46
    public function getOptional()
137
    {
138 46
        return $this->_optional;
139
    }
140
141 26
    public function complexTypes()
142
    {
143 26
        if (!$this->isComplex()) {
144 1
            throw new ParameterParserException("This parameter is not complex type.");
145
        }
146 25
        preg_match("#(@.+)#", $this->_parameter, $complexTypes);
147 25
        return ComplexTypeParser::create($complexTypes[1]);
148
    }
149
150 15
    public function wrapper()
151
    {
152 15
        if (!$this->isComplex()) {
153
            throw new ParameterParserException("This parameter is not complex type.");
154
        }
155 15
        preg_match('#@className=(.*?)(?:\s|$)#', $this->_parameter, $matches);
156 15
        $className = $matches[1];
157 15
        $this->_type = str_replace('\\', '', $className);
158 15
        $wrapperParser = new WrapperParser($className);
159 15
        $wrapperParser->parse();
160 15
        return $wrapperParser;
161
    }
162
163 35
    public function isComplex()
164
    {
165 35
        return in_array($this->getType(), array('object', 'wrapper'));
166
    }
167
168
    /**
169
     * @param array $parameters
170
     * @param $methodName
171
     * @return ParameterParser[]
172
     */
173 39
    public static function create($parameters, $methodName)
174
    {
175 39
        $obj = array();
176 39
        foreach ($parameters as $parameter) {
177 39
            $parser = new self($parameter, $methodName);
178 39
            $obj[] = $parser->parse();
179 39
        }
180 39
        return $obj;
181
    }
182
}
183