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

WrapperParser::_createArrayObject()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.4285
ccs 0
cts 10
cp 0
cc 3
eloc 9
nc 3
nop 3
crap 12
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 23
    public function __construct($wrapperClass)
45
    {
46 23
        $this->_wrapperClass = new ReflectionClass($wrapperClass);
47 23
    }
48
49 23
    public function parse()
50
    {
51 23
        $publicFields = $this->_wrapperClass->getProperties(ReflectionProperty::IS_PUBLIC);
52 23
        foreach ($publicFields as $field) {
53 21
            $this->_makeComplexType($field->getName(), $field->getDocComment());
54 23
        }
55 23
    }
56
57 21
    private function _makeComplexType($name, $docComment)
58
    {
59 21
        if (preg_match('#@type (\w*)\[\]#', $docComment, $matches)) {
60
            $type = $matches[1];
61
            $strategy = 'array';
62
        } else {
63 21
            preg_match('#@type (\w+)#', $docComment, $matches);
64 21
            if (isset($matches[1])) {
65 21
                $type = trim($matches[1]);
66 21
                $strategy = trim($matches[1]);
67 21
            } else {
68
                $type = 'void';
69
                $strategy = 'void';
70
            }
71
        }
72
73
        switch ($strategy) {
74 21
            case 'object':
75
                $this->_complexTypes[] = new Object($type, $name, $this->getComplexTypes());
76
                break;
77 21
            case 'wrapper':
78
                $this->_complexTypes[] = $this->_createWrapperObject($type, $name, $docComment);
79
                break;
80 21
            case 'array':
81
                $this->_complexTypes[] = $this->_createArrayObject($type, $name, $docComment);
82
                break;
83 21
            default:
84 21
                $this->_complexTypes[] = new ComplexTypeParser($type, $name);
85 21
                break;
86 21
        }
87 21
    }
88
    
89
    private function _createWrapperObject($type, $name, $docComment)
90
    {
91
        $wrapper = $this->wrapper($type, $docComment);
92
        $object = null;
93
        if ($wrapper->getComplexTypes()) {
94
            $object = new Object($type, $name, $wrapper->getComplexTypes());
95
        }
96
        return new Object($type, $name, $object);
97
    }
98
99
    private function _createArrayObject($type, $name, $docComment)
100
    {
101
        $object = null;
102
        if ($type == 'wrapper') {
103
            $complex = $this->wrapper($type, $docComment)->getComplexTypes();
104
            $object = new Object($type, $name, $complex);
105
        } elseif ($this->isComplex($type)) {
106
            $complex = $this->getComplexTypes();
107
            $object = new Object($type, $name, $complex);
108
        }
109
        return new Arrays($type, $name, $object);
110
    }
111
112 23
    public function getComplexTypes()
113
    {
114 23
        return $this->_complexTypes;
115
    }
116
    
117
    public function wrapper(&$type, $docComment)
118
    {
119
        if (!$this->isComplex($type)) {
120
            throw new WrapperParserException("This attribute is not complex type.");
121
        }
122
        preg_match('#@className=(.*?)(?:\s|$)#', $docComment, $matches);
123
        $className = $matches[1];
124
        $type = str_replace('\\', '', $className);
125
        $wrapperParser = new WrapperParser($className);
126
        $wrapperParser->parse();
127
        return $wrapperParser;
128
    }
129
130
    public function isComplex($type)
131
    {
132
        return in_array($type, array('object', 'wrapper'));
133
    }
134
}
135