HydeKernel::version()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Hyde\Foundation;
6
7
use Hyde\Facades\Features;
8
use Hyde\Enums\Feature;
9
use Hyde\Foundation\Kernel\Filesystem;
10
use Hyde\Foundation\Kernel\Hyperlinks;
11
use Hyde\Foundation\Kernel\FileCollection;
12
use Hyde\Foundation\Kernel\PageCollection;
13
use Hyde\Foundation\Kernel\RouteCollection;
14
use Hyde\Support\Contracts\SerializableContract;
15
use Hyde\Support\Concerns\Serializable;
16
use Illuminate\Support\Traits\Macroable;
17
18
/**
19
 * Encapsulates a HydePHP project, providing helpful methods for interacting with it.
20
 *
21
 * @see \Hyde\Hyde for the facade commonly used to access this class.
22
 *
23
 * @author  Emma De Silva <[email protected]>
24
 * @copyright 2022 Emma De Silva
25
 * @license MIT License
26
 *
27
 * @link https://hydephp.com/
28
 *
29
 * @extra Usage information:
30
 *
31
 * The HydeKernel It is stored as a singleton in this class, and is bound into the
32
 * Laravel Application Service Container, and can be accessed in a few ways.
33
 *
34
 * Commonly, you'll use the Hyde facade to access it, but you can also use Dependency Injection
35
 * by type-hinting the HydeKernel::class, or use the hyde() function to get the Kernel.
36
 * The Kernel instance is constructed and bound in the app/bootstrap.php script.
37
 */
38
class HydeKernel implements SerializableContract
39
{
40
    use Concerns\HandlesFoundationCollections;
41
    use Concerns\ImplementsStringHelpers;
42
    use Concerns\ForwardsHyperlinks;
43
    use Concerns\ForwardsFilesystem;
0 ignored issues
show
Bug introduced by
The type Hyde\Foundation\Concerns\ForwardsFilesystem was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
44
    use Concerns\ManagesHydeKernel;
45
    use Concerns\ManagesExtensions;
46
    use Concerns\ManagesViewData;
47
    use Concerns\BootsHydeKernel;
48
    use Concerns\HasKernelData;
49
50
    use Serializable;
51
    use Macroable;
52
53
    final public const VERSION = '2.0.1';
54
55
    protected static self $instance;
56
57
    protected string $basePath;
58
    protected string $sourceRoot = '';
59
    protected string $outputDirectory = '_site';
60
    protected string $mediaDirectory = '_media';
61
62
    protected Features $features;
63
    protected Filesystem $filesystem;
64
    protected Hyperlinks $hyperlinks;
65
66
    protected FileCollection $files;
67
    protected PageCollection $pages;
68
    protected RouteCollection $routes;
69
70
    protected bool $booted = false;
71
72
    /** @var array<class-string<\Hyde\Foundation\Concerns\HydeExtension>, \Hyde\Foundation\Concerns\HydeExtension> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string<\Hyde...Concerns\HydeExtension> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string<\Hyde\Foundation\Concerns\HydeExtension>, \Hyde\Foundation\Concerns\HydeExtension>.
Loading history...
73
    protected array $extensions = [];
74
75
    public function __construct(?string $basePath = null)
76
    {
77
        $this->setBasePath($basePath ?? getcwd());
78
79
        $this->filesystem = new Filesystem($this);
80
        $this->hyperlinks = new Hyperlinks($this);
81
82
        $this->registerExtension(HydeCoreExtension::class);
83
    }
84
85
    public static function version(): string
86
    {
87
        return self::VERSION;
88
    }
89
90
    public function features(): Features
91
    {
92
        return $this->features ??= new Features();
93
    }
94
95
    public function hasFeature(Feature $feature): bool
96
    {
97
        return Features::has($feature);
98
    }
99
100
    /** @inheritDoc */
101
    public function toArray(): array
102
    {
103
        return [
104
            'version' => self::VERSION,
105
            'basePath' => $this->basePath,
106
            'sourceRoot' => $this->sourceRoot,
107
            'outputDirectory' => $this->outputDirectory,
108
            'mediaDirectory' => $this->mediaDirectory,
109
            'extensions' => $this->getRegisteredExtensions(),
110
            'features' => $this->features(),
111
            'files' => $this->files(),
112
            'pages' => $this->pages(),
113
            'routes' => $this->routes(),
114
            'authors' => $this->authors(),
115
        ];
116
    }
117
}
118