Passed
Push — master ( 9bbf4f...edf6a5 )
by Caen
02:59 queued 12s
created

HydeKernel::needsToBeBooted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Hyde\Framework;
4
5
use Composer\InstalledVersions;
6
use Hyde\Framework\Concerns\JsonSerializesArrayable;
7
use Hyde\Framework\Contracts\HydeKernelContract;
8
use Hyde\Framework\Contracts\RouteContract;
9
use Hyde\Framework\Foundation\FileCollection;
10
use Hyde\Framework\Foundation\Filesystem;
11
use Hyde\Framework\Foundation\Hyperlinks;
12
use Hyde\Framework\Foundation\PageCollection;
13
use Hyde\Framework\Foundation\RouteCollection;
14
use Hyde\Framework\Helpers\Features;
15
use Illuminate\Contracts\Support\Arrayable;
16
use Illuminate\Support\Facades\View;
17
use Illuminate\Support\Traits\Macroable;
18
19
/**
20
 * Encapsulates a HydePHP project, providing helpful methods for interacting with it.
21
 *
22
 * @see \Hyde\Framework\Hyde for the facade commonly used to access this class.
23
 *
24
 * @author  Caen De Silva <[email protected]>
25
 * @copyright 2022 Caen De Silva
26
 * @license MIT License
27
 *
28
 * @link https://hydephp.com/
29
 */
30
class HydeKernel implements HydeKernelContract, Arrayable, \JsonSerializable
0 ignored issues
show
Deprecated Code introduced by
The interface Hyde\Framework\Contracts\HydeKernelContract has been deprecated: v0.61.0-beta - Type hint the HydeKernel::class instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

30
class HydeKernel implements /** @scrutinizer ignore-deprecated */ HydeKernelContract, Arrayable, \JsonSerializable

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
31
{
32
    use Foundation\Concerns\HandlesFoundationCollections;
33
    use Foundation\Concerns\ImplementsStringHelpers;
34
    use Foundation\Concerns\ForwardsHyperlinks;
35
    use Foundation\Concerns\ForwardsFilesystem;
36
    use Foundation\Concerns\ManagesHydeKernel;
37
38
    use JsonSerializesArrayable;
39
    use Macroable;
0 ignored issues
show
Bug introduced by
The trait Illuminate\Support\Traits\Macroable requires the property $name which is not provided by Hyde\Framework\HydeKernel.
Loading history...
40
41
    protected static HydeKernel $instance;
42
43
    protected string $basePath;
44
45
    protected Filesystem $filesystem;
46
    protected Hyperlinks $hyperlinks;
47
48
    protected FileCollection $files;
49
    protected PageCollection $pages;
50
    protected RouteCollection $routes;
51
52
    protected bool $booted = false;
53
54
    public function __construct(?string $basePath = null)
55
    {
56
        $this->setBasePath($basePath ?? getcwd());
57
        $this->filesystem = new Filesystem($this);
58
        $this->hyperlinks = new Hyperlinks($this);
59
    }
60
61
    public static function version(): string
62
    {
63
        return InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased';
64
    }
65
66
    public function features(): Features
67
    {
68
        return new Features;
69
    }
70
71
    public function hasFeature(string $feature): bool
72
    {
73
        return Features::enabled($feature);
74
    }
75
76
    public function currentPage(): string
77
    {
78
        return View::shared('currentPage', '');
79
    }
80
81
    public function currentRoute(): ?RouteContract
82
    {
83
        return View::shared('currentRoute');
84
    }
85
86
    /**
87
     * @inheritDoc
88
     *
89
     * @return array{basePath: string, features: \Hyde\Framework\Helpers\Features, pages: \Hyde\Framework\Foundation\PageCollection, routes: \Hyde\Framework\Foundation\RouteCollection}
90
     */
91
    public function toArray(): array
92
    {
93
        return [
94
            'basePath' => $this->basePath,
95
            'features' => $this->features(),
96
            'files' => $this->files(),
97
            'pages' => $this->pages(),
98
            'routes' => $this->routes(),
99
        ];
100
    }
101
}
102