Completed
Push — master ( 7cb054...584ba8 )
by Tim
44:11 queued 26:38
created

ComplexTypeParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 46
rs 10
wmc 6
lcom 0
cbo 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
use Ouzo\Utilities\Strings;
26
27
/**
28
 * ComplexTypeParser
29
 *
30
 * @author Piotr Olaszewski <[email protected]>
31
 */
32
class ComplexTypeParser
33
{
34
    private $_type;
35
    private $_name;
36
37
    public function __construct($type, $name)
38
    {
39
        $this->_type = $type;
40
        $this->_name = $name;
41
    }
42
43
    public function getName()
44
    {
45
        return $this->_name;
46
    }
47
48
    public function getType()
49
    {
50
        return $this->_type;
51
    }
52
53
    /**
54
     * @param string $types
55
     * @return ComplexTypeParser[]
56
     */
57
    public static function create($types)
58
    {
59
        preg_match_all('#@(\((?:.+)\)|(?:.+?))(?: |$)#', $types, $matches);
60
        $typesArray = $matches[1];
61
        $obj = array_map(function ($type) {
62
            if (ComplexTypeParser::isReflectionType($type)) {
63
                $type = str_replace(array('(', ')'), '', $type);
64
            } else {
65
                $type = str_replace('=', ' ', $type);
66
            }
67
            $parser = new ParameterParser($type, '');
68
            return $parser->parse();
69
        }, $typesArray);
70
        return $obj;
71
    }
72
73
    public static function isReflectionType($types)
74
    {
75
        return Strings::contains($types, 'className');
76
    }
77
}
78