Completed
Push — master ( 7881aa...9b899c )
by Mike
32:14 queued 08:12
created

GeocoderService::configPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 1
crap 6
1
<?php namespace Geocoder\Laravel\Providers;
2
3
/**
4
 * This file is part of the Geocoder Laravel package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author Mike Bronner <[email protected]>
9
 * @license    MIT License
10
 */
11
12
use Geocoder\Laravel\Facades\Geocoder;
13
use Geocoder\Laravel\ProviderAndDumperAggregator;
14
use Illuminate\Support\Collection;
15
use Illuminate\Support\ServiceProvider;
16
use ReflectionClass;
17
18
class GeocoderService extends ServiceProvider
19
{
20
    protected $defer = false;
21
22 26
    public function boot()
23
    {
24 26
        $configPath = __DIR__ . "/../../config/geocoder.php";
25 26
        $this->publishes(
26 26
            [$configPath => $this->configPath("geocoder.php")],
27 26
            "config"
28 24
        );
29 24
        $this->mergeConfigFrom($configPath, "geocoder");
30 26
        $this->app->singleton("geocoder", function () {
31 26
            return (new ProviderAndDumperAggregator)
32
                ->registerProvidersFromConfig(collect(config("geocoder.providers")));
33 26
        });
34
    }
35 26
36 26
    public function register()
37
    {
38
        $this->app->alias("Geocoder", Geocoder::class);
39
    }
40
41
    public function provides() : array
42
    {
43
        return ["geocoder"];
44
    }
45
46
    protected function configPath(string $path = "") : string
47
    {
48
        if (function_exists("config_path")) {
49
            return config_path($path);
50
        }
51
52
        $pathParts = [
53
            app()->basePath(),
54
            "config",
55
            trim($path, "/"),
56
        ];
57
58
        return implode("/", $pathParts);
59
    }
60
}
61