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.

WrapperParser::wrapper()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 9
cp 0
cc 2
eloc 9
nc 2
nop 2
crap 6
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 ReflectionClass;
27
use ReflectionProperty;
28
use WSDL\Types\Arrays;
29
use WSDL\Types\Object;
30
31
/**
32
 * WrapperParser
33
 *
34
 * @author Piotr Olaszewski <[email protected]>
35
 */
36
class WrapperParser
37
{
38
    private $_wrapperClass;
39
    /**
40
     * @var ComplexTypeParser[]
41
     */
42
    private $_complexTypes;
43
44
    /**
45
     * @desc Count of arrays in document
46
     * @var array
47
     */
48
    static private $arrayCnt = [];
49
50 16
    public function __construct($wrapperClass)
51
    {
52 16
        $this->_wrapperClass = new ReflectionClass($wrapperClass);
53 16
    }
54
55 16
    public function parse()
56
    {
57 16
        $publicFields = $this->_wrapperClass->getProperties(ReflectionProperty::IS_PUBLIC);
58 16
        foreach ($publicFields as $field) {
59 14
            $this->_makeComplexType($field->getName(), $field->getDocComment());
60 16
        }
61 16
    }
62
63 14
    private function _makeComplexType($name, $docComment)
64
    {
65 14
        if (preg_match('#@type (\w*)\[\]#', $docComment, $matches)) {
66
            $type = $matches[1];
67
            $strategy = 'array';
68
        } else {
69 14
            preg_match('#@type (\w+)#', $docComment, $matches);
70 14
            if (isset($matches[1])) {
71 14
                $type = trim($matches[1]);
72 14
                $strategy = trim($matches[1]);
73 14
            } else {
74
                $type = 'void';
75
                $strategy = 'void';
76
            }
77
        }
78
79 14
        $optional = false;
80 14
        if (preg_match('#@optional#', $docComment, $matches)) {
81
            $optional = true;
82
        }
83
84
        switch ($strategy) {
85 14
            case 'object':
86
                $this->_complexTypes[] = new Object($type, $name, $this->getComplexTypes(), $optional);
87
                break;
88 14
            case 'wrapper':
89
                $this->_complexTypes[] = $this->_createWrapperObject($type, $name, $docComment, $optional);
90
                break;
91 14
            case 'array':
92
                $this->_complexTypes[] = $this->_createArrayObject($type, $name, $docComment, $optional);
93
                break;
94 14
            default:
95 14
                $this->_complexTypes[] = new ComplexTypeParser($type, $name, $optional);
96 14
                break;
97 14
        }
98 14
    }
99
100
    private function _createWrapperObject($type, $name, $docComment, $optional = false)
101
    {
102
        $wrapper = $this->wrapper($type, $docComment);
103
        $object = null;
104
        if ($wrapper->getComplexTypes()) {
105
            $object = new Object($type, $name, $wrapper->getComplexTypes(), $optional);
106
        }
107
        return new Object($type, $name, $object, $optional);
108
    }
109
110
    private function _createArrayObject($type, $name, $docComment, $optional = false)
111
    {
112
        $object = null;
113
        if ($type == 'wrapper') {
114
            $complex = $this->wrapper($type, $docComment)->getComplexTypes();
115
            $object = new Object($type, $name, $complex, $optional);
116
        } elseif ($this->isComplex($type)) {
117
            $complex = $this->getComplexTypes();
118
            $object = new Object($type, $name, $complex, $optional);
119
        }
120
        if (!isset(self::$arrayCnt[$name])) {
121
            self::$arrayCnt[$name] = 0;
122
        }
123
        return new Arrays($type, $name, $object, $optional, self::$arrayCnt[$name]++);
124
    }
125
126 16
    public function getComplexTypes()
127
    {
128 16
        return $this->_complexTypes;
129
    }
130
131
    public function wrapper(&$type, $docComment)
132
    {
133
        if (!$this->isComplex($type)) {
134
            throw new WrapperParserException("This attribute is not complex type.");
135
        }
136
        preg_match('#@className=(.*?)(?:\s|$)#', $docComment, $matches);
137
        $className = $matches[1];
138
        $type = str_replace('\\', '', $className);
139
        $wrapperParser = new WrapperParser($className);
140
        $wrapperParser->parse();
141
        return $wrapperParser;
142
    }
143
144
    public function isComplex($type)
145
    {
146
        return in_array($type, array('object', 'wrapper'));
147
    }
148
}
149