GreetingController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getGreeting() 0 9 3
A staticallyGreetAction() 0 3 1
A dynamicallyGreetAction() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Acme\PHPDishExamplePlugin\Controller;
6
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\Response;
9
10
final class GreetingController extends Controller
11
{
12
    /**
13
     * @param string|null $name
14
     *
15
     * @return Response
16
     */
17
    public function staticallyGreetAction(?string $name): Response
18
    {
19
        return $this->render('@AcmePHPDishExamplePlugin/static_greeting.html.twig', ['greeting' => $this->getGreeting($name)]);
20
    }
21
22
    /**
23
     * @param string|null $name
24
     *
25
     * @return Response
26
     */
27
    public function dynamicallyGreetAction(?string $name): Response
28
    {
29
        return $this->render('@AcmePHPDishExamplePlugin/dynamic_greeting.html.twig', ['greeting' => $this->getGreeting($name)]);
30
    }
31
32
    /**
33
     * @param string|null $name
34
     *
35
     * @return string
36
     */
37
    private function getGreeting(?string $name): string
38
    {
39
        switch ($name) {
40
            case null:
41
                return 'Hello!';
42
            case 'Lionel Richie':
43
                return 'Hello, is it me you\'re looking for?';
44
            default:
45
                return sprintf('Hello, %s!', $name);
46
        }
47
    }
48
}
49