ServiceProvider::boot()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 16
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 32
rs 9.7333
1
<?php
2
3
namespace Phpsa\Datastore;
4
5
use Illuminate\Support\Facades\Blade;
6
use Phpsa\Datastore\Helpers;
7
use Illuminate\Support\Facades\Route;
8
9
10
class ServiceProvider extends \Illuminate\Support\ServiceProvider
11
{
12
    const CONFIG_PATH = __DIR__ . '/../config/datastore.php';
13
14
    public function boot()
15
    {
16
		// publish our pacakge
17
        $this->publishes([
18
            self::CONFIG_PATH => config_path('datastore.php'),
19
		], 'config');
20
21
		//set our migratinos directory
22
		$this->loadMigrationsFrom(__DIR__.'/Database/migrations');
23
24
		//Router
25
		Route::middleware('web')
26
			->group(__DIR__.'/routes.php');
27
28
		//Breadcrumbs
29
		if (class_exists('Breadcrumbs')) {
30
			require __DIR__ . '/breadcrumbs.php';
31
		}
32
33
		//Translations
34
		$this->loadTranslationsFrom(__DIR__.'/translations', 'phpsa-datastore');
35
36
		$this->publishes([
37
			__DIR__.'/translations' => resource_path('lang/vendor/phpsa-datastore'),
38
			// Assets
39
			__DIR__.'/resources/js' => public_path('vendor/phpsa-datastore/js'),
40
			__DIR__.'/resources/css' => public_path('vendor/phpsa-datastore/css'),
41
			__DIR__.'/resources/img' => public_path('vendor/phpsa-datastore/img'),
42
			__DIR__.'/resources/thumbs' => public_path('vendor/phpsa-datastore/thumbs'),
43
		]);
44
45
		$this->registerBladeHelpers();
46
    }
47
48
    public function register()
49
    {
50
        $this->mergeConfigFrom(
51
            self::CONFIG_PATH,
52
            'datastore'
53
        );
54
55
        $this->app->bind('datastore', function () {
56
            return new Datastore();
57
		});
58
59
		$this->loadViewsFrom(__DIR__.'/views', 'phpsa-datastore');
60
	}
61
62
63
	public function registerBladeHelpers(){
64
		Blade::directive('datastoreAssetList', function ($grouped = false) {
65
            return Helpers::getAssetList($grouped, false);
0 ignored issues
show
Bug introduced by
Are you sure the usage of Phpsa\Datastore\Helpers:...etList($grouped, false) targeting Phpsa\Datastore\Helpers::getAssetList() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
66
		});
67
68
		Blade::directive('forDatastores', function () {
69
			return "<?php foreach(Phpsa\Datastore\Helpers::getAssetList(1, 0) as \$datastoreKey => \$datastoreData): ?>";
70
		});
71
72
		Blade::directive('endforDatastores', function () {
73
			return "<?php endforeach; ?>";
74
		});
75
	}
76
}
77