Passed
Push — stable ( f958a0...2a58cd )
by Nuno
04:01
created

Provider   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 52.63%

Importance

Changes 0
Metric Value
wmc 7
eloc 16
dl 0
loc 48
ccs 10
cts 19
cp 0.5263
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isAvailable() 0 3 1
A boot() 0 7 3
A register() 0 21 3
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of Laravel Zero.
7
 *
8
 * (c) Nuno Maduro <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace LaravelZero\Framework\Components\Updater;
15
16
use function class_exists;
17
use Humbug\SelfUpdate\Updater as PharUpdater;
18
use LaravelZero\Framework\Providers\Build\Build;
19
use LaravelZero\Framework\Components\AbstractComponentProvider;
20
21
/**
22
 * @internal
23
 */
24
final class Provider extends AbstractComponentProvider
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 37
    public function isAvailable(): bool
30
    {
31 37
        return class_exists(\Humbug\SelfUpdate\Updater::class);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 37
    public function boot(): void
38
    {
39 37
        $build = $this->app->make(Build::class);
40
41 37
        if ($build->isRunning() && $this->app->environment() === 'production') {
42
            $this->commands([
43
                SelfUpdateCommand::class,
44
            ]);
45
        }
46 37
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 37
    public function register(): void
52
    {
53 37
        $config = $this->app['config'];
54
55 37
        $build = $this->app->make(Build::class);
56
57 37
        if ($build->isRunning() && $config->get('app.production', false)) {
58
            $this->app->singleton(Updater::class, function () use ($build) {
59
60
                $updater = new PharUpdater($build->getPath(), false, PharUpdater::STRATEGY_GITHUB);
61
62
                $composer = json_decode(file_get_contents(base_path('composer.json')), true);
63
                $name = $composer['name'];
64
65
                $updater->setStrategyObject(new GithubStrategy);
66
67
                $updater->getStrategy()->setPackageName($name);
68
69
                $updater->getStrategy()->setCurrentLocalVersion(config('app.version'));
70
71
                return new Updater($updater);
72
            });
73
        }
74 37
    }
75
}
76