Issues (1574)

Soap/Serializer/SoapAddressingEventSubscriber.php (30 issues)

1
<?php
2
0 ignored issues
show
Missing file doc comment
Loading history...
3
namespace DMT\Insolvency\Soap\Serializer;
4
5
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
6
use JMS\Serializer\EventDispatcher\ObjectEvent;
7
use JMS\Serializer\SerializationContext;
8
use JMS\Serializer\XmlSerializationVisitor;
9
10
/**
11
 * Class SoapAddressingEventSubscriber
12
 */
0 ignored issues
show
Missing @category tag in class comment
Loading history...
Missing @package tag in class comment
Loading history...
Missing @author tag in class comment
Loading history...
Missing @license tag in class comment
Loading history...
Missing @link tag in class comment
Loading history...
13
class SoapAddressingEventSubscriber implements EventSubscriberInterface
14
{
15
    /** @var string $action */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
16
    protected $action = 'http://www.rechtspraak.nl/namespaces/cir01/%s';
17
18
    /** @var string $endPoint */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
19
    protected $endPoint = 'https://webservice.rechtspraak.nl/cir.asmx';
20
21
    /**
22
     * SoapAddressingEventSubscriber constructor.
23
     * @param string|null $action
0 ignored issues
show
There must be exactly one blank line before the tags in a doc comment
Loading history...
Missing parameter comment
Loading history...
24
     * @param string|null $endPoint
0 ignored issues
show
Missing parameter comment
Loading history...
25
     */
26 13
    public function __construct(string $action = null, string $endPoint = null)
27
    {
28 13
        if ($action) {
29
            $this->action = $action;
30
        }
31 13
        if ($endPoint) {
32
            $this->endPoint = $endPoint;
33
        }
34 13
    }
35
36
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
37
     * @return array
38
     */
39 12
    public static function getSubscribedEvents()
40
    {
41
        return [
42
            [
43 12
                'event' => 'serializer.post_serialize',
44
                'method' => 'addAddressing',
45
                'format' => 'soap',
46
            ]
47
        ];
48
    }
49
50
    /**
0 ignored issues
show
Missing short description in doc comment
Loading history...
51
     * @param ObjectEvent $event
0 ignored issues
show
Missing parameter comment
Loading history...
52
     */
0 ignored issues
show
Missing @return tag in function comment
Loading history...
53 12
    public function addAddressing(ObjectEvent $event)
54
    {
55
        /** @var SerializationContext $context */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
56 12
        $context = $event->getContext();
57
        /** @var XmlSerializationVisitor $visitor */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
58 12
        $visitor = $event->getVisitor();
59
60 12
        $document = $visitor->getDocument();
61 12
        $xpath = new \DOMXPath($document);
62 12
        $query = '//*[local-name()="Action" and namespace-uri()="http://schemas.xmlsoap.org/ws/2004/08/addressing"]';
63 12
        $namespace = $document->lookupNamespaceUri('soap');
64
65
        if (
0 ignored issues
show
First condition of a multi-line IF statement must directly follow the opening parenthesis
Loading history...
66 12
            $context->getDepth() > 0
0 ignored issues
show
Each line in a multi-line IF statement must begin with a boolean operator
Loading history...
67 12
            || $document->getElementsByTagNameNS($namespace, 'Body')->length == 0
68 12
            || $document->getElementsByTagNameNS($namespace, 'Header')->length == 0
69 12
            || $xpath->query($query)->length > 0
70
        ) {
71 11
            return;
72
        }
73
74 12
        $action = sprintf(
75 12
            $this->action,
76 12
            $document->getElementsByTagNameNS($namespace, 'Body')[0]->firstChild->localName
77
        );
78
79
        /** @var \DOMElement $element */
0 ignored issues
show
The open comment tag must be the only content on the line
Loading history...
Missing short description in doc comment
Loading history...
The close comment tag must be the only content on the line
Loading history...
80 12
        $element = $document->getElementsByTagNameNS($namespace, 'Header')[0];
81 12
        $element->appendChild(
82 12
            $document->createElementNS('http://schemas.xmlsoap.org/ws/2004/08/addressing', 'Action', $action)
83
        );
84 12
        $element->appendChild(
85 12
            $document->createElementNS('http://schemas.xmlsoap.org/ws/2004/08/addressing', 'To', $this->endPoint)
86
        );
87
    }
88
}