Passed
Push — master ( ef93dc...4f7931 )
by
unknown
13:58
created

ServiceProvider::provides()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of ibrand/laravel-sms.
5
 *
6
 * (c) iBrand <https://www.ibrand.cc>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace iBrand\Sms;
13
14
use iBrand\Sms\Storage\CacheStorage;
15
use Illuminate\Support\Facades\Route;
16
use Overtrue\EasySms\EasySms;
17
use iBrand\Sms\Http\Middleware\ThrottleRequests;
18
19
/**
20
 * Class ServiceProvider.
21
 */
22
class ServiceProvider extends \Illuminate\Support\ServiceProvider
23
{
24
	/**
25
	 * @var string
26
	 */
27
	protected $namespace = 'iBrand\Sms';
28
29
	/**
30
	 * Boot the service provider.
31
	 */
32 40
	public function boot()
33
	{
34 40
		if ($this->app->runningInConsole()) {
35 40
			$this->publishes([
36 40
				__DIR__ . '/../config/config.php' => config_path('ibrand/sms.php'),
37
			]);
38
39 40
			$this->loadMigrationsFrom(__DIR__ . '/../migrations');
40
		}
41
42 40
		if (!$this->app->routesAreCached()) {
43 40
			$routeAttr = config('ibrand.sms.route', []);
44 40
			if (config('ibrand.sms.enable_rate_limit')) {
45 40
				$routeAttr['middleware'] = array_merge($routeAttr['middleware'], [config('ibrand.sms.rate_limit_middleware') . ':' . config('ibrand.sms.rate_limit_count') . ',' . config('ibrand.sms.rate_limit_time')]);
46
			}
47
48 40
			Route::group(array_merge(['namespace' => $this->namespace], $routeAttr), function ($router) {
49 40
				require __DIR__ . '/route.php';
50 40
			});
51
		}
52 40
	}
53
54
	/**
55
	 * Register the service provider.
56
	 */
57 40
	public function register()
58
	{
59 40
		$this->mergeConfigFrom(
60 40
			__DIR__ . '/../config/config.php', 'ibrand.sms'
61
		);
62
63 40
		$this->app->singleton(Sms::class, function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64 31
			$storage = config('ibrand.sms.storage', CacheStorage::class);
65
66 31
			return new Sms(new EasySms(config('ibrand.sms.easy_sms')), new $storage());
67 40
		});
68 40
	}
69
70
	/**
71
	 * @return array
72
	 */
73
	public function provides()
74
	{
75
		return [Sms::class];
76
	}
77
}
78