Provider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getOrder() 0 3 1
A search() 0 18 2
A __construct() 0 7 1
A getId() 0 3 1
1
<?php
2
/**
3
 * Audio Player
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 2020 Marcel Scherello
10
 */
11
12
declare(strict_types=1);
13
14
namespace OCA\audioplayer\Search;
15
16
use OCA\audioplayer\Controller\DbController;
17
use OCP\IL10N;
18
use OCP\IURLGenerator;
19
use OCP\IUser;
20
use OCP\Search\IProvider;
0 ignored issues
show
Bug introduced by Rello
The type OCP\Search\IProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use OCP\Search\ISearchQuery;
0 ignored issues
show
Bug introduced by Rello
The type OCP\Search\ISearchQuery was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use OCP\Search\SearchResult;
0 ignored issues
show
Bug introduced by Rello
The type OCP\Search\SearchResult was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use OCP\Search\SearchResultEntry;
0 ignored issues
show
Bug introduced by Rello
The type OCP\Search\SearchResultEntry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
class Provider implements IProvider
26
{
27
28
    /** @var IL10N */
29
    private $l10n;
30
31
    /** @var IURLGenerator */
32
    private $urlGenerator;
33
34
    private $DBController;
35
36
    public function __construct(IL10N $l10n,
37
                                IURLGenerator $urlGenerator,
38
                                DBController $DBController)
39
    {
40
        $this->l10n = $l10n;
41
        $this->urlGenerator = $urlGenerator;
42
        $this->DBController = $DBController;
43
    }
44
45
    public function getId(): string
46
    {
47
        return 'audioplayer';
48
    }
49
50
    public function search(IUser $user, ISearchQuery $query): SearchResult
51
    {
52
        $datasets = $this->DBController->search($query->getTerm());
53
        $result = [];
54
55
        foreach ($datasets as $dataset) {
56
            $result[] = new SearchResultEntry(
57
                '',
58
                $this->l10n->t('Audio Player') . ' - ' . $dataset['name'],
59
                '',
60
                $this->urlGenerator->linkToRoute('audioplayer.page.index') . '#' . $dataset['id'],
61
                $this->urlGenerator->imagePath('audioplayer', 'app-dark.svg')
62
            );
63
        }
64
65
        return SearchResult::complete(
66
            $this->l10n->t('Audioplayer'),
67
            $result
68
        );
69
    }
70
71
    public function getName(): string
72
    {
73
        return $this->l10n->t('Audioplayer');
74
    }
75
76
    public function getOrder(string $route, array $routeParameters): int
77
    {
78
        return 10;
79
    }
80
}