Completed
Push — master ( 8e286a...78e0f9 )
by Rafał
09:27
created

ExportAnalytics::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 1
nc 1
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2020 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2020 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\AnalyticsExport;
18
19
use SWP\Bundle\CoreBundle\MessageHandler\Message\MessageInterface;
20
21
class ExportAnalytics implements MessageInterface
22
{
23
    /** @var string */
24
    private $start;
25
26
    /** @var string */
27
    private $end;
28
29
    /** @var string */
30
    private $tenantCode;
31
32
    /** @var string */
33
    private $fileName;
34
35
    /** @var string */
36
    private $userEmail;
37
38
    /** @var array */
39
    private $routeIds;
40
41
    /** @var array */
42
    private $authors;
43
44
    /** @var string */
45
    private $term;
46
47
    public function __construct(
48
        string $start,
49
        string $end,
50
        string $tenantCode,
51
        string $fileName,
52
        string $userEmail,
53
        array $routeIds,
54
        array $authors,
55
        string $term
56
    ) {
57
        $this->start = $start;
58
        $this->end = $end;
59
        $this->tenantCode = $tenantCode;
60
        $this->fileName = $fileName;
61
        $this->userEmail = $userEmail;
62
        $this->routeIds = $routeIds;
63
        $this->authors = $authors;
64
        $this->term = $term;
65
    }
66
67
    public function getStart(): string
68
    {
69
        return $this->start;
70
    }
71
72
    public function getEnd(): string
73
    {
74
        return $this->end;
75
    }
76
77
    public function getTenantCode(): string
78
    {
79
        return $this->tenantCode;
80
    }
81
82
    public function getFileName(): string
83
    {
84
        return $this->fileName;
85
    }
86
87
    public function getUserEmail(): string
88
    {
89
        return $this->userEmail;
90
    }
91
92
    public function getRouteIds(): array
93
    {
94
        return array_filter($this->routeIds);
95
    }
96
97
    public function getAuthors(): array
98
    {
99
        return array_filter($this->authors);
100
    }
101
102
    public function getTerm(): string
103
    {
104
        return $this->term;
105
    }
106
107
    public function getFilters(): array
108
    {
109
        return [
110
            'term' => $this->term,
111
            'start' => $this->start,
112
            'end' => $this->end,
113
            'routes' => array_map('intval', $this->routeIds),
114
            'authors' => $this->authors,
115
        ];
116
    }
117
118
    public function toArray(): array
119
    {
120
        return [
121
            'start' => $this->start,
122
            'end' => $this->end,
123
            'tenantCode' => $this->tenantCode,
124
            'fileName' => $this->fileName,
125
            'userEmail' => $this->userEmail,
126
            'routeIds' => $this->routeIds,
127
            'authors' => $this->authors,
128
            'term' => $this->term,
129
        ];
130
    }
131
}
132