Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
18 / 18
CRAP
n/a
0 / 0
hyde
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
unslash
n/a
0 / 0
n/a
0 / 0
1
asset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
route
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
url
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\hyde
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\unslash
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\unixsum
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\unixsum_file
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\make_title
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\normalize_newlines
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\strip_newlines
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\trim_slashes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\evaluate_arrayable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
Hyde\yaml_encode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
Hyde\yaml_decode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\path_join
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
Hyde\normalize_slashes
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace {
6    use Hyde\Foundation\HydeKernel;
7    use JetBrains\PhpStorm\Deprecated;
8
9    if (! function_exists('hyde')) {
10        /**
11         * Get the available HydeKernel instance.
12         */
13        function hyde(): HydeKernel
14        {
15            return HydeKernel::getInstance();
16        }
17    }
18
19    if (! function_exists('unslash')) {
20        /**
21         * Remove trailing slashes from the start and end of a string.
22         *
23         * @deprecated This function will be replaced by {@see \Hyde\unslash()} in v2.0
24         *
25         * @codeCoverageIgnore This function is deprecated and will be removed in a future release.
26         */
27        #[Deprecated(reason: 'Replaced by the \Hyde\unslash() function', replacement: '\Hyde\unslash(%parametersList%)', since: '1.7.0')]
28        function unslash(string $string): string
29        {
30            return \Hyde\unslash($string);
31        }
32    }
33
34    if (defined('HYDE_COMPATIBILITY_MODE') && HYDE_COMPATIBILITY_MODE === true) {
35        // Don't declare these functions when running in compatibility mode.
36    } else {
37        if (! function_exists('asset')) {
38            /**
39             * Get a relative link or URL to an asset in the media directory.
40             */
41            function asset(string $name, bool $preferQualifiedUrl = false): string
42            {
43                return hyde()->asset($name, $preferQualifiedUrl);
44            }
45        }
46
47        if (! function_exists('route')) {
48            /**
49             * Get a page route instance by its key. Casting it to a string will return a relative link to the page.
50             */
51            function route(string $key): ?Hyde\Support\Models\Route
52            {
53                return hyde()->route($key);
54            }
55        }
56
57        if (! function_exists('url')) {
58            /**
59             * Get a qualified URL to the supplied path if a base URL is set.
60             */
61            function url(string $path = ''): string
62            {
63                return hyde()->url($path);
64            }
65        }
66    }
67}
68
69namespace Hyde {
70    use Hyde\Facades\Filesystem;
71    use Hyde\Foundation\HydeKernel;
72    use Illuminate\Contracts\Support\Arrayable;
73    use Symfony\Component\Yaml\Yaml;
74
75    use function function_exists;
76    use function array_merge;
77    use function str_replace;
78    use function implode;
79    use function trim;
80    use function md5;
81
82    if (! function_exists('\Hyde\hyde')) {
83        /**
84         * Get the available HydeKernel instance.
85         */
86        function hyde(): HydeKernel
87        {
88            return HydeKernel::getInstance();
89        }
90    }
91
92    if (! function_exists('\Hyde\unslash')) {
93        /**
94         * Remove trailing slashes from the start and end of a string.
95         */
96        function unslash(string $string): string
97        {
98            return trim($string, '/\\');
99        }
100    }
101
102    if (! function_exists('\Hyde\unixsum')) {
103        /**
104         * A EOL agnostic wrapper for calculating MD5 checksums.
105         *
106         * This function is not cryptographically secure.
107         */
108        function unixsum(string $string): string
109        {
110            return md5(str_replace(["\r\n", "\r"], "\n", $string));
111        }
112    }
113
114    if (! function_exists('\Hyde\unixsum_file')) {
115        /**
116         * Shorthand for {@see unixsum()} but loads a file.
117         */
118        function unixsum_file(string $file): string
119        {
120            return \Hyde\unixsum(Filesystem::getContents($file));
121        }
122    }
123
124    if (! function_exists('\Hyde\make_title')) {
125        function make_title(string $value): string
126        {
127            return hyde()->makeTitle($value);
128        }
129    }
130
131    if (! function_exists('\Hyde\normalize_newlines')) {
132        function normalize_newlines(string $string): string
133        {
134            return hyde()->normalizeNewlines($string);
135        }
136    }
137
138    if (! function_exists('\Hyde\strip_newlines')) {
139        function strip_newlines(string $string): string
140        {
141            return hyde()->stripNewlines($string);
142        }
143    }
144
145    if (! function_exists('\Hyde\trim_slashes')) {
146        function trim_slashes(string $string): string
147        {
148            return hyde()->trimSlashes($string);
149        }
150    }
151
152    if (! function_exists('\Hyde\evaluate_arrayable')) {
153        function evaluate_arrayable(array|Arrayable $array): array
154        {
155            return $array instanceof Arrayable ? $array->toArray() : $array;
156        }
157    }
158
159    if (! function_exists('\Hyde\yaml_encode')) {
160        function yaml_encode(mixed $input, int $inline = 2, int $indent = 4, int $flags = 0): string
161        {
162            return Yaml::dump($input instanceof Arrayable ? $input->toArray() : $input, $inline, $indent, $flags);
163        }
164    }
165
166    if (! function_exists('\Hyde\yaml_decode')) {
167        function yaml_decode(string $input, int $flags = 0): mixed
168        {
169            return Yaml::parse($input, $flags);
170        }
171    }
172
173    if (! function_exists('\Hyde\path_join')) {
174        function path_join(string $directory, string ...$paths): string
175        {
176            return implode('/', array_merge([$directory], $paths));
177        }
178    }
179
180    if (! function_exists('\Hyde\normalize_slashes')) {
181        function normalize_slashes(string $string): string
182        {
183            return str_replace('\\', '/', $string);
184        }
185    }
186}