Provider::register()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5.3197

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 11
c 4
b 0
f 0
dl 0
loc 20
rs 9.9
ccs 4
cts 11
cp 0.3636
cc 3
nc 2
nop 0
crap 5.3197
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\Components\AbstractComponentProvider;
19
use LaravelZero\Framework\Providers\Build\Build;
20
21
/**
22
 * @internal
23
 */
24
final class Provider extends AbstractComponentProvider
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29 39
    public function isAvailable(): bool
30
    {
31 39
        return class_exists(\Humbug\SelfUpdate\Updater::class);
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37 39
    public function boot(): void
38
    {
39 39
        $build = $this->app->make(Build::class);
40
41 39
        if ($build->isRunning() && $this->app->environment() === 'production') {
42
            $this->commands([
43
                SelfUpdateCommand::class,
44
            ]);
45
        }
46 39
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 39
    public function register(): void
52
    {
53 39
        $config = $this->app['config'];
54
55 39
        $build = $this->app->make(Build::class);
56
57 39
        if ($build->isRunning() && $config->get('app.production', false)) {
58
            $this->app->singleton(Updater::class, function () use ($build) {
59
                $updater = new PharUpdater($build->getPath(), false, PharUpdater::STRATEGY_GITHUB);
60
61
                $composer = json_decode(file_get_contents(base_path('composer.json')), true);
62
                $name = $composer['name'];
63
64
                $updater->setStrategyObject(new GithubStrategy);
65
66
                $updater->getStrategy()->setPackageName($name);
67
68
                $updater->getStrategy()->setCurrentLocalVersion(config('app.version'));
69
70
                return new Updater($updater);
71
            });
72
        }
73 39
    }
74
}
75