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

orchestral / sidekick / 13858668691

14 Mar 2025 02:23PM UTC coverage: 94.118%. Remained the same
13858668691

Pull #11

github

web-flow
Merge 04075bb25 into 6eed7eced
Pull Request #11: Use `function_exists()` before registering function.

17 of 19 new or added lines in 1 file covered. (89.47%)

32 of 34 relevant lines covered (94.12%)

1.88 hits per line

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

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

3
namespace Orchestra\Sidekick;
4

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

10
if (! \function_exists('Orchestra\Sidekick\once')) {
11
    /**
12
     * Run callback only once.
13
     *
14
     * @api
15
     *
16
     * @param  mixed  $callback
17
     * @return \Closure():mixed
18
     */
19
    function once($callback): Closure
20
    {
21
        $response = new UndefinedValue;
5✔
22

23
        return function () use ($callback, &$response) {
5✔
24
            if ($response instanceof UndefinedValue) {
5✔
25
                $response = value($callback) ?? null;
5✔
26
            }
27

28
            return $response;
5✔
29
        };
5✔
30
    }
31
}
32

33
if (! \function_exists('Orchestra\Sidekick\join_paths')) {
34
    /**
35
     * Join the given paths together.
36
     *
37
     * @param  string|null  $basePath
38
     * @param  string  ...$paths
39
     * @return string
40
     */
41
    function join_paths(?string $basePath, string ...$paths): string
42
    {
43
        foreach ($paths as $index => $path) {
1✔
44
            if (empty($path) && $path !== '0') {
1✔
45
                unset($paths[$index]);
1✔
46
            } else {
47
                $paths[$index] = DIRECTORY_SEPARATOR.ltrim($path, DIRECTORY_SEPARATOR);
1✔
48
            }
49
        }
50

51
        return $basePath.implode('', $paths);
1✔
52
    }
53
}
54

55
if (! \function_exists('Orchestra\Sidekick\is_symlink')) {
56
    /**
57
     * Determine if path is symlink for both Unix and Windows environment.
58
     *
59
     * @api
60
     *
61
     * @param  string  $path
62
     * @return bool
63
     */
64
    function is_symlink(string $path): bool
65
    {
66
        if (windows_os() && is_dir($path) && readlink($path) !== $path) {
1✔
NEW
67
            return true;
×
68
        } elseif (is_link($path)) {
1✔
NEW
69
            return true;
×
70
        }
71

72
        return false;
1✔
73
    }
74
}
75

76
if (! \function_exists('Orchestra\Sidekick\transform_relative_path')) {
77
    /**
78
     * Transform relative path.
79
     *
80
     * @api
81
     *
82
     * @param  string  $path
83
     * @param  string  $workingPath
84
     * @return string
85
     */
86
    function transform_relative_path(string $path, string $workingPath): string
87
    {
88
        return str_starts_with($path, './')
1✔
89
            ? rtrim($workingPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.mb_substr($path, 2)
1✔
90
            : $path;
1✔
91
    }
92
}
93

94
if (! \function_exists('Orchestra\Sidekick\laravel_version_compare')) {
95
    /**
96
     * Laravel version compare.
97
     *
98
     * @api
99
     *
100
     * @template TOperator of string|null
101
     *
102
     * @param  string  $version
103
     * @param  string|null  $operator
104
     * @return int|bool
105
     *
106
     * @phpstan-param  TOperator  $operator
107
     *
108
     * @phpstan-return (TOperator is null ? int : bool)
109
     *
110
     * @codeCoverageIgnore
111
     */
112
    function laravel_version_compare(string $version, ?string $operator = null): int|bool
113
    {
114
        if (! class_exists(Application::class)) {
115
            throw new RuntimeException('Unable to verify Laravel Framework version');
116
        }
117

118
        /**
119
         * @var string $laravel
120
         */
121
        $laravel = transform(
122
            Application::VERSION,
123
            fn (string $version) => match ($version) {
124
                '13.x-dev' => '13.0.0',
125
                default => $version,
126
            }
127
        );
128

129
        if (\is_null($operator)) {
130
            return version_compare($laravel, $version);
131
        }
132

133
        return version_compare($laravel, $version, $operator);
134
    }
135
}
136

137
if (! \function_exists('Orchestra\Sidekick\phpunit_version_compare')) {
138
    /**
139
     * PHPUnit version compare.
140
     *
141
     * @api
142
     *
143
     * @template TOperator of string|null
144
     *
145
     * @param  string  $version
146
     * @param  string|null  $operator
147
     * @return int|bool
148
     *
149
     * @throws \RuntimeException
150
     *
151
     * @phpstan-param  TOperator  $operator
152
     *
153
     * @phpstan-return (TOperator is null ? int : bool)
154
     *
155
     * @codeCoverageIgnore
156
     */
157
    function phpunit_version_compare(string $version, ?string $operator = null): int|bool
158
    {
159
        if (! class_exists(Version::class)) {
160
            throw new RuntimeException('Unable to verify PHPUnit version');
161
        }
162

163
        /** @var string $phpunit */
164
        $phpunit = transform(
165
            Version::id(),
166
            fn (string $version) => match (true) {
167
                str_starts_with($version, '12.1-') => '12.1.0',
168
                default => $version,
169
            }
170
        );
171

172
        if (\is_null($operator)) {
173
            return version_compare($phpunit, $version);
174
        }
175

176
        return version_compare($phpunit, $version, $operator);
177
    }
178
}
179

180
if (! \function_exists('Orchestra\Sidekick\php_binary')) {
181
    /**
182
     * Determine the PHP Binary.
183
     *
184
     * @api
185
     *
186
     * @return string
187
     *
188
     * @codeCoverageIgnore
189
     */
190
    function php_binary(): string
191
    {
192
        return (new PhpExecutableFinder)->find(false) ?: 'php';
193
    }
194
}
195

196
if (! \function_exists('Orchestra\Sidekick\windows_os')) {
197
    /**
198
     * Determine whether the current environment is Windows based.
199
     *
200
     * @api
201
     *
202
     * @return bool
203
     *
204
     * @codeCoverageIgnore
205
     */
206
    function windows_os(): bool
207
    {
208
        return PHP_OS_FAMILY === 'Windows';
209
    }
210
}
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

© 2026 Coveralls, Inc