CardResponseRequestHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
dl 0
loc 37
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A supportsRequest() 0 4 1
A handleRequest() 0 9 1
1
<?php
2
3
use MaxBeckers\AmazonAlexa\Helper\ResponseHelper;
4
use MaxBeckers\AmazonAlexa\Request\Request;
5
use MaxBeckers\AmazonAlexa\Request\Request\Standard\IntentRequest;
6
use MaxBeckers\AmazonAlexa\RequestHandler\AbstractRequestHandler;
7
use MaxBeckers\AmazonAlexa\Response\Card;
8
use MaxBeckers\AmazonAlexa\Response\Response;
9
10
/**
11
 * Just a simple example request handler for a card response.
12
 * To create a response with an image @see https://developer.amazon.com/de/docs/custom-skills/include-a-card-in-your-skills-response.html#creating-a-home-card-to-display-text-and-an-image
13
 *
14
 * @author Maximilian Beckers <[email protected]>
15
 */
16
class CardResponseRequestHandler extends AbstractRequestHandler
17
{
18
    /**
19
     * @var ResponseHelper
20
     */
21
    private $responseHelper;
22
23
    /**
24
     * @param ResponseHelper $responseHelper
25
     */
26
    public function __construct(ResponseHelper $responseHelper)
27
    {
28
        $this->responseHelper          = $responseHelper;
29
        $this->supportedApplicationIds = ['my_amazon_skill_id'];
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function supportsRequest(Request $request): bool
36
    {
37
        // support all intent requests, should not be done.
38
        return $request->request instanceof IntentRequest;
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function handleRequest(Request $request): Response
45
    {
46
        $card = Card::createSimple(
47
            'Example of the Card Title',
48
            "Example of card content. This card has just plain text content.\nThe content is formatted with line breaks to improve readability."
49
        );
50
        $this->responseHelper->card($card);
51
52
        return $this->responseHelper->respond('Text to speak back to the user.');
53
    }
54
}
55