VersionServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
eloc 32
c 3
b 0
f 0
dl 0
loc 69
ccs 28
cts 28
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 15 2
A boot() 0 37 4
1
<?php
2
3
namespace Spinen\Version;
4
5
use Illuminate\Contracts\Routing\Registrar as Router;
6
use Illuminate\Support\ServiceProvider;
7
use Spinen\Version\Commands\MajorVersionCommand;
8
use Spinen\Version\Commands\MetaVersionCommand;
9
use Spinen\Version\Commands\MinorVersionCommand;
10
use Spinen\Version\Commands\PatchVersionCommand;
11
use Spinen\Version\Commands\PreReleaseVersionCommand;
12
use Spinen\Version\Commands\SemVersionCommand;
13
use Spinen\Version\Commands\VersionCommand;
14
15
/**
16
 * Class VersionServiceProvider
17
 *
18
 * @package Spinen\Version
19
 */
20
class VersionServiceProvider extends ServiceProvider
21
{
22
    /**
23
     * Perform post-registration booting of services.
24
     *
25
     * @return void
26
     */
27 7
    public function boot()
28
    {
29 7
        if ($this->app['config']->get('version.route.enabled')) {
30 2
            $this->app['router']->group(
31
                [
32 2
                    'namespace'  => 'Spinen\Version\Http\Controllers',
33 2
                    'middleware' => $this->app['config']->get('version.route.middleware', 'web'),
34
                ],
35
                function (Router $router) {
36 1
                    $router->get($this->app['config']->get('version.route.uri', 'version'), 'VersionController@version')
37 1
                           ->name($this->app['config']->get('version.route.name', 'version'));
38 2
                }
39
            );
40
        }
41
42 7
        if ($this->app['config']->get('version.view.enabled')) {
43 2
            $this->app['view']->composer(
44 2
                $this->app['config']->get('version.view.views', '*'),
45
                function ($view) {
46 1
                    return $view->with(
47 1
                        $this->app['config']->get('version.view.variable', 'version'),
48 1
                        $this->app->make(Version::class)
49
                    );
50 2
                }
51
            );
52
        }
53
54 7
        if ($this->app->runningInConsole()) {
55 7
            $this->commands(
56
                [
57 7
                    MajorVersionCommand::class,
58
                    MetaVersionCommand::class,
59
                    MinorVersionCommand::class,
60
                    PatchVersionCommand::class,
61
                    PreReleaseVersionCommand::class,
62
                    SemVersionCommand::class,
63
                    VersionCommand::class,
64
                ]
65
            );
66
        }
67 7
    }
68
69
    /**
70
     * Register the service provider.
71
     *
72
     * @return void
73
     */
74 2
    public function register()
75
    {
76 2
        $this->app->singleton(
77 2
            Version::class,
78
            function () {
79 1
                return new Version(base_path($this->app['config']->get('version.file', 'VERSION')));
80 2
            }
81
        );
82
83 2
        if ($this->app->runningInConsole()) {
84 2
            $this->publishes(
85
                [
86 2
                    realpath(__DIR__ . '/../config/version.php') => config_path('version.php'),
87
                ],
88 2
                'version-config'
89
            );
90
        }
91 2
    }
92
}
93