Passed
Push — trunk ( aca09f...bd7f95 )
by Christian
14:04 queued 13s
created

FinishController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Shopware\WebInstaller\Controller;
5
6
use Shopware\Core\Framework\Log\Package;
7
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8
use Symfony\Component\DependencyInjection\Attribute\Autowire;
9
use Symfony\Component\Filesystem\Filesystem;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\HttpFoundation\Response;
12
use Symfony\Component\Routing\Annotation\Route;
13
14
/**
15
 * @internal
16
 */
17
#[Package('core')]
18
class FinishController extends AbstractController
19
{
20
    #[Route('/finish', name: 'finish', defaults: ['step' => 3])]
21
    public function default(Request $request, #[Autowire('%kernel.cache_dir%')] string $cacheDir): Response
22
    {
23
        // @codeCoverageIgnoreStart
24
        if ($request->getMethod() === Request::METHOD_POST) {
25
            if ($request->hasSession()) {
26
                $request->getSession()->invalidate();
27
            }
28
29
            $self = $_SERVER['SCRIPT_FILENAME'];
30
            \assert(\is_string($self));
31
32
            $redirectUrl = $request->getBasePath() . '/admin';
33
34
            // Cleanup our generated cache dir in system temporary directory
35
            $fs = new Filesystem();
36
            $fs->remove($cacheDir);
37
38
            // Below this line call only php native functions as we deleted our own files already
39
            unlink($self);
40
41
            header('Content-Type: text/html; charset=utf-8');
42
            echo '<script>window.location.href = "' . $redirectUrl . '" </script>';
43
            exit;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
44
        }
45
        // @codeCoverageIgnoreEnd
46
47
        return $this->render('finish.html.twig');
48
    }
49
}
50