Issues (1868)

src/LtiBundle/Component/OutcomeResponse.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\LtiBundle\Component;
8
9
use SimpleXMLElement;
10
11
abstract class OutcomeResponse
12
{
13
    public const TYPE_REPLACE = 'replace';
14
    public const TYPE_READ = 'read';
15
    public const TYPE_DELETE = 'delete';
16
17
    protected array $bodyParams;
18
    private OutcomeResponseStatus $statusInfo;
19
20
    /**
21
     * @param null|mixed $bodyParam
22
     */
23
    public function __construct(OutcomeResponseStatus $statusInfo, $bodyParam = null)
24
    {
25
        $this->statusInfo = $statusInfo;
26
        $this->bodyParams = $bodyParam;
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function __toString()
33
    {
34
        $xml = new SimpleXMLElement('<imsx_POXEnvelopeResponse></imsx_POXEnvelopeResponse>');
35
        $xml->addAttribute('xmlns', 'http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0');
36
37
        $headerInfo = $xml->addChild('imsx_POXHeader')->addChild('imsx_POXResponseHeaderInfo');
38
        $headerInfo->addChild('imsx_version', 'V1.0');
39
        $headerInfo->addChild('imsx_messageIdentifier', time());
40
41
        $statusInfo = $headerInfo->addChild('imsx_statusInfo');
42
        $statusInfo->addChild('imsx_codeMajor', $this->statusInfo->getCodeMajor());
43
        $statusInfo->addChild('imsx_severity', $this->statusInfo->getSeverity());
44
        $statusInfo->addChild('imsx_description', $this->statusInfo->getDescription());
45
        $statusInfo->addChild('imsx_messageRefIdentifier', $this->statusInfo->getMessageRefIdentifier());
46
        $statusInfo->addChild('imsx_operationRefIdentifier', $this->statusInfo->getOperationRefIdentifier());
47
48
        $body = $xml->addChild('imsx_POXBody');
49
50
        $this->generateBody($body);
51
52
        return $xml->asXML();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $xml->asXML() also could return the type true which is incompatible with the documented return type string.
Loading history...
53
    }
54
55
    abstract protected function generateBody(SimpleXMLElement $xmlBody);
56
}
57