VideoAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A __invoke() 0 18 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Web\Action;
6
7
use Article\Entity\ArticleType;
8
use Article\Service\VideoService;
9
use Category\Service\CategoryService;
10
use Psr\Http\Message\ResponseInterface as Response;
11
use Psr\Http\Message\ServerRequestInterface as Request;
12
use Zend\Diactoros\Response\HtmlResponse;
13
use Zend\Expressive\Template\TemplateRendererInterface as Template;
14
15
/**
16
 * Class VideoAction.
17
 */
18
class VideoAction
19
{
20
    /** @var Template */
21
    private $template;
22
23
    /** @var VideoService */
24
    private $videoService;
25
26
    /** @var CategoryService */
27
    private $categoryService;
28
29
    /**
30
     * VideoAction constructor.
31
     *
32
     * @param Template        $template
33
     * @param VideoService    $videoService
34
     * @param CategoryService $categoryService
35
     */
36
    public function __construct(
37
        Template $template,
38
        VideoService $videoService,
39
        CategoryService $categoryService
40
    ) {
41
        $this->template = $template;
42
        $this->videoService = $videoService;
43
        $this->categoryService = $categoryService;
44
    }
45
46
    /**
47
     * Executed when action is invoked.
48
     *
49
     * @param Request       $request
50
     * @param Response      $response
51
     * @param callable|null $next
52
     *
53
     * @throws \Exception
54
     *
55
     * @return HtmlResponse
56
     */
57
    public function __invoke(
58
        Request $request,
59
        Response $response,
60
        callable $next = null
61
    ) {
62
        $categorySlug = $request->getAttribute('segment_1');
0 ignored issues
show
Unused Code introduced by
$categorySlug is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
        $videoSlug = $request->getAttribute('segment_2');
64
        $video = $this->videoService->fetchVideoBySlug($videoSlug);
65
66
        if (!$video || $video->type != ArticleType::VIDEO) {
67
            return $next($request, $response);
68
        }
69
70
        return new HtmlResponse($this->template->render('web::video', [
71
            'layout' => 'layout/web',
72
            'video'  => $video,
73
        ]));
74
    }
75
}
76