Completed
Push — master ( cb32ca...f4aa28 )
by ARCANEDEV
25s
created

PackageServiceProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 155
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 7

Test Coverage

Coverage 60.71%

Importance

Changes 0
Metric Value
dl 0
loc 155
ccs 17
cts 28
cp 0.6071
rs 10
c 0
b 0
f 0
wmc 10
lcom 3
cbo 7

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A resolveBasePath() 0 6 1
A getBasePath() 0 4 1
A getDatabasePath() 0 4 1
A getResourcesPath() 0 4 1
A register() 0 6 1
A publishAll() 0 8 1
A checkPackageName() 0 5 3
1
<?php namespace Arcanedev\Support\Providers;
2
3
use Arcanedev\Support\Exceptions\PackageException;
4
use Arcanedev\Support\Providers\Concerns\{
5
    HasConfig, HasFactories, HasMigrations, HasTranslations, HasViews
6
};
7
use Illuminate\Contracts\Foundation\Application;
8
use ReflectionClass;
9
10
/**
11
 * Class     PackageServiceProvider
12
 *
13
 * @package  Arcanedev\Support\Providers
14
 * @author   ARCANEDEV <[email protected]>
15
 */
16
abstract class PackageServiceProvider extends ServiceProvider
17
{
18
    /* -----------------------------------------------------------------
19
     |  Traits
20
     | -----------------------------------------------------------------
21
     */
22
23
    use HasConfig,
24
        HasFactories,
25
        HasMigrations,
26
        HasTranslations,
27
        HasViews;
28
29
    /* -----------------------------------------------------------------
30
     |  Properties
31
     | -----------------------------------------------------------------
32
     */
33
34
    /**
35
     * Vendor name.
36
     *
37
     * @var string
38
     */
39
    protected $vendor = 'arcanedev';
40
41
    /**
42
     * Package name.
43
     *
44
     * @var string
45
     */
46
    protected $package = '';
47
48
    /**
49
     * Package base path.
50
     *
51
     * @var string
52
     */
53
    protected $basePath;
54
55
    /* -----------------------------------------------------------------
56
     |  Constructor
57
     | -----------------------------------------------------------------
58
     */
59
60
    /**
61
     * Create a new service provider instance.
62
     *
63
     * @param  \Illuminate\Contracts\Foundation\Application  $app
64
     */
65 6
    public function __construct(Application $app)
66
    {
67 6
        parent::__construct($app);
68
69 6
        $this->basePath = $this->resolveBasePath();
70 6
    }
71
72
    /**
73
     * Resolve the base path of the package.
74
     *
75
     * @return string
76
     */
77 6
    protected function resolveBasePath()
78
    {
79 6
        return dirname(
80 6
            (new ReflectionClass($this))->getFileName(), 2
81
        );
82
    }
83
84
    /* -----------------------------------------------------------------
85
     |  Getters & Setters
86
     | -----------------------------------------------------------------
87
     */
88
89
    /**
90
     * Get the base path of the package.
91
     *
92
     * @return string
93
     */
94 6
    public function getBasePath()
95
    {
96 6
        return $this->basePath;
97
    }
98
99
    /**
100
     * Get the base database path.
101
     *
102
     * @return string
103
     */
104
    protected function getDatabasePath()
105
    {
106
        return $this->getBasePath().DS.'database';
107
    }
108
109
    /**
110
     * Get the base resources path.
111
     *
112
     * @deprecated Use the getBasePath() instead!
113
     *
114
     * @return string
115
     */
116
    protected function getResourcesPath()
117
    {
118
        return $this->getBasePath().DS.'resources';
119
    }
120
121
    /* -----------------------------------------------------------------
122
     |  Main Methods
123
     | -----------------------------------------------------------------
124
     */
125
126
    /**
127
     * Register the service provider.
128
     */
129 6
    public function register()
130
    {
131 6
        parent::register();
132
133 6
        $this->checkPackageName();
134 6
    }
135
136
    /* -----------------------------------------------------------------
137
     |  Package Methods
138
     | -----------------------------------------------------------------
139
     */
140
141
    /**
142
     * Publish all the package files.
143
     *
144
     * @param  bool  $load
145
     */
146
    protected function publishAll($load = true)
147
    {
148
        $this->publishConfig();
149
        $this->publishMigrations();
150
        $this->publishViews($load);
151
        $this->publishTranslations($load);
152
        $this->publishFactories();
153
    }
154
155
    /* ------------------------------------------------------------------------------------------------
156
     |  Check Functions
157
     | ------------------------------------------------------------------------------------------------
158
     */
159
160
    /**
161
     * Check package name.
162
     *
163
     * @throws \Arcanedev\Support\Exceptions\PackageException
164
     */
165 6
    private function checkPackageName()
166
    {
167 6
        if (empty($this->vendor) || empty($this->package))
168 2
            throw new PackageException('You must specify the vendor/package name.');
169 6
    }
170
}
171