ChartTypeAdapterFactory   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 10
Bugs 4 Features 1
Metric Value
wmc 17
c 10
b 4
f 1
lcom 1
cbo 7
dl 0
loc 127
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B getChartTypeAdapterByConfig() 0 24 6
A getStorageUsageCurrentAdapter() 0 10 2
A getStorageUsageLastMonthAdapter() 0 10 2
A getStorageUsagePerMonthAdapter() 0 10 2
A getActivityUsageLastMonthAdapter() 0 10 2
A getActivityUsagePerMonthAdapter() 0 10 2
1
<?php
2
/**
3
 * Copyright (c) 2014 - Arno van Rossum <[email protected]>
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
24
namespace OCA\ocUsageCharts;
25
26
use OCA\ocUsageCharts\Adapters as Adapters;
27
use OCA\ocUsageCharts\Adapters\ChartTypeAdapterInterface;
28
use OCA\ocUsageCharts\Entity\ChartConfig;
29
use OCA\ocUsageCharts\Exception\ChartTypeAdapterException;
30
use OCA\ocUsageCharts\Owncloud\User;
31
32
/**
33
 * @author Arno van Rossum <[email protected]>
34
 */
35
class ChartTypeAdapterFactory
36
{
37
    /**
38
     * @var User
39
     */
40
    private $user;
41
42
    /**
43
     * @param User $user
44
     */
45
    public function __construct(User $user)
46
    {
47
        $this->user = $user;
48
    }
49
50
    /**
51
     * Return the proper adapter based on the chartconfig given
52
     *
53
     * @param ChartConfig $config
54
     * @return ChartTypeAdapterInterface
55
     * @throws ChartTypeAdapterException
56
     */
57
    public function getChartTypeAdapterByConfig(ChartConfig $config)
58
    {
59
        switch($config->getChartType())
60
        {
61
            case 'StorageUsageCurrent':
62
                $adapter = $this->getStorageUsageCurrentAdapter($config->getChartProvider(), $config);
63
                break;
64
            case 'StorageUsageLastMonth':
65
                $adapter = $this->getStorageUsageLastMonthAdapter($config->getChartProvider(), $config);
66
                break;
67
            case 'StorageUsagePerMonth':
68
                $adapter = $this->getStorageUsagePerMonthAdapter($config->getChartProvider(), $config);
69
                break;
70
            case 'ActivityUsageLastMonth':
71
                $adapter = $this->getActivityUsageLastMonthAdapter($config->getChartProvider(), $config);
72
                break;
73
            case 'ActivityUsagePerMonth':
74
                $adapter = $this->getActivityUsagePerMonthAdapter($config->getChartProvider(), $config);
75
                break;
76
            default:
77
                throw new ChartTypeAdapterException("ChartType Adapter for " . $config->getChartType() . ' does not exist.');
78
        }
79
        return $adapter;
80
    }
81
82
    /**
83
     * @param string $provider
84
     * @param ChartConfig $config
85
     * @return Adapters\c3js\Storage\StorageUsageCurrentAdapter
86
     */
87
    private function getStorageUsageCurrentAdapter($provider, ChartConfig $config)
88
    {
89
        switch($provider)
90
        {
91
            case 'c3js':
92
            default:
93
                $adapter = new Adapters\c3js\Storage\StorageUsageCurrentAdapter($config, $this->user);
94
        }
95
        return $adapter;
96
    }
97
98
    /**
99
     * @param string $provider
100
     * @param ChartConfig $config
101
     * @return Adapters\c3js\Storage\StorageUsageLastMonthAdapter
102
     */
103
    private function getStorageUsageLastMonthAdapter($provider, ChartConfig $config)
104
    {
105
        switch($provider)
106
        {
107
            case 'c3js':
108
            default:
109
                $adapter = new Adapters\c3js\Storage\StorageUsageLastMonthAdapter($config, $this->user);
110
        }
111
        return $adapter;
112
    }
113
114
    /**
115
     * @param string $provider
116
     * @param ChartConfig $config
117
     * @return Adapters\c3js\Storage\StorageUsagePerMonthAdapter
118
     */
119
    private function getStorageUsagePerMonthAdapter($provider, ChartConfig $config)
120
    {
121
        switch($provider)
122
        {
123
            case 'c3js':
124
            default:
125
                $adapter = new Adapters\c3js\Storage\StorageUsagePerMonthAdapter($config, $this->user);
126
        }
127
        return $adapter;
128
    }
129
130
    /**
131
     * @param string $provider
132
     * @param ChartConfig $config
133
     * @return Adapters\c3js\Activity\ActivityUsageLastMonthAdapter
134
     */
135
    private function getActivityUsageLastMonthAdapter($provider, ChartConfig $config)
136
    {
137
        switch($provider)
138
        {
139
            case 'c3js':
140
            default:
141
                $adapter = new Adapters\c3js\Activity\ActivityUsageLastMonthAdapter($config, $this->user);
142
        }
143
        return $adapter;
144
    }
145
146
    /**
147
     * @param string $provider
148
     * @param ChartConfig $config
149
     * @return Adapters\c3js\Activity\ActivityUsagePerMonthAdapter
150
     */
151
    private function getActivityUsagePerMonthAdapter($provider, ChartConfig $config)
152
    {
153
        switch($provider)
154
        {
155
            case 'c3js':
156
            default:
157
                $adapter = new Adapters\c3js\Activity\ActivityUsagePerMonthAdapter($config, $this->user);
158
        }
159
        return $adapter;
160
    }
161
}
162