|
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'); |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.