Skip to content

Commit c215719

Browse files
authored
Merge pull request #755 from hydephp/refactor-internal-code
Refactor internal code
2 parents 39f3e53 + 0626e59 commit c215719

File tree

18 files changed

+137
-89
lines changed

18 files changed

+137
-89
lines changed

packages/framework/src/Facades/Filesystem.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ public static function putContents(string $path, string $contents, bool $lock =
130130
return self::put($path, $contents, $lock);
131131
}
132132

133-
protected static function qualifyPossiblePathArray(array|string $paths): array|string
134-
{
135-
return self::kernel()->filesystem()->qualifyPossiblePathArray($paths);
136-
}
137-
138133
protected static function filesystem(): \Illuminate\Filesystem\Filesystem
139134
{
140135
return File::getFacadeRoot();

packages/framework/src/Foundation/Concerns/BaseFoundationCollection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Illuminate\Support\Collection;
1010

1111
/**
12-
* @internal Base class for the kernel auto-discovery collections.
12+
* Base class for the kernel auto-discovery collections.
1313
*
1414
* @see \Hyde\Foundation\FileCollection
1515
* @see \Hyde\Foundation\PageCollection

packages/framework/src/Foundation/Concerns/ForwardsFilesystem.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function sitePath(string $path = ''): string
7373
return $this->filesystem->sitePath($path);
7474
}
7575

76-
public function pathToAbsolute(string $path): string
76+
public function pathToAbsolute(array|string $path): array|string
7777
{
7878
return $this->filesystem->pathToAbsolute($path);
7979
}

packages/framework/src/Foundation/Filesystem.php

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Hyde\Foundation;
66

7+
use function array_map;
78
use function collect;
89
use function copy;
910
use Hyde\Facades\Site;
@@ -14,6 +15,7 @@
1415
use Hyde\Pages\MarkdownPage;
1516
use Hyde\Pages\MarkdownPost;
1617
use Illuminate\Support\Collection;
18+
use function is_array;
1719
use function is_string;
1820
use function str_replace;
1921
use function touch;
@@ -66,9 +68,15 @@ public function path(string $path = ''): string
6668

6769
/**
6870
* Get an absolute file path from a supplied relative path.
71+
*
72+
* Input types are matched, meaning that if the input is a string so will the output be.
6973
*/
70-
public function pathToAbsolute(string $path): string
74+
public function pathToAbsolute(array|string $path): array|string
7175
{
76+
if (is_array($path)) {
77+
return array_map(fn (string $path): string => $this->pathToAbsolute($path), $path);
78+
}
79+
7280
return $this->path($path);
7381
}
7482

@@ -205,16 +213,6 @@ public function smartGlob(string $pattern, int $flags = 0): Collection
205213
->map(fn (string $path): string => $this->pathToRelative($path));
206214
}
207215

208-
/** @internal */
209-
public function qualifyPossiblePathArray(array|string $paths): array|string
210-
{
211-
if (is_array($paths)) {
212-
return array_map(fn ($path) => $this->pathToAbsolute($path), $paths);
213-
}
214-
215-
return $this->pathToAbsolute($paths);
216-
}
217-
218216
/**
219217
* Implode path components into a string with directory separators.
220218
*/

packages/framework/src/Framework/Actions/BladeMatterParser.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@
44

55
namespace Hyde\Framework\Actions;
66

7+
use function explode;
8+
use function file_get_contents;
79
use Hyde\Hyde;
10+
use function json_decode;
811
use RuntimeException;
12+
use function strlen;
13+
use function strpos;
14+
use function substr;
15+
use function substr_count;
16+
use function trim;
917

1018
/**
1119
* Parse the front matter in a Blade file.
@@ -69,21 +77,19 @@ public function parse(): static
6977

7078
foreach ($lines as $line) {
7179
if (static::lineMatchesFrontMatter($line)) {
72-
$this->matter[static::extractKey($line)] = static::normalizeValue(static::extractValue($line));
80+
$this->matter[static::extractKey($line)] = static::getValueWithType(static::extractValue($line));
7381
}
7482
}
7583

7684
return $this;
7785
}
7886

79-
/** @internal */
80-
public static function lineMatchesFrontMatter(string $line): bool
87+
protected static function lineMatchesFrontMatter(string $line): bool
8188
{
8289
return str_starts_with($line, static::SEARCH);
8390
}
8491

