DataProviderFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 7
Bugs 1 Features 2
Metric Value
wmc 7
c 7
b 1
f 2
lcom 1
cbo 7
dl 0
loc 79
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
B getDataProviderByConfig() 0 24 6
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\DataProviders\Activity\ActivityUsageLastMonthProvider;
27
use OCA\ocUsageCharts\DataProviders\Activity\ActivityUsagePerMonthProvider;
28
use OCA\ocUsageCharts\DataProviders\ChartUsageHelper;
29
use OCA\ocUsageCharts\DataProviders\Storage\StorageUsageCurrentProvider;
30
use OCA\ocUsageCharts\DataProviders\Storage\StorageUsageLastMonthProvider;
31
use OCA\ocUsageCharts\DataProviders\Storage\StorageUsagePerMonthProvider;
32
use OCA\ocUsageCharts\Entity\Activity\ActivityUsageRepository;
33
use OCA\ocUsageCharts\Entity\ChartConfig;
34
use OCA\ocUsageCharts\Entity\Storage\StorageUsageRepository;
35
use OCA\ocUsageCharts\Exception\ChartDataProviderException;
36
use OCA\ocUsageCharts\Owncloud\Storage;
37
use OCA\ocUsageCharts\Owncloud\User;
38
use OCA\ocUsageCharts\Owncloud\Users;
39
40
/**
41
 * @author Arno van Rossum <[email protected]>
42
 */
43
class DataProviderFactory
44
{
45
    /**
46
     * @var StorageUsageRepository
47
     */
48
    private $repository;
49
50
    /**
51
     * @var ActivityUsageRepository
52
     */
53
    private $activityUsageRepository;
54
55
    /**
56
     * @var User
57
     */
58
    private $user;
59
60
    /**
61
     * @var Storage
62
     */
63
    private $storage;
64
65
    /**
66
     * @var ChartUsageHelper
67
     */
68
    private $chartUsageHelper;
69
70
    /**
71
     * @var Users
72
     */
73
    private $users;
74
    /**
75
     * @param StorageUsageRepository $repository
76
     * @param ActivityUsageRepository $activityUsageRepository
77
     * @param User $user
78
     * @param Storage $storage
79
     * @param ChartUsageHelper $chartUsageHelper
80
     * @param Users $users
81
     */
82
    public function __construct(StorageUsageRepository $repository, ActivityUsageRepository $activityUsageRepository, User $user, Storage $storage, ChartUsageHelper $chartUsageHelper, Users $users)
83
    {
84
        $this->repository = $repository;
85
        $this->user = $user;
86
        $this->storage = $storage;
87
        $this->activityUsageRepository = $activityUsageRepository;
88
        $this->chartUsageHelper = $chartUsageHelper;
89
        $this->users = $users;
90
    }
91
92
    /**
93
     * @param ChartConfig $config
94
     * @return StorageUsageCurrentProvider|StorageUsageLastMonthProvider|StorageUsagePerMonthProvider
95
     * @throws Exception\ChartDataProviderException
96
     */
97
    public function getDataProviderByConfig(ChartConfig $config)
98
    {
99
        switch($config->getChartType())
100
        {
101
            case 'StorageUsageCurrent':
102
                $provider = new StorageUsageCurrentProvider($config, $this->repository, $this->user, $this->storage);
103
                break;
104
            case 'StorageUsageLastMonth':
105
                $provider = new StorageUsageLastMonthProvider($config, $this->repository, $this->user, $this->storage);
106
                break;
107
            case 'StorageUsagePerMonth':
108
                $provider = new StorageUsagePerMonthProvider($config, $this->repository, $this->user, $this->storage, $this->chartUsageHelper);
109
                break;
110
            case 'ActivityUsageLastMonth':
111
                $provider = new ActivityUsageLastMonthProvider($config, $this->activityUsageRepository, $this->user, $this->users);
112
                break;
113
            case 'ActivityUsagePerMonth':
114
                $provider = new ActivityUsagePerMonthProvider($config, $this->activityUsageRepository, $this->user, $this->chartUsageHelper);
115
                break;
116
            default:
117
                throw new ChartDataProviderException("DataProvider for " . $config->getChartType() . ' does not exist.');
118
        }
119
        return $provider;
120
    }
121
}
122