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

orchestral / sidekick / 13629420372

03 Mar 2025 11:06AM UTC coverage: 85.294%. Remained the same
13629420372

push

github

crynobone
wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

0 of 1 new or added line in 1 file covered. (0.0%)

29 of 34 relevant lines covered (85.29%)

1.79 hits per line

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

73.68
/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
use function is_link as unix_is_link;
11

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

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

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

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

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

53
/**
54
 * Determine if path is symlink for both Unix and Windows environment.
55
 *
56
 * @api
57
 *
58
 * @param  string  $path
59
 * @return bool
60
 */
61
function is_link(string $path): bool
62
{
63
    if (windows_os() && is_dir($path) && readlink($path) !== $path) {
×
64
        return true;
×
NEW
65
    } elseif (unix_is_link($path)) {
×
66
        return true;
×
67
    }
68

69
    return false;
×
70
}
71

72
/**
73
 * Transform relative path.
74
 *
75
 * @api
76
 *
77
 * @param  string  $path
78
 * @param  string  $workingPath
79
 * @return string
80
 */
81
function transform_relative_path(string $path, string $workingPath): string
82
{
83
    return str_starts_with($path, './')
1✔
84
        ? rtrim($workingPath, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.mb_substr($path, 2)
1✔
85
        : $path;
1✔
86
}
87

88
/**
89
 * Laravel version compare.
90
 *
91
 * @api
92
 *
93
 * @template TOperator of string|null
94
 *
95
 * @param  string  $version
96
 * @param  string|null  $operator
97
 * @return int|bool
98
 *
99
 * @phpstan-param  TOperator  $operator
100
 *
101
 * @phpstan-return (TOperator is null ? int : bool)
102
 *
103
 * @codeCoverageIgnore
104
 */
105
function laravel_version_compare(string $version, ?string $operator = null): int|bool
106
{
107
    if (! class_exists(Application::class)) {
108
        throw new RuntimeException('Unable to verify Laravel Framework version');
109
    }
110

111
    /**
112
     * @var string $laravel
113
     */
114
    $laravel = transform(
115
        Application::VERSION,
116
        fn (string $version) => match ($version) {
117
            '13.x-dev' => '13.0.0',
118
            default => $version,
119
        }
120
    );
121

122
    if (\is_null($operator)) {
123
        return version_compare($laravel, $version);
124
    }
125

126
    return version_compare($laravel, $version, $operator);
127
}
128

129
/**
130
 * PHPUnit version compare.
131
 *
132
 * @api
133
 *
134
 * @template TOperator of string|null
135
 *
136
 * @param  string  $version
137
 * @param  string|null  $operator
138
 * @return int|bool
139
 *
140
 * @throws \RuntimeException
141
 *
142
 * @phpstan-param  TOperator  $operator
143
 *
144
 * @phpstan-return (TOperator is null ? int : bool)
145
 *
146
 * @codeCoverageIgnore
147
 */
148
function phpunit_version_compare(string $version, ?string $operator = null): int|bool
149
{
150
    if (! class_exists(Version::class)) {
151
        throw new RuntimeException('Unable to verify PHPUnit version');
152
    }
153

154
    /** @var string $phpunit */
155
    $phpunit = transform(
156
        Version::id(),
157
        fn (string $version) => match (true) {
158
            str_starts_with($version, '12.1-') => '12.1.0',
159
            default => $version,
160
        }
161
    );
162

163
    if (\is_null($operator)) {
164
        return version_compare($phpunit, $version);
165
    }
166

167
    return version_compare($phpunit, $version, $operator);
168
}
169

170
/**
171
 * Determine the PHP Binary.
172
 *
173
 * @api
174
 *
175
 * @return string
176
 *
177
 * @codeCoverageIgnore
178
 */
179
function php_binary(): string
180
{
181
    return (new PhpExecutableFinder)->find(false) ?: 'php';
182
}
183

184
/**
185
 * Determine whether the current environment is Windows based.
186
 *
187
 * @api
188
 *
189
 * @return bool
190
 *
191
 * @codeCoverageIgnore
192
 */
193
function windows_os(): bool
194
{
195
    return PHP_OS_FAMILY === 'Windows';
196
}
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