Completed
Push — master ( 3c5f58...cea679 )
by Thijs
13s
created

SOAP::send()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SAML2;
4
5
/**
6
 * Class which implements the SOAP binding.
7
 *
8
 * @package SimpleSAMLphp
9
 */
10
class SOAP extends Binding
11
{
12
    public function getOutputToSend(Message $message)
13
    {
14
        $outputFromIdp = '<?xml version="1.0" encoding="UTF-8"?>';
15
        $outputFromIdp .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">';
16
        $outputFromIdp .= '<SOAP-ENV:Body>';
17
        $xmlMessage = $message->toSignedXML();
18
        Utils::getContainer()->debugMessage($xmlMessage, 'out');
0 ignored issues
show
Documentation introduced by
$xmlMessage is of type object<DOMElement>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
19
        $tempOutputFromIdp = $xmlMessage->ownerDocument->saveXML($xmlMessage);
20
        $outputFromIdp .= $tempOutputFromIdp;
21
        $outputFromIdp .= '</SOAP-ENV:Body>';
22
        $outputFromIdp .= '</SOAP-ENV:Envelope>';
23
24
        return $outputFromIdp;
25
    }
26
27
    /**
28
     * Send a SAML 2 message using the SOAP binding.
29
     *
30
     * Note: This function never returns.
31
     *
32
     * @param \SAML2\Message $message The message we should send.
33
     */
34
    public function send(Message $message)
35
    {
36
        header('Content-Type: text/xml', true);
37
        print($this->getOutputToSend($message));
38
        exit(0);
0 ignored issues
show
Coding Style Compatibility introduced by
The method send() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
39
    }
40
41
    /**
42
     * Receive a SAML 2 message sent using the HTTP-POST binding.
43
     *
44
     * Throws an exception if it is unable receive the message.
45
     *
46
     * @return \SAML2\Message The received message.
47
     * @throws \Exception
48
     */
49
    public function receive()
50
    {
51
        $postText = $this->getInputStream();
52
53
        if (empty($postText)) {
54
            throw new \Exception('Invalid message received to AssertionConsumerService endpoint.');
55
        }
56
57
        $document = DOMDocumentFactory::fromString($postText);
58
        $xml = $document->firstChild;
59
        Utils::getContainer()->debugMessage($xml, 'in');
0 ignored issues
show
Documentation introduced by
$xml is of type object<DOMNode>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
        $results = Utils::xpQuery($xml, '/soap-env:Envelope/soap-env:Body/*[1]');
61
62
        return Message::fromXML($results[0]);
63
    }
64
65
    protected function getInputStream()
66
    {
67
        return file_get_contents('php://input');
68
    }
69
}
70