Test Failed
Push — develop ( c548cd...99a4a2 )
by Nuno
04:09
created

LocalSettingsRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 11
dl 0
loc 64
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 7 2
A exists() 0 3 1
A find() 0 4 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Scout Extended.
7
 *
8
 * (c) Algolia Team <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Algolia\ScoutExtended\Repositories;
15
16
use Algolia\ScoutExtended\Settings\Settings;
17
use Illuminate\Support\Str;
18
use Algolia\AlgoliaSearch\Index;
0 ignored issues
show
Bug introduced by
The type Algolia\AlgoliaSearch\Index 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...
19
use Illuminate\Filesystem\Filesystem;
20
21
/**
22
 * @internal
23
 */
24
final class LocalSettingsRepository
25
{
26
    /**
27
     * @var \Algolia\ScoutExtended\Repositories\RemoteSettingsRepository
28
     */
29
    private $remoteRepository;
30
31
    /**
32
     * @var \Illuminate\Filesystem\Filesystem
33
     */
34
    private $files;
35
36
    /**
37
     * LocalRepository constructor.
38
     *
39
     * @param \Algolia\ScoutExtended\Repositories\RemoteSettingsRepository $remoteRepository
40
     * @param \Illuminate\Filesystem\Filesystem $files
41
     *
42
     */
43
    public function __construct(RemoteSettingsRepository $remoteRepository, Filesystem $files)
44
    {
45
        $this->remoteRepository = $remoteRepository;
46
        $this->files = $files;
47
    }
48
49
    /**
50
     * Checks if the given index settings exists.
51
     *
52
     * @param  \Algolia\AlgoliaSearch\Index $index
53
     *
54
     * @return bool
55
     */
56
    public function exists(Index $index): bool
57
    {
58
        return $this->files->exists($this->getPath($index));
59
    }
60
61
    /**
62
     * Get the settings path of the given index name.
63
     *
64
     * @param  \Algolia\AlgoliaSearch\Index $index
65
     *
66
     * @return string
67
     */
68
    public function getPath(Index $index): string
69
    {
70
        $name = str_replace('_', '-', $index->getIndexName());
71
72
        $name = is_array($name) ? current($name) : $name;
73
74
        return config_path('scout-'.Str::lower($name).'.php');
75
    }
76
77
    /**
78
     * Find the settings of the given Index.
79
     *
80
     * @param \Algolia\AlgoliaSearch\Index $index
81
     *
82
     * @return \Algolia\ScoutExtended\Settings\Settings
83
     */
84
    public function find(Index $index): Settings
85
    {
86
        return new Settings(($this->exists($index) ? require $this->getPath($index) : []),
87
            $this->remoteRepository->defaults());
88
    }
89
}
90