Launcher::broadcast()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Leonidas\Plugin;
4
5
use Leonidas\Contracts\Extension\ExtensionLoaderInterface;
6
use Leonidas\Contracts\Extension\WpExtensionInterface;
7
use Leonidas\Framework\ExtensionLoader;
8
use Leonidas\Framework\Plugin\Plugin;
9
10
final class Launcher
11
{
12
    private ExtensionLoaderInterface $loader;
13
14
    private WpExtensionInterface $extension;
15
16
    private static self $instance;
17
18
    private function __construct(string $path, string $url)
19
    {
20
        $this->loader = new ExtensionLoader('plugin', $path, $url);
21
        $this->extension = $this->loader->getExtension();
22
    }
23
24
    private function launch(): void
25
    {
26
        $this->initiate()->boot()->broadcast();
27
    }
28
29
    private function initiate(): self
30
    {
31
        Leonidas::init($this->extension);
32
33
        return $this;
34
    }
35
36
    private function boot(): self
37
    {
38
        $this->loader->bootstrap();
39
40
        return $this;
41
    }
42
43
    private function broadcast(): void
44
    {
45
        $this->extension->doAction('loaded');
46
    }
47
48
    public static function init(string $base): void
49
    {
50
        !isset(self::$instance)
51
            ? self::load($base)
52
            : self::$instance->loader->error();
53
    }
54
55
    private static function load(string $base): void
56
    {
57
        self::$instance = new self(
58
            Plugin::path($base),
59
            Plugin::url($base),
60
        );
61
62
        self::$instance->launch();
63
    }
64
}
65