Passed
Push — master ( e6afbd...41d08a )
by Aimeos
07:18
created

ShopServiceProvider::boot()   B

Complexity

Conditions 11
Paths 8

Size

Total Lines 34
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 18
c 7
b 0
f 0
dl 0
loc 34
rs 7.3166
cc 11
nc 8
nop 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 */
8
9
10
namespace Aimeos\Shop;
11
12
use Illuminate\Support\ServiceProvider;
13
use Illuminate\Support\Facades\Blade;
14
use Illuminate\Support\Facades\Route;
15
16
17
/**
18
 * Aimeos shop service provider for Laravel
19
 * @package laravel
20
 */
21
class ShopServiceProvider extends ServiceProvider {
22
23
	/**
24
	 * Indicates if loading of the provider is deferred.
25
	 *
26
	 * @var bool
27
	 */
28
	protected $defer = false;
29
30
31
	/**
32
	 * Bootstrap the application events.
33
	 *
34
	 * @return void
35
	 */
36
	public function boot()
37
	{
38
		$ds = DIRECTORY_SEPARATOR;
39
		$basedir = dirname( __DIR__, 2 ) . $ds;
40
41
		$this->loadRoutesFrom( $basedir . 'routes.php' );
42
		$this->loadViewsFrom( $basedir . 'views', 'shop' );
43
44
		$this->publishes( [$basedir . 'config/shop.php' => config_path( 'shop.php' )], 'config' );
45
		$this->publishes( [dirname( $basedir ) . $ds . 'public' => public_path( 'vendor/shop' )], 'public' );
46
47
		if( file_exists( $basepath = base_path( 'ext' ) ) )
48
		{
49
			foreach( new \DirectoryIterator( $basepath ) as $entry )
50
			{
51
				if( $entry->isDir() && !$entry->isDot() && file_exists( $entry->getPathName() . '/client/html/themes' ) ) {
52
					$this->publishes( [$entry->getPathName() . '/client/html/themes' => public_path( 'vendor/shop/themes' )], 'public' );
53
				}
54
			}
55
		}
56
57
		$class = '\Composer\InstalledVersions';
58
59
		if( class_exists( $class ) && method_exists( $class, 'getInstalledPackagesByType' ) )
60
		{
61
			$extdir = base_path( 'ext' );
62
			$packages = \Composer\InstalledVersions::getInstalledPackagesByType( 'aimeos-extension' );
63
64
			foreach( $packages as $package )
65
			{
66
				$path = realpath( \Composer\InstalledVersions::getInstallPath( $package ) );
0 ignored issues
show
Bug introduced by
It seems like Composer\InstalledVersio...etInstallPath($package) can also be of type null; however, parameter $path of realpath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

66
				$path = realpath( /** @scrutinizer ignore-type */ \Composer\InstalledVersions::getInstallPath( $package ) );
Loading history...
67
68
				if( strncmp( $path, $extdir, strlen( $extdir ) ) && file_exists( $path . '/client/html/themes' ) ) {
69
					$this->publishes( [$path . '/client/html/themes' => public_path( 'vendor/shop/themes' )], 'public' );
70
				}
71
			}
72
		}
73
	}
74
75
76
	/**
77
	 * Register the service provider.
78
	 *
79
	 * @return void
80
	 */
81
	public function register()
82
	{
83
		$this->mergeConfigFrom( dirname( dirname( __DIR__ ) ) . DIRECTORY_SEPARATOR . 'default.php', 'shop' );
84
85
		$this->app->singleton( 'aimeos', function( $app ) {
86
			return new \Aimeos\Shop\Base\Aimeos( $app['config'] );
87
		});
88
89
		$this->app->singleton( 'aimeos.config', function( $app ) {
90
			return new \Aimeos\Shop\Base\Config( $app['config'], $app['aimeos'] );
91
		});
92
93
		$this->app->singleton( 'aimeos.i18n', function( $app ) {
94
			return new \Aimeos\Shop\Base\I18n( $this->app['config'], $app['aimeos'] );
95
		});
96
97
		$this->app->singleton( 'aimeos.locale', function( $app ) {
98
			return new \Aimeos\Shop\Base\Locale( $app['config'] );
99
		});
100
101
		$this->app->singleton( 'aimeos.context', function( $app ) {
102
			return new \Aimeos\Shop\Base\Context( $app['session.store'], $app['aimeos.config'], $app['aimeos.locale'], $app['aimeos.i18n'] );
103
		});
104
105
		$this->app->singleton( 'aimeos.support', function( $app ) {
106
			return new \Aimeos\Shop\Base\Support( $app['aimeos.context'], $app['aimeos.locale'] );
107
		});
108
109
		$this->app->singleton( 'aimeos.view', function( $app ) {
110
			return new \Aimeos\Shop\Base\View( $app['config'], $app['aimeos.i18n'], $app['aimeos.support'] );
111
		});
112
113
		$this->app->singleton( 'aimeos.shop', function( $app ) {
114
			return new \Aimeos\Shop\Base\Shop( $app['aimeos'], $app['aimeos.context'], $app['aimeos.view'] );
115
		});
116
117
118
		$this->commands( array(
119
			'Aimeos\Shop\Command\AccountCommand',
120
			'Aimeos\Shop\Command\ClearCommand',
121
			'Aimeos\Shop\Command\SetupCommand',
122
			'Aimeos\Shop\Command\JobsCommand',
123
		) );
124
	}
125
126
127
	/**
128
	 * Get the services provided by the provider.
129
	 *
130
	 * @return array
131
	 */
132
	public function provides()
133
	{
134
		return array(
135
			'Aimeos\Shop\Base\Aimeos', 'Aimeos\Shop\Base\I18n', 'Aimeos\Shop\Base\Context',
136
			'Aimeos\Shop\Base\Config', 'Aimeos\Shop\Base\Locale', 'Aimeos\Shop\Base\View',
137
			'Aimeos\Shop\Base\Support', 'Aimeos\Shop\Base\Shop',
138
			'Aimeos\Shop\Command\AccountCommand', 'Aimeos\Shop\Command\ClearCommand',
139
			'Aimeos\Shop\Command\SetupCommand', 'Aimeos\Shop\Command\JobsCommand',
140
		);
141
	}
142
143
}