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.

Style   A
last analyzed

Complexity

Total Complexity 28

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 85.29%

Importance

Changes 0
Metric Value
wmc 28
lcom 1
cbo 5
dl 0
loc 120
rs 10
c 0
b 0
f 0
ccs 58
cts 68
cp 0.8529

14 Methods

Rating   Name   Duplication   Size   Complexity  
bindingStyle() 0 1 ?
bindingUse() 0 1 ?
methodInput() 0 1 ?
methodOutput() 0 1 ?
typeParameters() 0 1 ?
typeReturning() 0 1 ?
A _createElement() 0 13 2
B _prepareTypeAndValue() 0 16 5
A _getObjectName() 0 4 2
A _generateType() 0 10 3
A _generateComplexType() 0 10 3
A _generateArray() 0 16 4
A _generateObject() 0 21 4
B _setComplexTypeIfNeeded() 0 8 5
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\XML\Styles;
25
26
use Ouzo\Utilities\Inflector;
27
use WSDL\Parser\MethodParser;
28
use WSDL\Types\Type;
29
use WSDL\Utilities\Strings;
30
use WSDL\Utilities\TypeHelper;
31
32
/**
33
 * Style
34
 *
35
 * @author Piotr Olaszewski <[email protected]>
36
 */
37
abstract class Style
38
{
39
    abstract public function bindingStyle();
40
41
    abstract public function bindingUse();
42
43
    abstract public function methodInput(MethodParser $method);
44
45
    abstract public function methodOutput(MethodParser $method);
46
47
    abstract public function typeParameters(MethodParser $method);
48
49
    abstract public function typeReturning(MethodParser $method);
50
51
    protected function _createElement(Type $returning)
52
    {
53
        list($type, $value) = $this->_prepareTypeAndValue($returning);
54
        $element = array(
55
            'name' => $returning->getName(),
56
            $type => $value
57
        );
58
59
        if ($returning->getOptional()) {
60
            $element['minOccurs'] = 0;
61
        }
62
        return $element;
63
    }
64
65 23
    protected function _prepareTypeAndValue(Type $parameter)
66
    {
67 23
        $type = '';
68 23
        $value = '';
69 23
        if (TypeHelper::isSimple($parameter)) {
70 20
            $type = 'type';
71 20
            $value = TypeHelper::getXsdType($parameter->getType());
72 23
        } elseif (TypeHelper::isArray($parameter)) {
73 12
            $type = 'type';
74 12
            $value = 'ns:' . 'ArrayOf' . ucfirst($parameter->getName()) . ($parameter->getCounter() ? $parameter->getCounter() : '');
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getCounter() does only exist in the following implementations of said interface: WSDL\Types\Arrays.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
75 19
        } elseif (TypeHelper::isObject($parameter)) {
76 11
            $type = 'element';
77 11
            $value = 'ns:' . $this->_getObjectName($parameter);
78 11
        }
79 23
        return array($type, $value);
80
    }
81
82 25
    protected function _getObjectName(Type $parameter)
83
    {
84 25
        return $parameter->getType() == 'object' ? ucfirst($parameter->getName()) : $parameter->getType();
85
    }
86
87 19
    protected function _generateType($parameter)
88
    {
89 19
        if (!TypeHelper::isSimple($parameter)) {
90 19
            $generateComplexType = $this->_generateComplexType($parameter);
91 12
            if ($generateComplexType) {
92 12
                return $generateComplexType;
93
            }
94
        }
95 7
        return null;
96
    }
97
98 25
    protected function _generateComplexType(Type $parameter)
99
    {
100 25
        if (TypeHelper::isArray($parameter)) {
101 8
            return $this->_generateArray($parameter);
102
        }
103 17
        if (TypeHelper::isObject($parameter)) {
104 17
            return $this->_generateObject($parameter);
105
        }
106
        return null;
107
    }
108
109 16
    protected function _generateArray(Type $parameter)
110
    {
111 16
        $type = $parameter->getComplexType() ? 'ns:' : 'xsd:';
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getComplexType() does only exist in the following implementations of said interface: WSDL\Types\Arrays, WSDL\Types\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
112
113 16
        $typesComplex = new TypesComplex();
114
        $typesComplex
115 16
            ->setName('ArrayOf' . ucfirst($parameter->getName()) . ($parameter->getCounter() ? $parameter->getCounter() : ''))
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getCounter() does only exist in the following implementations of said interface: WSDL\Types\Arrays.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
116 16
            ->setArrayType($type . $this->_getObjectName($parameter) . '[]')
117 16
            ->setArrayTypeName(Inflector::singularize($parameter->getName()));
118
119 16
        if ($parameter->getComplexType()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getComplexType() does only exist in the following implementations of said interface: WSDL\Types\Arrays, WSDL\Types\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
120 8
            $typesComplex->setComplex($this->_generateObject($parameter->getComplexType()));
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getComplexType() does only exist in the following implementations of said interface: WSDL\Types\Arrays, WSDL\Types\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
121 8
        }
122
123 16
        return $typesComplex;
124
    }
125
126 21
    protected function _generateObject(Type $parameter)
127
    {
128 21
        $typesElement = new TypesElement();
129 21
        $typesElement->setName($this->_getObjectName($parameter));
130
131 21
        $types = is_array($parameter->getComplexType()) ? $parameter->getComplexType() : $parameter->getComplexType()->getComplexType();
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getComplexType() does only exist in the following implementations of said interface: WSDL\Types\Arrays, WSDL\Types\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
132
133 21
        foreach ($types as $complexType) {
134 21
            if ($complexType instanceof Type) {
135 20
                list($type, $value) = $this->_prepareTypeAndValue($complexType);
136 20
            } else {
137 9
                $type = 'type';
138 9
                $value = TypeHelper::getXsdType($complexType->getType());
139
            }
140
141 21
            $typesElement->setElementAttributes($type, $value, $complexType->getName(), $complexType->getOptional());
142
143 21
            $this->_setComplexTypeIfNeeded($complexType, $typesElement);
144 21
        }
145 21
        return $typesElement;
146
    }
147
148 21
    protected function _setComplexTypeIfNeeded($complexType, TypesElement $typesElement)
149
    {
150 21
        if (TypeHelper::isArray($complexType)) {
151 8
            $typesElement->setComplex($this->_generateArray($complexType));
152 21
        } elseif ($complexType instanceof Type && !TypeHelper::isSimple($complexType) && $complexType->getComplexType()) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getComplexType() does only exist in the following implementations of said interface: WSDL\Types\Arrays, WSDL\Types\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
153 4
            $typesElement->setComplex($this->_generateComplexType($complexType->getComplexType()));
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface WSDL\Types\Type as the method getComplexType() does only exist in the following implementations of said interface: WSDL\Types\Arrays, WSDL\Types\Object.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
154 4
        }
155 21
    }
156
}
157