85-
/** @internal */
86-
public static function extractKey(string $line): string
92+
protected static function extractKey(string $line): string
8793
{
8894
// Remove search prefix
8995
$key = substr($line, strlen(static::SEARCH));
@@ -95,8 +101,7 @@ public static function extractKey(string $line): string
95101
return trim($key);
96102
}
97103

98-
/** @internal */
99-
public static function extractValue(string $line): string
104+
protected static function extractValue(string $line): string
100105
{
101106
// Trim any trailing spaces and newlines
102107
$key = trim($line);
@@ -114,8 +119,7 @@ public static function extractValue(string $line): string
114119
return trim($key);
115120
}
116121

117-
/** @internal Return the proper type for the string */
118-
public static function normalizeValue(string $value): mixed
122+
protected static function getValueWithType(string $value): mixed
119123
{
120124
$value = trim($value);
121125

@@ -132,8 +136,7 @@ public static function normalizeValue(string $value): mixed
132136
return json_decode($value) ?? $value;
133137
}
134138

135-
/** @internal */
136-
public static function parseArrayString(string $string): array
139+
protected static function parseArrayString(string $string): array
137140
{
138141
$array = [];
139142

@@ -153,7 +156,7 @@ public static function parseArrayString(string $string): array
153156
// Remove opening and closing brackets
154157
$string = substr($string, 1, strlen($string) - 2);
155158

156-
// tokenize string between commas
159+
// Tokenize string between commas
157160
$tokens = explode(',', $string);
158161

159162
// Parse each token
@@ -162,7 +165,7 @@ public static function parseArrayString(string $string): array
162165
$pair = explode('=>', $entry);
163166

164167
// Add key/value pair to array
165-
$array[static::normalizeValue(trim(trim($pair[0]), "'"))] = static::normalizeValue(trim(trim($pair[1]), "'"));
168+
$array[static::getValueWithType(trim(trim($pair[0]), "'"))] = static::getValueWithType(trim(trim($pair[1]), "'"));
166169
}
167170

168171
return $array;

packages/framework/src/Framework/Concerns/Internal/ForwardsIlluminateFilesystem.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/**
1010
* Forwards calls to the Laravel File facade to the HydePHP Filesystem Facade.
1111
*
12-
* @interal
12+
* @interal This trait is not covered by the backward compatibility promise.
1313
*
1414
* @see \Hyde\Facades\Filesystem
1515
*/
@@ -102,7 +102,7 @@ public static function chmod(string $path, int $mode = null): mixed
102102
/** @inheritDoc */
103103
public static function delete(array|string $paths): bool
104104
{
105-
return self::filesystem()->delete(self::qualifyPossiblePathArray($paths));
105+
return self::filesystem()->delete(self::kernel()->filesystem()->pathToAbsolute($paths));
106106
}
107107

108108
/** @inheritDoc */

packages/framework/src/Framework/Concerns/Internal/MockableFeatures.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
namespace Hyde\Framework\Concerns\Internal;
66

77
/**
8-
* @internal
8+
* Allows the Features class to be mocked.
9+
*
10+
* @internal This trait is not covered by the backward compatibility promise.
11+
*
12+
* @see \Hyde\Facades\Features
913
*/
1014
trait MockableFeatures
1115
{

packages/framework/src/Framework/Concerns/Internal/SetsUpMarkdownConverter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
use Torchlight\Commonmark\V2\TorchlightExtension;
1111

1212
/**
13-
* @internal Sets up the Markdown converter for the Markdown service.
13+
* Sets up the Markdown converter for the Markdown service.
14+
*
15+
* @internal This trait is not covered by the backward compatibility promise.
1416
*
1517
* @see \Hyde\Framework\Services\MarkdownService
1618
*/

packages/framework/src/Framework/Features/BuildTasks/PostBuildTasks/GenerateSearch.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public function then(): void
3636
$this->createdSiteFile(DocumentationSearchService::$filePath)->withExecutionTime();
3737
}
3838

39-
/** @internal Estimated processing time per file in ms */
40-
public static float $guesstimationFactor = 52.5;
39+
/**
40+
* Estimated processing time per file in ms.
41+
*/
42+
protected static float $guesstimationFactor = 52.5;
4143

4244
protected function guesstimateGenerationTime(): int|float
4345
{

packages/framework/src/Framework/Features/Documentation/SemanticDocumentationArticle.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function renderFooter(): HtmlString
5959
return new HtmlString($this->footer);
6060
}
6161

62-
/** @internal */
6362
protected function process(): self
6463
{
6564
$this->tokenize();

0 commit comments

Comments
 (0)