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

orchestral / sidekick / 13629470765

03 Mar 2025 11:08AM UTC coverage: 85.294%. Remained the same
13629470765

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
/**
11
 * Run callback only once.
12
 *
13
 * @api
14
 *
15
 * @param  mixed  $callback
16
 * @return \Closure():mixed
17
 */
18
function once($callback): Closure
19
{
20
    $response = new UndefinedValue;
5✔
21

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

27
        return $response;
5✔
28
    };
5✔
29
}
30

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

48
    return $basePath.implode('', $paths);
1✔
49
}
50

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

67
    return false;
×
68
}
69

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

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

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

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

124
    return version_compare($laravel, $version, $operator);
125
}
126

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

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

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

165
    return version_compare($phpunit, $version, $operator);
166
}
167

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

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