Passed
Pull Request — main (#4760)
by David
06:51
created

ModuleMapProviderTrait::hasApiKey()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 8
rs 10
1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2023 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Module;
21
22
use Fisharebest\Webtrees\Auth;
0 ignored issues
show
Bug introduced by
The type Fisharebest\Webtrees\Auth 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 Fisharebest\Webtrees\Http\Exceptions\HttpServerErrorException;
24
use Fisharebest\Webtrees\I18N;
0 ignored issues
show
Bug introduced by
The type Fisharebest\Webtrees\I18N 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...
25
26
use function e;
27
28
/**
29
 * Trait ModuleMapProviderTrait - default implementation of ModuleMapProviderInterface
30
 */
31
trait ModuleMapProviderTrait
32
{
33
    use ModuleConfigTrait;
34
35
    /**
36
     * Parameters to create a TileLayer in LeafletJs.
37
     *
38
     * @return array<object>
39
     */
40
    public function leafletJsTileLayers(): array
41
    {
42
        return [];
43
    }
44
45
    /**
46
     *  If module requires an api key then return false if not valid
47
     *
48
     * @return bool
49
     * @throws HttpServerErrorException
50
     */
51
    public function hasApiKey(): bool
52
    {
53
        $api_key = $this->getPreference('api_key', 'not-needed');
0 ignored issues
show
Bug introduced by
It seems like getPreference() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

53
        /** @scrutinizer ignore-call */ 
54
        $api_key = $this->getPreference('api_key', 'not-needed');
Loading history...
54
        if ($api_key !== 'not-needed' && $api_key === '' && Auth::isAdmin()) {
55
            $message = I18N::translate('<a href="%s">The %s service requires an API key.', e($this->getConfigLink()), $this->title());
0 ignored issues
show
Bug introduced by
It seems like title() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

55
            $message = I18N::translate('<a href="%s">The %s service requires an API key.', e($this->getConfigLink()), $this->/** @scrutinizer ignore-call */ title());
Loading history...
56
            throw new HttpServerErrorException($message);
57
        }
58
        return $api_key !== '';
59
    }
60
}
61