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.

GDPRInformationBlockService   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
eloc 39
c 5
b 0
f 0
dl 0
loc 93
rs 10
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 13 2
A configureSettings() 0 7 1
A configureEditForm() 0 23 1
A configureCreateForm() 0 3 1
A getMetadata() 0 4 1
A validate() 0 2 1
A __construct() 0 5 1
A hasGdprCookie() 0 5 2
A getName() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\GDPRBundle\Block\Service;
13
14
use Sonata\BlockBundle\Block\BlockContextInterface;
15
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
16
use Sonata\BlockBundle\Block\Service\EditableBlockService;
17
use Sonata\BlockBundle\Form\Mapper\FormMapper;
18
use Sonata\BlockBundle\Meta\Metadata;
19
use Sonata\BlockBundle\Meta\MetadataInterface;
20
use Sonata\BlockBundle\Model\BlockInterface;
21
use Sonata\Form\Type\ImmutableArrayType;
22
use Sonata\Form\Validator\ErrorElement;
23
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
24
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
25
use Symfony\Component\Form\Extension\Core\Type\TextType;
26
use Symfony\Component\Form\Extension\Core\Type\UrlType;
27
use Symfony\Component\HttpFoundation\RequestStack;
28
use Symfony\Component\HttpFoundation\Response;
29
use Symfony\Component\OptionsResolver\OptionsResolver;
30
31
final class GDPRInformationBlockService extends AbstractBlockService implements EditableBlockService
32
{
33
    public const COOKIE_NAME = 'GDPR_COOKIE_LAW_CONSENT';
34
35
    /**
36
     * @var RequestStack
37
     */
38
    private $request;
39
40
    public function __construct(EngineInterface $templating, RequestStack $request)
41
    {
42
        parent::__construct($templating);
43
44
        $this->request = $request;
45
    }
46
47
    public function execute(BlockContextInterface $blockContext, Response $response = null)
48
    {
49
        if ($this->hasGdprCookie()) {
50
            return new Response('', Response::HTTP_NO_CONTENT);
51
        }
52
53
        $parameters = [
54
            'context'  => $blockContext,
55
            'settings' => $blockContext->getSettings(),
56
            'block'    => $blockContext->getBlock(),
57
        ];
58
59
        return $this->renderPrivateResponse($blockContext->getTemplate(), $parameters, $response);
60
    }
61
62
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
63
    {
64
        $this->configureEditForm($form, $block);
65
    }
66
67
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
68
    {
69
        $formMapper->add('settings', ImmutableArrayType::class, [
70
            'keys' => [
71
                ['text', TextType::class, [
72
                    'label'    => 'form.label_text',
73
                    'required' => false,
74
                ]],
75
                ['url', UrlType::class, [
76
                    'label'    => 'form.label_url',
77
                    'required' => false,
78
                ]],
79
                ['position', ChoiceType::class, [
80
                    'label'   => 'form.label_position',
81
                    'choices' => [
82
                        'form.choice_top'      => 'top',
83
                        'form.choice_fixedtop' => 'fixedtop',
84
                        'form.choice_bottom'   => 'bottom',
85
                        'form.choice_block'    => 'block',
86
                    ],
87
                ]],
88
            ],
89
            'translation_domain' => 'Core23GDPRBundle',
90
        ]);
91
    }
92
93
    public function configureSettings(OptionsResolver $resolver): void
94
    {
95
        $resolver->setDefaults([
96
            'text'            => null,
97
            'url'             => 'https://gdpr-info.eu/',
98
            'template'        => '@Core23GDPR/Block/block_gdpr.html.twig',
99
            'position'        => 'block',
100
        ]);
101
    }
102
103
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
104
    {
105
    }
106
107
    public function getMetadata(): MetadataInterface
108
    {
109
        return new Metadata('core23_gdpr.block.information', null, null, 'Core23GDPRBundle', [
110
            'class' => 'fa fa-balance-scale',
111
        ]);
112
    }
113
114
    public function getName(): string
115
    {
116
        return $this->getMetadata()->getTitle();
117
    }
118
119
    private function hasGdprCookie(): bool
120
    {
121
        $request = $this->request->getMasterRequest();
122
123
        return null !== $request && $request->cookies->getBoolean(self::COOKIE_NAME);
124
    }
125
}
126