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.

WSDLCreator::getNamespaceWithSanitizedClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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;
25
26
use Exception;
27
use WSDL\Parser\ClassParser;
28
use WSDL\Service\Service;
29
use WSDL\Utilities\Strings;
30
use WSDL\XML\Styles\RpcLiteral;
31
use WSDL\XML\Styles\Style;
32
use WSDL\XML\XMLGenerator;
33
34
/**
35
 * WSDLCreator
36
 *
37
 * @author Piotr Olaszewski <[email protected]>
38
 */
39
class WSDLCreator
40
{
41
    private $_class;
42
    private $_location;
43
    /**
44
     * @var ClassParser
45
     */
46
    private $_classParser;
47
    private $_namespace = 'http://example.com/';
48
    /**
49
     * @var Style
50
     */
51
    private $_bindingStyle;
52
    /**
53
     * @var string
54
     */
55
    private $_locationSuffix;
56
57
    public function __construct($class, $location, $locationSuffix = 'wsdl')
58
    {
59
        $this->_class = $class;
60
        $this->_location = $location;
61
        $this->_locationSuffix = $locationSuffix;
62
        $this->_bindingStyle = new RpcLiteral();
63
        $this->_parseClass();
64
    }
65
66
    private function _parseClass()
67
    {
68
        $this->_classParser = new ClassParser($this->_class);
69
        $this->_classParser->parse();
70
    }
71
72
    public function renderWSDL()
73
    {
74
        header("Content-Type: text/xml");
75
        $xml = new XMLGenerator($this->_class, $this->_namespace, $this->_location);
76
        $xml
77
            ->setWSDLMethods($this->_classParser->getMethods())
78
            ->setBindingStyle($this->_bindingStyle)
79
            ->generate();
80
        $xml->render();
81
    }
82
83
    public function setNamespace($namespace)
84
    {
85
        $namespace = $this->_addSlashAtEndIfNotExists($namespace);
86
        $this->_namespace = $namespace;
87
        return $this;
88
    }
89
90
    public function getNamespaceWithSanitizedClass()
91
    {
92
        return Strings::sanitizedNamespaceWithClass($this->_namespace, $this->_class);
93
    }
94
95
    private function _addSlashAtEndIfNotExists($namespace)
96
    {
97
        return rtrim($namespace, '/') . '/';
98
    }
99
100
    public function setBindingStyle(Style $style = null)
101
    {
102
        if (!$style) {
103
            throw new Exception('Incorrect binding style.');
104
        }
105
        $this->_bindingStyle = $style;
106
        return $this;
107
    }
108
109
    public function renderWSDLService()
110
    {
111
        $headers = apache_request_headers();
112
        if (empty($headers['Content-Type']) || !preg_match('#xml#i', $headers['Content-Type'])) {
113
            $newService = new Service($this->_location, $this->getWsdlLocation(), $this->_classParser->getMethods());
114
            $newService->render($this->_class, $this->getNamespaceWithSanitizedClass());
115
        }
116
    }
117
118
    public function getLocation()
119
    {
120
        return $this->_location;
121
    }
122
123
    public function getWsdlLocation()
124
    {
125
        return $this->_location . '?' . $this->_locationSuffix;
126
    }
127
}
128