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 ( 7f89d9...155582 )
by Tomas
8s
created

WrapperParser   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 38.24%

Importance

Changes 5
Bugs 2 Features 0
Metric Value
wmc 19
c 5
b 2
f 0
lcom 1
cbo 4
dl 0
loc 108
ccs 26
cts 68
cp 0.3824
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A parse() 0 7 2
B _makeComplexType() 0 31 6
A _createWrapperObject() 0 9 2
A _createArrayObject() 0 15 4
A getComplexTypes() 0 4 1
A wrapper() 0 12 2
A isComplex() 0 4 1
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 23
    public function __construct($wrapperClass)
51
    {
52 23
        $this->_wrapperClass = new ReflectionClass($wrapperClass);
53 23
    }
54
55 23
    public function parse()
56
    {
57 23
        $publicFields = $this->_wrapperClass->getProperties(ReflectionProperty::IS_PUBLIC);
58 23
        foreach ($publicFields as $field) {
59 21
            $this->_makeComplexType($field->getName(), $field->getDocComment());
60 23
        }
61 23
    }
62
63 21
    private function _makeComplexType($name, $docComment)
64
    {
65 21
        if (preg_match('#@type (\w*)\[\]#', $docComment, $matches)) {
66
            $type = $matches[1];
67
            $strategy = 'array';
68
        } else {
69 21
            preg_match('#@type (\w+)#', $docComment, $matches);
70 21
            if (isset($matches[1])) {
71 21
                $type = trim($matches[1]);
72 21
                $strategy = trim($matches[1]);
73 21
            } else {
74
                $type = 'void';
75
                $strategy = 'void';
76
            }
77
        }
78
79
        switch ($strategy) {
80 21
            case 'object':
81
                $this->_complexTypes[] = new Object($type, $name, $this->getComplexTypes());
82
                break;
83 21
            case 'wrapper':
84
                $this->_complexTypes[] = $this->_createWrapperObject($type, $name, $docComment);
85
                break;
86 21
            case 'array':
87
                $this->_complexTypes[] = $this->_createArrayObject($type, $name, $docComment);
88
                break;
89 21
            default:
90 21
                $this->_complexTypes[] = new ComplexTypeParser($type, $name);
91 21
                break;
92 21
        }
93 21
    }
94
95
    private function _createWrapperObject($type, $name, $docComment)
96
    {
97
        $wrapper = $this->wrapper($type, $docComment);
98
        $object = null;
99
        if ($wrapper->getComplexTypes()) {
100
            $object = new Object($type, $name, $wrapper->getComplexTypes());
101
        }
102
        return new Object($type, $name, $object);
103
    }
104
105
    private function _createArrayObject($type, $name, $docComment)
106
    {
107
        $object = null;
108
        if ($type == 'wrapper') {
109
            $complex = $this->wrapper($type, $docComment)->getComplexTypes();
110
            $object = new Object($type, $name, $complex);
111
        } elseif ($this->isComplex($type)) {
112
            $complex = $this->getComplexTypes();
113
            $object = new Object($type, $name, $complex);
114
        }
115
        if (!isset(self::$arrayCnt[$name])) {
116
            self::$arrayCnt[$name] = 0;
117
        }
118
        return new Arrays($type, $name, $object, self::$arrayCnt[$name]++);
119
    }
120
121 23
    public function getComplexTypes()
122
    {
123 23
        return $this->_complexTypes;
124
    }
125
126
    public function wrapper(&$type, $docComment)
127
    {
128
        if (!$this->isComplex($type)) {
129
            throw new WrapperParserException("This attribute is not complex type.");
130
        }
131
        preg_match('#@className=(.*?)(?:\s|$)#', $docComment, $matches);
132
        $className = $matches[1];
133
        $type = str_replace('\\', '', $className);
134
        $wrapperParser = new WrapperParser($className);
135
        $wrapperParser->parse();
136
        return $wrapperParser;
137
    }
138
139
    public function isComplex($type)
140
    {
141
        return in_array($type, array('object', 'wrapper'));
142
    }
143
}
144