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.
Passed
Push — master ( c7c802...71c991 )
by Malte
03:14
created

TestKernel::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Webfactory\ShortcodeBundle\Tests\Functional;
4
5
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
6
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
7
use Symfony\Bundle\TwigBundle\TwigBundle;
8
use Symfony\Component\Config\Loader\LoaderInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Reference;
11
use Symfony\Component\Filesystem\Filesystem;
12
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
13
use Symfony\Component\HttpKernel\Kernel;
14
use Symfony\Component\Routing\RouteCollectionBuilder;
15
use Webfactory\ShortcodeBundle\DependencyInjection\WebfactoryShortcodeExtension;
16
use Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler;
17
use Webfactory\ShortcodeBundle\WebfactoryShortcodeBundle;
18
19
/**
20
 * A minimal kernel that is used for testing.
21
 */
22
final class TestKernel extends Kernel
23
{
24
    use MicroKernelTrait;
25
26
    /**
27
     * ID of this kernel instance. Used to separate cache directories, containers etc.
28
     *
29
     * Null if the ID was not generated yet.
30
     *
31
     * @var string|null
32
     * @see getInstanceId()
33
     */
34
    private $instanceId;
35
36
    /**
37
     * @var array, e.g. [
38
     *     [
39
     *         'name' => 'myShortcode,
40
     *         'controller' => 'app.controller.myController:myShortcodePartialAction',
41
     *         'renderer' => 'esi'|'inline'
42
     *     ],
43
     * ]
44
     */
45
    private $shortcodeDefinitions = [];
46
47
    /**
48
     * @param string $environment The environment
49
     * @param bool   $debug       Whether to enable debugging or not
50
     * @param array  $shortcodeDefinitions
51
     */
52 3
    public function __construct($environment, $debug, array $shortcodeDefinitions)
53
    {
54 3
        parent::__construct($environment, $debug);
55 3
        $this->shortcodeDefinitions = $shortcodeDefinitions;
56 3
    }
57
58
59
    /**
60
     * Returns an array of bundles to register.
61
     *
62
     * @return BundleInterface[] An array of bundle instances
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<FrameworkBundle|Tw...factoryShortcodeBundle>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
63
     */
64 3
    public function registerBundles()
65
    {
66
        return [
67 3
            new FrameworkBundle(),
68 3
            new TwigBundle(),
69 3
            new WebfactoryShortcodeBundle(),
70 3
        ];
71
    }
72
73
    /**
74
     * Configures the container.
75
     *
76
     * You can register extensions:
77
     *
78
     * $c->loadFromExtension('framework', array(
79
     *     'secret' => '%secret%'
80
     * ));
81
     *
82
     * Or services:
83
     *
84
     * $c->register('halloween', 'FooBundle\HalloweenProvider');
85
     *
86
     * Or parameters:
87
     *
88
     * $c->setParameter('halloween', 'lot of fun');
89
     *
90
     * @param ContainerBuilder $container
91
     * @param LoaderInterface $loader
92
     */
93 3
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
94
    {
95
        // use the actual configuration of the bundle to get it's basic configuration
96 3
        (new WebfactoryShortcodeExtension())->load([], $container);
97
98
        // load some additional infrastructure
99 3
        $container->loadFromExtension(
100 3
            'framework',
101
            [
102 3
                'secret' => 'my-secret',
103 3
                'test' => true,
104
                'templating' => [
105 3
                    'engines' => ['twig']
106 3
                ]
107 3
            ]
108 3
        );
109
110
        // and register test-specific shortcodes
111 3
        foreach ($this->shortcodeDefinitions as $shortCodeDefinition) {
112
            $container
113 3
                ->register('webfactory.shortcode.myfilter.' . uniqid('', false), EmbeddedShortcodeHandler::class)
114 3
                ->setArguments([
115 3
                    new Reference('fragment.handler'),
116 3
                    $shortCodeDefinition['controller'],
117 3
                    $shortCodeDefinition['renderer'],
118 3
                ])->addTag('webfactory.shortcode', ['shortcode' => $shortCodeDefinition['name']]);
119 3
        }
120 3
    }
121
122
    /**
123
     * Gets the cache directory.
124
     *
125
     * @return string The cache directory
126
     */
127 3
    public function getCacheDir()
128
    {
129 3
        return sys_get_temp_dir() . '/test_kernel/' . $this->getInstanceId();
130
    }
131
132
    /**
133
     * Gets the log directory.
134
     *
135
     * @return string The log directory
136
     */
137 3
    public function getLogDir()
138
    {
139 3
        return $this->getCacheDir() . '/logs';
140
    }
141
142
    /**
143
     * Deletes the cache directory when the kernel is not used anymore.
144
     */
145
    public function __destruct()
146
    {
147
        (new Filesystem())->remove($this->getCacheDir());
148
    }
149
150
    /**
151
     * Add or import routes into your application.
152
     *
153
     *     $routes->import('config/routing.yml');
154
     *     $routes->add('/admin', 'AppBundle:Admin:dashboard', 'admin_dashboard');
155
     *
156
     * @param RouteCollectionBuilder $routes
157
     */
158
    protected function configureRoutes(RouteCollectionBuilder $routes)
159
    {
160
    }
161
162
    /**
163
     * Gets the container class.
164
     *
165
     * @return string The container class
166
     */
167 3
    protected function getContainerClass()
168
    {
169
        // Use different container class names to ensure that each kernel has its own container instance.
170
        // If the same class name is used by multiple kernels, then a cannot redeclare class error will occur.
171 3
        return parent::getContainerClass() . $this->getInstanceId();
172
    }
173
174
    /**
175
     * Returns a unique ID for this kernel instance.
176
     *
177
     * @return string
178
     */
179 3
    private function getInstanceId()
180
    {
181 3
        if ($this->instanceId === null) {
182 3
            $this->instanceId = 'Kernel' . uniqid('', true);
183
            // Remove special characters from the ID to ensure that it can be used as part of a class name.
184 3
            $this->instanceId = preg_replace('/[^a-zA-Z0-9]/', '', $this->instanceId);
185 3
        }
186 3
        return $this->instanceId;
187
    }
188
}
189