Passed
Push — 6.5.0.0 ( 85bd4e...fe6596 )
by Christian
24:46 queued 09:10
created

FinishController::default()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 24
rs 9.8333
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Controller;
5
6
use Shopware\Core\Framework\Log\Package;
7
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpFoundation\Response;
10
use Symfony\Component\Routing\Annotation\Route;
11
12
/**
13
 * @internal
14
 */
15
#[Package('core')]
16
class FinishController extends AbstractController
17
{
18
    #[Route('/finish', name: 'finish', defaults: ['step' => 3])]
19
    public function default(Request $request): Response
20
    {
21
        // @codeCoverageIgnoreStart
22
        if ($request->getMethod() === Request::METHOD_POST) {
23
            $self = $_SERVER['SCRIPT_FILENAME'];
24
            \assert(\is_string($self));
25
26
            $redirectUrl = $request->getBasePath() . '/admin';
27
28
            // Below this line call only php native functions as we deleted our own files already
29
            unlink($self);
30
31
            if (\function_exists('opcache_reset')) {
32
                opcache_reset();
33
            }
34
35
            header('Content-Type: text/html; charset=utf-8');
36
            echo '<script>window.location.href = "' . $redirectUrl . '" </script>';
37
            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...
38
        }
39
        // @codeCoverageIgnoreEnd
40
41
        return $this->render('finish.html.twig');
42
    }
43
}
44