Passed
Branch master (7b1276)
by Marcel
06:24
created

FileService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 5
dl 0
loc 13
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\Datasource;
13
14
use OCA\Analytics\Controller\DbController;
15
use OCA\Analytics\Service\DataService;
16
use OCP\Files\IRootFolder;
17
use OCP\Files\NotFoundException;
18
use OCP\ILogger;
19
20
class FileService
21
{
22
    private $logger;
23
    private $DBController;
24
    private $rootFolder;
25
    private $DataService;
26
    private $userId;
27
28
    public function __construct(
29
        $userId,
30
        ILogger $logger,
31
        IRootFolder $rootFolder,
32
        DbController $DBController,
33
        DataService $DataService
34
    )
35
    {
36
        $this->userId = $userId;
37
        $this->DataService = $DataService;
38
        $this->logger = $logger;
39
        $this->DBController = $DBController;
40
        $this->rootFolder = $rootFolder;
41
    }
42
43
    /**
44
     * Get the items for the selected category
45
     *
46
     * @NoAdminRequired
47
     * @param $datasetMetadata
48
     * @return array
49
     * @throws NotFoundException
50
     */
51
    public function read($datasetMetadata)
52
    {
53
        //$this->logger->error('dataset path: ' . $datasetMetadata['link']);
54
        $file = $this->rootFolder->getUserFolder($datasetMetadata['user_id'])->get($datasetMetadata['link']);
55
        $data = $file->getContent();
0 ignored issues
show
Bug introduced by
The method getContent() does not exist on OCP\Files\Node. It seems like you code against a sub-type of OCP\Files\Node such as OCP\Files\File. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
        /** @scrutinizer ignore-call */ 
56
        $data = $file->getContent();
Loading history...
56
        return ['header' => '', 'data' => $data];
57
    }
58
59
    /**
60
     * Get the items for the selected category
61
     *
62
     * @NoAdminRequired
63
     * @param int $datasetId
64
     * @param $path
65
     * @return array
66
     * @throws NotFoundException
67
     */
68
    public function import(int $datasetId, $path)
69
    {
70
        $file = $this->rootFolder->getUserFolder($this->userId)->get($path);
71
        $import = $file->getContent();
72
        return $this->DataService->import($datasetId, $import);
73
    }
74
75
}