Passed
Push — master ( 65060b...2b54a2 )
by Julito
10:15
created

ImsLtiServiceRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 74
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A process() 0 6 1
A processHeader() 0 7 1
A generateResponse() 0 9 1
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
/**
5
 * Class ImsLtiServiceRequest.
6
 */
7
abstract class ImsLtiServiceRequest
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $responseType;
13
14
    /**
15
     * @var SimpleXMLElement
16
     */
17
    protected $xmlHeaderInfo;
18
19
    /**
20
     * @var SimpleXMLElement
21
     */
22
    protected $xmlRequest;
23
24
    /**
25
     * @var ImsLtiServiceResponseStatus
26
     */
27
    protected $statusInfo;
28
29
    /**
30
     * @var mixed
31
     */
32
    protected $responseBodyParam;
33
34
    /**
35
     * ImsLtiServiceRequest constructor.
36
     *
37
     * @param SimpleXMLElement $xml
38
     */
39
    public function __construct(SimpleXMLElement $xml)
40
    {
41
        $this->statusInfo = new ImsLtiServiceResponseStatus();
42
43
        $this->xmlHeaderInfo = $xml->imsx_POXHeader->imsx_POXRequestHeaderInfo;
44
        $this->xmlRequest = $xml->imsx_POXBody->children();
45
    }
46
47
    protected function processHeader()
48
    {
49
        $info = $this->xmlHeaderInfo;
50
51
        $this->statusInfo->setMessageRefIdentifier($info->imsx_messageIdentifier);
52
53
        error_log("Service Request: tool version {$info->imsx_version} message ID {$info->imsx_messageIdentifier}");
54
    }
55
56
    abstract protected function processBody();
57
58
    /**
59
     * @return ImsLtiServiceResponse|null
60
     */
61
    private function generateResponse()
62
    {
63
        $response = ImsLtiServiceResponseFactory::create(
64
            $this->responseType,
65
            $this->statusInfo,
66
            $this->responseBodyParam
67
        );
68
69
        return $response;
70
    }
71
72
    /**
73
     * @return ImsLtiServiceResponse|null
74
     */
75
    public function process()
76
    {
77
        $this->processHeader();
78
        $this->processBody();
79
80
        return $this->generateResponse();
81
    }
82
}