EventAction   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 68
Duplicated Lines 32.35 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 22
loc 68
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A __invoke() 22 22 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Web\Action;
6
7
use Article\Entity\ArticleType;
8
use Article\Service\EventService;
9
use Category\Service\CategoryService;
10
use Meetup\MeetupApiService;
11
use Psr\Http\Message\ResponseInterface as Response;
12
use Psr\Http\Message\ServerRequestInterface as Request;
13
use Zend\Diactoros\Response\HtmlResponse;
14
use Zend\Expressive\Template\TemplateRendererInterface as Template;
15
16
/**
17
 * Class EventAction.
18
 */
19
class EventAction
20
{
21
    /** @var Template */
22
    private $template;
23
24
    /** @var EventService */
25
    private $eventService;
26
27
    /** @var CategoryService */
28
    private $categoryService;
29
30
    /** @var MeetupApiService */
31
    private $meetupService;
32
33
    /**
34
     * EventAction constructor.
35
     *
36
     * @param Template         $template
37
     * @param EventService     $eventService
38
     * @param CategoryService  $categoryService
39
     * @param MeetupApiService $meetupService
40
     */
41
    public function __construct(
42
        Template $template,
43
        EventService $eventService,
44
        CategoryService $categoryService,
45
        MeetupApiService $meetupService
46
    ) {
47
        $this->template = $template;
48
        $this->eventService = $eventService;
49
        $this->categoryService = $categoryService;
50
        $this->meetupService = $meetupService;
51
    }
52
53
    /**
54
     * Executed when action is invoked.
55
     *
56
     * @param Request       $request
57
     * @param Response      $response
58
     * @param callable|null $next
59
     *
60
     * @throws \Exception
61
     *
62
     * @return HtmlResponse
63
     */
64 View Code Duplication
    public function __invoke(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
        Request $request,
66
        Response $response,
67
        callable $next = null
68
    ) {
69
        $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...
70
        $eventSlug = $request->getAttribute('segment_2');
71
        $event = $this->eventService->fetchEventBySlug($eventSlug);
72
73
        if (!$event || $event->type != ArticleType::EVENT) {
74
            return $next($request, $response);
75
        }
76
77
        // Fetch going ppl
78
        $attendees = $this->meetupService->getAttendees($event->event_url);
79
80
        return new HtmlResponse($this->template->render('web::event', [
81
            'layout'    => 'layout/web',
82
            'event'     => $event,
83
            'attendees' => $attendees,
84
        ]));
85
    }
86
}
87