• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

orchestral / sidekick / 14631564558

24 Apr 2025 01:39AM UTC coverage: 92.135% (-2.9%) from 95.0%
14631564558

Pull #25

github

web-flow
Merge f656b49cb into 12305ceb5
Pull Request #25: Add `Orchestra\Sidekick\Eloquent\normalize_value()` function

6 of 9 new or added lines in 1 file covered. (66.67%)

2 existing lines in 1 file now uncovered.

82 of 89 relevant lines covered (92.13%)

2.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.66
/src/functions.php
1
<?php
2

3
namespace Orchestra\Sidekick;
4

5
use Closure;
6
use Illuminate\Foundation\Application;
7
use Illuminate\Support\Arr;
8
use PHPUnit\Runner\Version;
9
use RuntimeException;
10

11
if (! \function_exists('Orchestra\Sidekick\join_paths')) {
12
    /**
13
     * Join the given paths together.
14
     *
15
     * @api
16
     */
17
    function join_paths(?string $basePath, string ...$paths): string
18
    {
19
        foreach ($paths as $index => $path) {
1✔
20
            if (empty($path) && $path !== '0') {
1✔
21
                unset($paths[$index]);
1✔
22
            } else {
23
                $paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR);
1✔
24
            }
25
        }
26

27
        return $basePath.implode('', $paths);
1✔
28
    }
29
}
30

31
if (! \function_exists('Orchestra\Sidekick\once')) {
32
    /**
33
     * Run callback only once.
34
     *
35
     * @api
36
     *
37
     * @param  mixed  $callback
38
     * @return \Closure():mixed
39
     */
40
    function once($callback): Closure
41
    {
42
        $response = new UndefinedValue;
5✔
43

44
        return function () use ($callback, &$response) {
5✔
45
            if ($response instanceof UndefinedValue) {
5✔
46
                $response = value($callback) ?? null;
5✔
47
            }
48

49
            return $response;
5✔
50
        };
5✔
51
    }
52
}
53

54
if (! \function_exists('Orchestra\Sidekick\is_safe_callable')) {
55
    /**
56
     * Determine if the value is a callable and not a string matching an available function name.
57
     */
58
    function is_safe_callable(mixed $value): bool
59
    {
60
        if ($value instanceof Closure) {
6✔
61
            return true;
1✔
62
        }
63

64
        if (! \is_callable($value)) {
5✔
65
            return false;
2✔
66
        }
67

68
        if (\is_array($value)) {
3✔
69
            $isList = \function_exists('array_is_list')
1✔
70
                ? array_is_list($value)
1✔
UNCOV
71
                : ! Arr::isAssoc($value);
×
72

73
            return \count($value) === 2 && $isList && method_exists(...$value);
1✔
74
        }
75

76
        return ! \is_string($value);
2✔
77
    }
78
}
79

80
if (! \function_exists('Orchestra\Sidekick\is_symlink')) {
81
    /**
82
     * Determine if the path is a symlink for both Unix and Windows environments.
83
     *
84
     * @api
85
     */
86
    function is_symlink(string $path): bool
87
    {
88
        if (windows_os() && is_dir($path) && readlink($path) !== $path) {
1✔
UNCOV
89
            return true;
×
90
        } elseif (is_link($path)) {
1✔
91
            return true;
×
92
        }
93

94
        return false;
1✔
95
    }
96
}
97

98
if (! \function_exists('Orchestra\Sidekick\transform_relative_path')) {
99
    /**
100
     * Transform relative path.
101
     *
102
     * @api
103
     */
104
    function transform_relative_path(string $path, string $workingPath): string
105
    {
106
        return str_starts_with($path, './')
1✔
107
            ? rtrim($workingPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.mb_substr($path, 2)
1✔
108
            : $path;
1✔
109
    }
110
}
111

112
if (! \function_exists('Orchestra\Sidekick\laravel_version_compare')) {
113
    /**
114
     * Laravel version compare.
115
     *
116
     * @api
117
     *
118
     * @template TOperator of string|null
119
     *
120
     * @phpstan-param  TOperator  $operator
121
     *
122
     * @phpstan-return (TOperator is null ? int : bool)
123
     *
124
     * @codeCoverageIgnore
125
     */
126
    function laravel_version_compare(string $version, ?string $operator = null): int|bool
127
    {
128
        if (! class_exists(Application::class)) {
129
            throw new RuntimeException('Unable to verify Laravel Framework version');
130
        }
131

132
        /** @var string $laravel */
133
        $laravel = transform(
134
            Application::VERSION,
135
            fn (string $version) => match ($version) {
136
                '13.x-dev' => '13.0.0',
137
                default => $version,
138
            }
139
        );
140

141
        if (\is_null($operator)) {
142
            return version_compare($laravel, $version);
143
        }
144

145
        return version_compare($laravel, $version, $operator);
146
    }
147
}
148

149
if (! \function_exists('Orchestra\Sidekick\phpunit_version_compare')) {
150
    /**
151
     * PHPUnit version compare.
152
     *
153
     * @api
154
     *
155
     * @template TOperator of string|null
156
     *
157
     * @throws \RuntimeException
158
     *
159
     * @phpstan-param  TOperator  $operator
160
     *
161
     * @phpstan-return (TOperator is null ? int : bool)
162
     *
163
     * @codeCoverageIgnore
164
     */
165
    function phpunit_version_compare(string $version, ?string $operator = null): int|bool
166
    {
167
        if (! class_exists(Version::class)) {
168
            throw new RuntimeException('Unable to verify PHPUnit version');
169
        }
170

171
        /** @var string $phpunit */
172
        $phpunit = transform(
173
            Version::id(),
174
            fn (string $version) => match (true) {
175
                str_starts_with($version, '12.2-') => '12.2.0',
176
                default => $version,
177
            }
178
        );
179

180
        if (\is_null($operator)) {
181
            return version_compare($phpunit, $version);
182
        }
183

184
        return version_compare($phpunit, $version, $operator);
185
    }
186
}
187

188
if (! \function_exists('Orchestra\Sidekick\php_binary')) {
189
    /**
190
     * Determine the PHP Binary.
191
     *
192
     * @api
193
     *
194
     * @codeCoverageIgnore
195
     */
196
    function php_binary(): string
197
    {
198
        return (new PhpExecutableFinder)->find(false) ?: 'php';
199
    }
200
}
201

202
if (! \function_exists('Orchestra\Sidekick\windows_os')) {
203
    /**
204
     * Determine whether the current environment is Windows-based.
205
     *
206
     * @api
207
     *
208
     * @codeCoverageIgnore
209
     */
210
    function windows_os(): bool
211
    {
212
        return PHP_OS_FAMILY === 'Windows';
213
    }
214
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc