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 Failed
Push — master ( 07c82e...4655b4 )
by Matthias
05:57
created

GuideController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 76
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
B detailAction() 0 36 6
A listAction() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Controller;
4
5
use Symfony\Component\Form\Extension\Core\Type\FormType;
6
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
7
use Symfony\Component\Form\FormFactoryInterface;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
use Twig\Environment;
12
use Twig_Environment;
0 ignored issues
show
Bug introduced by
The type Twig_Environment was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
14
/**
15
 * Guide for the configured shortcodes showing a list overview and detail pages with the rendered shortcode.
16
 */
17
final class GuideController
18
{
19
    /**
20
     * @var array
21
     *
22
     * Example structure: [
23
     *     [
24
     *         'shortcode' => 'img'
25
     *         'example' (optional key) => '[img src="https://upload.wikimedia.org/wikipedia/en/f/f7/RickRoll.png"]'
26
     *         'description' (optional key) => 'Embeds the imgage located at {src}.'
27
     *     ]
28
     * ]
29
     */
30
    private $shortcodeTags;
31
32
    /**
33
     * @var Environment|Twig_Environment
34
     */
35
    private $twig;
36
37
    /**
38
     * @var ?FormFactoryInterface
39
     */
40
    private $formFactory;
41
42
    /**
43
     * @param Twig_Environment|Environment $twig
44
     */
45
    public function __construct(array $shortcodeTags, $twig, FormFactoryInterface $formFactory = null)
46
    {
47
        $this->shortcodeTags = array_combine(array_map(function (array $definition): string { return $definition['shortcode']; }, $shortcodeTags), $shortcodeTags);
48
        $this->twig = $twig;
49
        $this->formFactory = $formFactory;
50
    }
51
52
    public function listAction(): Response
53
    {
54
        return new Response($this->twig->render('@WebfactoryShortcode/Guide/list.html.twig', ['shortcodeTags' => $this->shortcodeTags]));
55
    }
56
57
    public function detailAction(string $shortcode, Request $request): Response
58
    {
59
        if (!isset($this->shortcodeTags[$shortcode])) {
60
            throw new NotFoundHttpException();
61
        }
62
63
        $shortcodeTag = $this->shortcodeTags[$shortcode];
64
65
        // if custom parameters are provided, replace the example
66
        $customParameters = $request->get('customParameters');
67
        if ($customParameters) {
68
            $shortcodeTag['example'] = $shortcode.' '.$customParameters;
69
        }
70
71
        $example = '['.($shortcodeTag['example'] ?? $shortcode).']';
72
73
        if ($this->formFactory) {
74
            $formBuilder = $this->formFactory->createBuilder(FormType::class, ['example' => $example], ['method' => 'GET']);
75
            $formBuilder->add('example', TextareaType::class);
76
            $form = $formBuilder->getForm();
77
78
            $form->handleRequest($request);
79
80
            if ($form->isSubmitted()) {
81
                $example = $form->getData()['example'];
82
            }
83
        } else {
84
            $form = null;
85
        }
86
87
        return new Response(
88
            $this->twig->render(
89
                '@WebfactoryShortcode/Guide/detail.html.twig', [
90
                    'shortcodeTag' => $shortcodeTag,
91
                    'example' => $example,
92
                    'form' => $form ? $form->createView() : null,
93
                ]
94
            )
95
        );
96
    }
97
}
98