Passed
Push — master ( 794674...e99464 )
by Caen
03:59 queued 13s
created

unixsum_file()   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
declare(strict_types=1);
4
5
namespace {
6
    use Hyde\Foundation\HydeKernel;
7
8
    if (! function_exists('hyde')) {
9
        /**
10
         * Get the available HydeKernel instance.
11
         */
12
        function hyde(): HydeKernel
13
        {
14
            return app(HydeKernel::class);
15
        }
16
    }
17
18
    if (! function_exists('unslash')) {
19
        /**
20
         * Remove trailing slashes from the start and end of a string.
21
         */
22
        function unslash(string $string): string
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
23
        {
24
            return trim($string, '/\\');
25
        }
26
    }
27
}
28
29
namespace Hyde {
30
    use Hyde\Facades\Filesystem;
31
    use Hyde\Foundation\HydeKernel;
32
    use Illuminate\Contracts\Support\Arrayable;
33
    use Symfony\Component\Yaml\Yaml;
34
35
    if (! function_exists('\Hyde\hyde')) {
36
        /**
37
         * Get the available HydeKernel instance.
38
         */
39
        function hyde(): HydeKernel
40
        {
41
            return app(HydeKernel::class);
42
        }
43
    }
44
45
    if (! function_exists('\Hyde\unslash')) {
46
        /**
47
         * Remove trailing slashes from the start and end of a string.
48
         */
49
        function unslash(string $string): string
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
        {
51
            return trim($string, '/\\');
52
        }
53
    }
54
55
    if (! function_exists('\Hyde\unixsum')) {
56
        /**
57
         * A EOL agnostic wrapper for calculating MD5 checksums.
58
         *
59
         * This function is not cryptographically secure.
60
         */
61
        function unixsum(string $string): string
62
        {
63
            return md5(str_replace(["\r\n", "\r"], "\n", $string));
64
        }
65
    }
66
67
    if (! function_exists('\Hyde\unixsum_file')) {
68
        /**
69
         * Shorthand for {@see unixsum()} but loads a file.
70
         */
71
        function unixsum_file(string $file): string
72
        {
73
            return \Hyde\unixsum(Filesystem::getContents($file));
74
        }
75
    }
76
77
    if (! function_exists('\Hyde\make_title')) {
78
        function make_title(string $value): string
79
        {
80
            return hyde()->makeTitle($value);
81
        }
82
    }
83
84
    if (! function_exists('\Hyde\normalize_newlines')) {
85
        function normalize_newlines(string $string): string
86
        {
87
            return hyde()->normalizeNewlines($string);
88
        }
89
    }
90
91
    if (! function_exists('\Hyde\strip_newlines')) {
92
        function strip_newlines(string $string): string
93
        {
94
            return hyde()->stripNewlines($string);
95
        }
96
    }
97
98
    if (! function_exists('\Hyde\trim_slashes')) {
99
        function trim_slashes(string $string): string
100
        {
101
            return hyde()->trimSlashes($string);
102
        }
103
    }
104
105
    if (! function_exists('\Hyde\evaluate_arrayable')) {
106
        function evaluate_arrayable(array|Arrayable $array): array
107
        {
108
            return $array instanceof Arrayable ? $array->toArray() : $array;
0 ignored issues
show
introduced by
$array is never a sub-type of Illuminate\Contracts\Support\Arrayable.
Loading history...
109
        }
110
    }
111
112
    if (! function_exists('\Hyde\yaml_encode')) {
113
        function yaml_encode(mixed $input, int $inline = 2, int $indent = 4, int $flags = 0): string
114
        {
115
            return Yaml::dump($input instanceof Arrayable ? $input->toArray() : $input, $inline, $indent, $flags);
116
        }
117
    }
118
119
    if (! function_exists('\Hyde\yaml_decode')) {
120
        function yaml_decode(string $input, int $flags = 0): mixed
121
        {
122
            return Yaml::parse($input, $flags);
123
        }
124
    }
125
126
    if (! function_exists('\Hyde\path_join')) {
127
        function path_join(string $directory, string ...$paths): string
128
        {
129
            return implode('/', array_merge([$directory], $paths));
130
        }
131
    }
132
133
    if (! function_exists('\Hyde\normalize_slashes')) {
134
        function normalize_slashes(string $string): string
135
        {
136
            return str_replace('\\', '/', $string);
137
        }
138
    }
139
}
140