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

tempestphp / tempest-framework / 14729611330

29 Apr 2025 11:00AM UTC coverage: 80.654%. First build
14729611330

Pull #1150

github

web-flow
Merge 7c1d15bb8 into 76d70c153
Pull Request #1150: refactor(filesystem): move from package to functions

155 of 202 new or added lines in 10 files covered. (76.73%)

12945 of 16050 relevant lines covered (80.65%)

101.87 hits per line

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

92.86
/src/Tempest/Support/src/functions.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Support {
6
    use Closure;
7
    use Stringable;
8
    use Tempest\Support\Arr\ImmutableArray;
9
    use Tempest\Support\Path\Path;
10
    use Tempest\Support\Str\ImmutableString;
11

12
    /**
13
     * Creates an instance of {@see \Tempest\Support\Str\ImmutableString} using the given `$string`.
14
     */
15
    function str(Stringable|int|string|null $string = ''): ImmutableString
16
    {
17
        return new ImmutableString($string);
1,063✔
18
    }
19

20
    /**
21
     * Creates an instance of {@see \Tempest\Support\Arr\ImmutableCollection} using the given `$input`. If `$input` is not an array, it will be wrapped in one.
22
     */
23
    function arr(mixed $input = []): ImmutableArray
24
    {
25
        return new ImmutableArray($input);
991✔
26
    }
27

28
    /**
29
     * Normalizes the given path without checking it against the filesystem.
30
     */
31
    function path(Stringable|string ...$parts): Path
32
    {
33
        return new Path(...$parts);
229✔
34
    }
35

36
    /**
37
     * Executes the callback with the given `$value` and returns the same `$value`.
38
     *
39
     * @template T
40
     *
41
     * @param T $value
42
     * @param (Closure(T): void) $callback
43
     *
44
     * @return T
45
     */
46
    function tap(mixed $value, Closure $callback): mixed
47
    {
48
        $callback($value);
3✔
49

50
        return $value;
3✔
51
    }
52

53
    /**
54
     * Returns a tuple containing the result of the `$callback` as the first element and the error message as the second element if there was an error.
55
     *
56
     * @template T
57
     *
58
     * @param (Closure(): T) $callback
59
     *
60
     * @return array{0: T, 1: ?string}
61
     */
62
    function box(Closure $callback): array
63
    {
64
        $lastMessage = null;
68✔
65

66
        set_error_handler(static function (int $_type, string $message) use (&$lastMessage): void { // @phpstan-ignore argument.type
68✔
67
            $lastMessage = $message;
3✔
68
        });
68✔
69

70
        if (null !== $lastMessage && Str\contains($lastMessage, '): ')) {
68✔
NEW
71
            $lastMessage = Str\after_first(Str\to_lower_case($lastMessage), '): ');
×
72
        }
73

74
        try {
75
            $value = $callback();
68✔
76

77
            return [$value, $lastMessage];
68✔
78
        } finally {
79
            restore_error_handler();
68✔
80
        }
81
    }
82
}
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