Completed
Push — feature/EVO-10415-Analytics-wi... ( e2b3ad )
by
unknown
12:30
created

AnalyticModel::setCollection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
/**
3
 * Schema Class for output data.
4
 */
5
namespace Graviton\AnalyticsBundle\Model;
6
7
/**
8
 * Schema
9
 *
10
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
11
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
12
 * @link     http://swisscom.ch
13
 */
14
class AnalyticModel
15
{
16
    protected $collection;
17
    protected $route;
18
    protected $aggregate;
19
    protected $schema;
20
    protected $type;
21
22
    /**
23
     * String collection
24
     * @return mixed
25
     */
26
    public function getCollection()
27
    {
28
        return $this->collection;
29
    }
30
31
    /**
32
     * Set value of collection
33
     * @param mixed $collection string name
34
     * @return void
35
     */
36
    public function setCollection($collection)
37
    {
38
        $this->collection = $collection;
39
    }
40
41
    /**
42
     * Route path
43
     * @return mixed
44
     */
45
    public function getRoute()
46
    {
47
        return $this->route;
48
    }
49
50
    /**
51
     * Set path
52
     * @param mixed $route string route
53
     * @return void
54
     */
55
    public function setRoute($route)
56
    {
57
        $this->route = $route;
58
    }
59
60
    /**
61
     * Mongodb Aggregates
62
     * @return mixed
63
     */
64
    public function getAggregate()
65
    {
66
        return $this->aggregate;
67
    }
68
69
    /**
70
     * Set mongodb query
71
     * @param mixed $aggregate object type for query data
72
     * @return void
73
     */
74
    public function setAggregate($aggregate)
75
    {
76
        $this->aggregate = $aggregate;
77
    }
78
79
    /**
80
     * Schema for response
81
     * @return mixed
82
     */
83
    public function getSchema()
84
    {
85
        return $this->schema;
86
    }
87
88
    /**
89
     * Schema data
90
     * @param mixed $schema object schema
91
     * @return void
92
     */
93
    public function setSchema($schema)
94
    {
95
        $this->schema = $schema;
96
    }
97
98
    /**
99
     * Type of response data
100
     * @return mixed
101
     */
102
    public function getType()
103
    {
104
        return $this->type;
105
    }
106
107
    /**
108
     * Type for representation
109
     * @param mixed $type string view
110
     * @return void
111
     */
112
    public function setType($type)
113
    {
114
        $this->type = $type;
115
    }
116
117
118
    /**
119
     * Build query pipeline for aggregate mongo
120
     * @return array
121
     */
122
    public function getPipeline()
123
    {
124
        $pipeline = [];
125
        $aggregate = $this->getAggregate();
126
        if (empty($aggregate)) {
127
            return $pipeline;
128
        }
129
130 View Code Duplication
        if (property_exists($aggregate, 'match') && !empty((array) $aggregate->match)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
131
            $pipeline[] = [
132
                '$match' => $this->aggregate->match
133
            ];
134
        }
135
136 View Code Duplication
        if (property_exists($aggregate, 'group') && !empty((array) $aggregate->group)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
137
            $pipeline[] = [
138
                '$group' => $this->aggregate->group
139
            ];
140
        }
141
142
        return $pipeline;
143
    }
144
}
145