Passed
Push — master ( 4f8b07...d0e934 )
by Caen
04:08 queued 12s
created

HydeKernel::touch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Hyde\Framework;
4
5
use Composer\InstalledVersions;
6
use Hyde\Framework\Contracts\HydeKernelContract;
7
use Hyde\Framework\Contracts\RouteContract;
8
use Hyde\Framework\Foundation\Filesystem;
9
use Hyde\Framework\Foundation\Hyperlinks;
10
use Hyde\Framework\Helpers\Features;
11
use Illuminate\Support\Facades\View;
12
use Illuminate\Support\Str;
13
use Illuminate\Support\Traits\Macroable;
14
15
/**
16
 * Encapsulates a HydePHP project, providing helpful methods for interacting with it.
17
 *
18
 * @see \Hyde\Framework\Hyde for the facade commonly used to access this class.
19
 *
20
 * @author  Caen De Silva <[email protected]>
21
 * @copyright 2022 Caen De Silva
22
 * @license MIT License
23
 *
24
 * @link https://hydephp.com/
25
 */
26
class HydeKernel implements HydeKernelContract
27
{
28
    use Macroable;
29
30
    protected string $basePath;
31
    protected Filesystem $filesystem;
32
    protected Hyperlinks $hyperlinks;
33
34
    public function __construct(?string $basePath = null)
35
    {
36
        $this->setBasePath($basePath ?? getcwd());
37
        $this->filesystem = new Filesystem($this);
38
        $this->hyperlinks = new Hyperlinks($this);
39
    }
40
41
    public static function getInstance(): HydeKernelContract
42
    {
43
        return app(HydeKernelContract::class);
44
    }
45
46
    public static function version(): string
47
    {
48
        return InstalledVersions::getPrettyVersion('hyde/framework') ?: 'unreleased';
49
    }
50
51
    public function getBasePath(): string
52
    {
53
        return $this->basePath;
54
    }
55
56
    public function setBasePath(string $basePath)
57
    {
58
        $this->basePath = rtrim($basePath, '/\\');
59
    }
60
61
    public function features(): Features
62
    {
63
        return new Features;
64
    }
65
66
    public function hasFeature(string $feature): bool
67
    {
68
        return Features::enabled($feature);
69
    }
70
71
    public function currentPage(): string
72
    {
73
        return View::shared('currentPage', '');
74
    }
75
76
    public function currentRoute(): ?RouteContract
77
    {
78
        return View::shared('currentRoute');
79
    }
80
81
    public function makeTitle(string $slug): string
82
    {
83
        $alwaysLowercase = ['a', 'an', 'the', 'in', 'on', 'by', 'with', 'of', 'and', 'or', 'but'];
84
85
        return ucfirst(str_ireplace(
0 ignored issues
show
Bug introduced by
It seems like str_ireplace($alwaysLowe...t\Str::headline($slug)) can also be of type array; however, parameter $string of ucfirst() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

85
        return ucfirst(/** @scrutinizer ignore-type */ str_ireplace(
Loading history...
86
            $alwaysLowercase,
87
            $alwaysLowercase,
88
            Str::headline($slug)
89
        ));
90
    }
91
92
    public function formatHtmlPath(string $destination): string
93
    {
94
        return $this->hyperlinks->formatHtmlPath($destination);
95
    }
96
97
    public function relativeLink(string $destination): string
98
    {
99
        return $this->hyperlinks->relativeLink($destination);
100
    }
101
102
    public function image(string $name): string
103
    {
104
        return $this->hyperlinks->image($name);
105
    }
106
107
    public function hasSiteUrl(): bool
108
    {
109
        return $this->hyperlinks->hasSiteUrl();
110
    }
111
112
    public function url(string $path = '', ?string $default = null): string
113
    {
114
        return $this->hyperlinks->url($path, $default);
115
    }
116
117
    public function path(string $path = ''): string
118
    {
119
        return $this->filesystem->path($path);
120
    }
121
122
    public function vendorPath(string $path = ''): string
123
    {
124
        return $this->filesystem->vendorPath($path);
125
    }
126
127
    public function copy(string $from, string $to): bool
128
    {
129
        return $this->filesystem->copy($from, $to);
130
    }
131
132
    public function touch(string|array $path): bool
133
    {
134
        return $this->filesystem->touch($path);
135
    }
136
137
    public function unlink(string|array $path): bool
138
    {
139
        return $this->filesystem->unlink($path);
140
    }
141
142
    public function getModelSourcePath(string $model, string $path = ''): string
143
    {
144
        return $this->filesystem->getModelSourcePath($model, $path);
145
    }
146
147
    public function getBladePagePath(string $path = ''): string
148
    {
149
        return $this->filesystem->getBladePagePath($path);
150
    }
151
152
    public function getMarkdownPagePath(string $path = ''): string
153
    {
154
        return $this->filesystem->getMarkdownPagePath($path);
155
    }
156
157
    public function getMarkdownPostPath(string $path = ''): string
158
    {
159
        return $this->filesystem->getMarkdownPostPath($path);
160
    }
161
162
    public function getDocumentationPagePath(string $path = ''): string
163
    {
164
        return $this->filesystem->getDocumentationPagePath($path);
165
    }
166
167
    public function getSiteOutputPath(string $path = ''): string
168
    {
169
        return $this->filesystem->getSiteOutputPath($path);
170
    }
171
172
    public function pathToRelative(string $path): string
173
    {
174
        return $this->filesystem->pathToRelative($path);
175
    }
176
}
177