Passed
Push — master ( 222752...4454ce )
by Marcel
02:38
created

DataSourceController::read()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 10
rs 10
1
<?php
2
/**
3
 * Data Analytics
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @copyright 2019 Marcel Scherello
10
 */
11
12
namespace OCA\Analytics\Controller;
13
14
use OCA\Analytics\Datasource\ExternalFileService;
15
use OCA\Analytics\Datasource\FileService;
16
use OCA\Analytics\Datasource\GithubService;
17
use OCP\AppFramework\Controller;
18
use OCP\Files\NotFoundException;
19
use OCP\ILogger;
20
use OCP\IRequest;
21
22
class DataSourceController extends Controller
23
{
24
    private $logger;
25
    private $GithubService;
26
    private $FileService;
27
    private $ExternalFileService;
28
    private $userId;
29
30
    const DATASET_TYPE_GROUP = 0;
31
    const DATASET_TYPE_INTERNAL_FILE = 1;
32
    const DATASET_TYPE_INTERNAL_DB = 2;
33
    const DATASET_TYPE_GIT = 3;
34
    const DATASET_TYPE_EXTERNAL_FILE = 4;
35
36
    public function __construct(
37
        string $AppName,
38
        IRequest $request,
39
        $userId,
40
        ILogger $logger,
41
        GithubService $GithubService,
42
        FileService $FileService,
43
        ExternalFileService $ExternalFileService
44
    )
45
    {
46
        parent::__construct($AppName, $request);
47
        $this->userId = $userId;
48
        $this->logger = $logger;
49
        $this->ExternalFileService = $ExternalFileService;
50
        $this->GithubService = $GithubService;
51
        $this->FileService = $FileService;
52
    }
53
54
    /**
55
     * Get the data from a datasource;
56
     *
57
     * @NoAdminRequired
58
     * @param $datasetMetadata
59
     * @param null $options
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $options is correct as it would always require null to be passed?
Loading history...
60
     * @return array
61
     * @throws NotFoundException
62
     */
63
    public function read($datasetMetadata, $options = null)
64
    {
65
        $datasetMetadata['type'] = (int)$datasetMetadata['type'];
66
        //$this->logger->error('DataSourceController 65: '. $datasetMetadata['type']);
67
        if ($datasetMetadata['type'] === self::DATASET_TYPE_INTERNAL_FILE) $result = $this->FileService->read($datasetMetadata, $options);
68
        elseif ($datasetMetadata['type'] === self::DATASET_TYPE_GIT) $result = $this->GithubService->read($datasetMetadata);
69
        elseif ($datasetMetadata['type'] === self::DATASET_TYPE_EXTERNAL_FILE) $result = $this->ExternalFileService->read($datasetMetadata);
70
        else $result = new NotFoundException();
71
72
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result also could return the type OCP\Files\NotFoundException which is incompatible with the documented return type array.
Loading history...
73
    }
74
}