Test Failed
Push — develop ( 9dccb9...240a5e )
by Nuno
03:56
created

LocalRepository::find()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 1
nop 1
crap 6
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\Settings;
15
16
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...
17
use Algolia\ScoutExtended\Exceptions\SettingsNotFound;
18
use Illuminate\Support\Str;
19
use Illuminate\Filesystem\Filesystem;
20
21
/**
22
 * @internal
23
 */
24
final class LocalRepository
25
{
26
    /**
27
     * @var \Algolia\ScoutExtended\Settings\RemoteRepository
28
     */
29
    private $remoteRepository;
30
31
    /**
32
     * @var \Illuminate\Filesystem\Filesystem
33
     */
34
    private $files;
35
36
    /**
37
     * LocalRepository constructor.
38
     *
39
     * @param \Illuminate\Filesystem\Filesystem $files
40
     *
41
     * @return void
42
     */
43
    public function __construct(RemoteRepository $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
        return config_path('scout-'.Str::lower($name).'.php');
73
    }
74
75
    /**
76
     * Find the settings of the given Index.
77
     *
78
     * @param \Algolia\AlgoliaSearch\Index $index
79
     *
80
     * @return \Algolia\ScoutExtended\Settings\Settings
81
     */
82
    public function find(Index $index): Settings
83
    {
84
        return new Settings(($this->exists($index) ? require $this->getPath($index) : []), $this->remoteRepository->defaults());
85
    }
86
}
87