GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Test Setup Failed
Push — master ( aeed96...e25155 )
by Malte
03:19
created

EmbeddedShortcodeHandler   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 60.61%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
eloc 38
c 3
b 0
f 0
dl 0
loc 82
rs 10
ccs 20
cts 33
cp 0.6061

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A __invoke() 0 39 3
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Handler;
4
5
use Psr\Log\LoggerInterface;
6
use Psr\Log\NullLogger;
7
use Symfony\Component\HttpFoundation\RequestStack;
8
use Symfony\Component\HttpKernel\Controller\ControllerReference;
9
use Symfony\Component\HttpKernel\Fragment\FragmentHandler;
10
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
11
12
/**
13
 * Handler for thunderer\Shortcode that embeds the configured renderer for a shortcode.
14
 *
15
 * The attributes of the shortcode will be passed on as parameters to the controller.
16
 */
17
class EmbeddedShortcodeHandler
18
{
19
    /** @var FragmentHandler */
20
    private $fragmentHandler;
21
22
    /** @var string */
23
    private $controllerName;
24
25
    /** @var string */
26
    private $renderer;
27
28
    /** @var LoggerInterface */
29
    private $logger;
30
31
    /** @var RequestStack */
32
    private $requestStack;
33
34
    /**
35
     * @param FragmentHandler $fragmentHandler
36
     * @param string          $controllerName
37
     * @param string          $renderer
38
     * @param LoggerInterface $logger
39
     * @param RequestStack    $requestStack
40
     */
41 4
    public function __construct(
42
        FragmentHandler $fragmentHandler,
43
        $controllerName,
44
        $renderer,
45
        RequestStack $requestStack,
46
        LoggerInterface $logger = null
47
    ) {
48 4
        $this->fragmentHandler = $fragmentHandler;
49 4
        $this->controllerName = $controllerName;
50 4
        $this->renderer = $renderer;
51 4
        $this->requestStack = $requestStack;
52 4
        $this->logger = $logger ?: new NullLogger();
53 4
    }
54
55
    /**
56
     * @param ShortcodeInterface $shortcode
57
     *
58
     * @return string|null
59
     */
60 2
    public function __invoke(ShortcodeInterface $shortcode)
61
    {
62 2
        $this->logger->notice(
63 2
            'Request {controllerName} with parameters {parameters} and renderer {renderer} to resolve shortcode {shortcode}, triggered by a request to {url}.',
64
            [
65 2
                'controllerName' => $this->controllerName,
66 2
                'parameters' => json_encode($shortcode->getParameters()),
67 2
                'renderer' => $this->renderer,
68 2
                'shortcode' => $shortcode->getName(),
69 2
                'url' => $this->requestStack->getMasterRequest()->getRequestUri(),
70
            ]
71
        );
72
73
        try {
74 2
            return $this->fragmentHandler->render(
75 2
                new ControllerReference(
76 2
                    $this->controllerName,
77 2
                    array_merge(['request' => $this->requestStack->getCurrentRequest()], $shortcode->getParameters())
78
                ),
79 2
                $this->renderer
80
            );
81
        } catch (\InvalidArgumentException $exception) {
82
            if ('esi' === $this->renderer) {
83
                throw new \InvalidArgumentException(
84
                    'An InvalidArgumentException occured while trying to render the shortcode '
85
                    .$shortcode->getShortcodeText().'. You\'ve probably tried to use the ESI rendering  strategy for '
0 ignored issues
show
Bug introduced by
The method getShortcodeText() does not exist on Thunder\Shortcode\Shortcode\ShortcodeInterface. It seems like you code against a sub-type of Thunder\Shortcode\Shortcode\ShortcodeInterface such as Thunder\Shortcode\Shortcode\ProcessedShortcode. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

85
                    .$shortcode->/** @scrutinizer ignore-call */ getShortcodeText().'. You\'ve probably tried to use the ESI rendering  strategy for '
Loading history...
86
                    .'your shortcodes while handling a request that contained non-scalar values as part of URI '
87
                    .'attributes. This can happen e.g. when using Param Converters for your original controller '
88
                    .'action, as the request (containing the conversion result) is automatically passed to the call of '
89
                    .'the shortcode controller to allow context sensitive shortcodes. You could use '
90
                    .'Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler.inline as parent in your '
91
                    .'shortcode\'s service defintion, so that the inline instead of ESI rendering strategy will be '
92
                    .'used.',
93
                    0,
94
                    $exception
95
                );
96
            }
97
98
            throw $exception;
99
        }
100
    }
101
}
102