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.

MatomoTrackerBlockService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 7
dl 0
loc 75
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A configureSettings() 0 13 1
A execute() 0 9 2
A configureCreateForm() 0 4 1
A configureEditForm() 0 27 1
A validate() 0 3 1
A getMetadata() 0 6 1
A getName() 0 4 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\MatomoBundle\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\Component\Form\Extension\Core\Type\CheckboxType;
24
use Symfony\Component\Form\Extension\Core\Type\NumberType;
25
use Symfony\Component\Form\Extension\Core\Type\TextType;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\OptionsResolver\OptionsResolver;
28
29
final class MatomoTrackerBlockService extends AbstractBlockService implements EditableBlockService
30
{
31
    public function execute(BlockContextInterface $blockContext, Response $response = null)
32
    {
33
        return $this->renderResponse($blockContext->getTemplate(), [
34
            'context'    => $blockContext,
35
            'settings'   => $blockContext->getSettings(),
36
            'block'      => $blockContext->getBlock(),
37
            'statusCode' => null === $response ? 200 : $response->getStatusCode(),
38
        ], $response);
39
    }
40
41
    public function configureCreateForm(FormMapper $form, BlockInterface $block): void
42
    {
43
        $this->configureEditForm($form, $block);
44
    }
45
46
    public function configureEditForm(FormMapper $formMapper, BlockInterface $block): void
47
    {
48
        $formMapper->add('settings', ImmutableArrayType::class, [
49
            'keys' => [
50
                ['host', TextType::class, [
51
                    'required' => false,
52
                    'label'    => 'form.label_host',
53
                ]],
54
                ['site', NumberType::class, [
55
                    'label' => 'form.label_site',
56
                ]],
57
                ['domaintitle', CheckboxType::class, [
58
                    'label'    => 'form.label_domaintitle',
59
                    'required' => false,
60
                ]],
61
                ['nocookies', CheckboxType::class, [
62
                    'label'    => 'form.label_nocookies',
63
                    'required' => false,
64
                ]],
65
                ['donottrack', CheckboxType::class, [
66
                    'label'    => 'form.label_donottrack',
67
                    'required' => false,
68
                ]],
69
            ],
70
            'translation_domain' => 'Core23MatomoBundle',
71
        ]);
72
    }
73
74
    public function configureSettings(OptionsResolver $resolver): void
75
    {
76
        $resolver->setDefaults([
77
            'host'        => null,
78
            'site'        => null,
79
            'domaintitle' => false,
80
            'donottrack'  => false,
81
            'nocookies'   => false,
82
            'template'    => '@Core23Matomo/Block/block_matomo_tracker.html.twig',
83
        ]);
84
85
        $resolver->setRequired(['site', 'host']);
86
    }
87
88
    public function validate(ErrorElement $errorElement, BlockInterface $block): void
89
    {
90
    }
91
92
    public function getMetadata(): MetadataInterface
93
    {
94
        return new Metadata('core23_matomo.block.tracker', null, null, 'Core23MatomoBundle', [
95
            'class' => 'fa fa-code',
96
        ]);
97
    }
98
99
    public function getName(): string
100
    {
101
        return $this->getMetadata()->getTitle();
102
    }
103
}
104