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 ( fa9233...7f89d9 )
by Tomas
06:55
created

ParameterParser   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 98.75%

Importance

Changes 16
Bugs 1 Features 3
Metric Value
wmc 24
c 16
b 1
f 3
lcom 1
cbo 7
dl 0
loc 134
rs 10
ccs 79
cts 80
cp 0.9875

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parse() 0 4 1
A _detectType() 0 16 4
A _parseAndSetType() 0 16 3
A _parseAndSetName() 0 5 1
A _createWrapperObject() 0 9 2
A _createArrayObject() 0 12 3
A getType() 0 4 1
A getName() 0 4 1
A complexTypes() 0 8 2
A wrapper() 0 12 2
A isComplex() 0 4 1
A create() 0 9 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
44 47
    public function __construct($parameter, $methodName = '')
45
    {
46 47
        $this->_parameter = trim($parameter);
47 47
        $this->_methodName = $methodName;
48 47
    }
49
50 46
    public function parse()
51
    {
52 46
        return $this->_detectType();
53
    }
54
55 46
    private function _detectType()
56
    {
57 46
        $this->_parseAndSetType();
58 46
        $this->_parseAndSetName();
59
60 46
        switch ($this->_strategy) {
61 46
            case 'object':
62 28
                return new Object($this->getType(), $this->getName(), $this->complexTypes());
63 46
            case 'wrapper':
64 14
                return $this->_createWrapperObject();
65 44
            case 'array':
66 28
                return $this->_createArrayObject();
67 38
            default:
68 38
                return new Simple($this->getType(), $this->getName());
69 38
        }
70
    }
71
72 46
    private function _parseAndSetType()
73
    {
74 46
        if (preg_match('#^(\w*)\[\]#', $this->_parameter, $type)) {
75 28
            $this->_type = $type[1];
76 28
            $this->_strategy = 'array';
77 28
        } else {
78 40
            preg_match('#(\w+)#', $this->_parameter, $type);
79 40
            if (isset($type[1])) {
80 40
                $this->_type = $type[1];
81 40
                $this->_strategy = $type[1];
82 40
            } else {
83 8
                $this->_type = 'void';
84 8
                $this->_strategy = 'void';
85
            }
86
        }
87 46
    }
88
89 46
    private function _parseAndSetName()
90
    {
91 46
        preg_match('#\\$(\w+)#', $this->_parameter, $name);
92 46
        $this->_name = OuzoArrays::getValue($name, 1, '');
93 46
    }
94
95 14
    private function _createWrapperObject()
96
    {
97 14
        $wrapper = $this->wrapper();
98 14
        $object = null;
99 14
        if ($wrapper->getComplexTypes()) {
100 14
            $object = new Object($this->getType(), $this->getName(), $wrapper->getComplexTypes());
101 14
        }
102 14
        return new Object($this->getType(), $this->getName(), $object);
103
    }
104
105 28
    private function _createArrayObject()
106
    {
107 28
        $object = null;
108 28
        if ($this->_type == 'wrapper') {
109 16
            $complex = $this->wrapper()->getComplexTypes();
110 16
            $object = new Object($this->getType(), $this->getName(), $complex);
111 28
        } elseif ($this->isComplex()) {
112 5
            $complex = $this->complexTypes();
113 5
            $object = new Object($this->getType(), $this->getName(), $complex);
114 5
        }
115 28
        return new Arrays($this->getType(), $this->getName(), $object);
116
    }
117
118 47
    public function getType()
119
    {
120 47
        return $this->_type;
121
    }
122
123 46
    public function getName()
124
    {
125 46
        return $this->_name;
126
    }
127
128 33
    public function complexTypes()
129
    {
130 33
        if (!$this->isComplex()) {
131 1
            throw new ParameterParserException("This parameter is not complex type.");
132
        }
133 32
        preg_match("#(@.+)#", $this->_parameter, $complexTypes);
134 32
        return ComplexTypeParser::create($complexTypes[1]);
135
    }
136
137 22
    public function wrapper()
138
    {
139 22
        if (!$this->isComplex()) {
140
            throw new ParameterParserException("This parameter is not complex type.");
141
        }
142 22
        preg_match('#@className=(.*?)(?:\s|$)#', $this->_parameter, $matches);
143 22
        $className = $matches[1];
144 22
        $this->_type = str_replace('\\', '', $className);
145 22
        $wrapperParser = new WrapperParser($className);
146 22
        $wrapperParser->parse();
147 22
        return $wrapperParser;
148
    }
149
150 42
    public function isComplex()
151
    {
152 42
        return in_array($this->getType(), array('object', 'wrapper'));
153
    }
154
155
    /**
156
     * @param array $parameters
157
     * @param $methodName
158
     * @return ParameterParser[]
159
     */
160 32
    public static function create($parameters, $methodName)
161
    {
162 32
        $obj = array();
163 32
        foreach ($parameters as $parameter) {
164 31
            $parser = new self($parameter, $methodName);
165 31
            $obj[] = $parser->parse();
166 32
        }
167 32
        return $obj;
168
    }
169
}
170