Completed
Pull Request — master (#9)
by Asmir
148:13 queued 118:12
created

WssSecurityHeaderHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 35
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribingMethods() 0 11 1
A __construct() 0 4 1
A serializeHeader() 0 10 1
1
<?php
2
namespace GoetasWebservices\SoapServices\SoapClient\WssWsSecurity;
3
4
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Secext\AttributedStringType;
5
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Secext\Nonce;
6
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Secext\Password;
7
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Secext\Security as SecextSecurity;
8
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Secext\UsernameToken;
9
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Utility\Created;
10
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Utility\Expires;
11
use GoetasWebservices\SoapServices\SoapClient\WssWsSecurity\Utility\Timestamp;
12
use JMS\Serializer\GraphNavigator;
13
use JMS\Serializer\Handler\SubscribingHandlerInterface;
14
use JMS\Serializer\Metadata\StaticPropertyMetadata;
15
use JMS\Serializer\SerializationContext;
16
use JMS\Serializer\XmlSerializationVisitor;
17
18
class WssSecurityHeaderHandler implements SubscribingHandlerInterface
19
{
20
    /**
21
     * @var WsSecurityFilterRequest
22
     */
23
    protected $filter;
24
25
    public static function getSubscribingMethods()
26
    {
27
        return array(
28
            array(
29
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
30
                'format' => 'xml',
31
                'type' => Security::class,
32
                'method' => 'serializeHeader'
33
            )
34
        );
35
    }
36
37
    public function __construct(WsSecurityFilterRequest $filterResponse)
38
    {
39
        $this->filter = $filterResponse;
40
    }
41
42
    public function serializeHeader(XmlSerializationVisitor $visitor, Security $data, array $type, SerializationContext $context)
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
    {
44
45
        $securityHeader = $this->filter->filterDom($visitor->getDocument(), $data);
0 ignored issues
show
Bug introduced by
It seems like $visitor->getDocument() can be null; however, filterDom() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
46
47
        $currentNode = $visitor->getCurrentNode();
48
        $currentNode->parentNode->replaceChild($securityHeader, $currentNode);
49
        $visitor->revertCurrentNode();
50
        $visitor->setCurrentNode($securityHeader);
51
    }
52
}
53