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

tempestphp / tempest-framework / 14130274841

28 Mar 2025 01:41PM UTC coverage: 80.713%. First build
14130274841

Pull #1080

github

web-flow
Merge d0d9f19bf into fb8977b7f
Pull Request #1080: refactor(support): improve path utilities

147 of 159 new or added lines in 17 files covered. (92.45%)

10939 of 13553 relevant lines covered (80.71%)

100.33 hits per line

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

66.67
/src/Tempest/Support/src/Path/Path.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Support\Path;
6

7
use Stringable;
8
use Tempest\Support\Arr\ImmutableArray;
9
use Tempest\Support\Str\ManipulatesString;
10
use Tempest\Support\Str\StringInterface;
11

12
/**
13
 * Represents a file system path and provides access to convenience methods.
14
 */
15
final class Path implements StringInterface
16
{
17
    use ManipulatesString;
18

19
    public function __construct(Stringable|string ...$paths)
196✔
20
    {
21
        $this->value = namespace\normalize(...$paths);
196✔
22
    }
23

24
    protected function createOrModify(Stringable|string $string): static
180✔
25
    {
26
        return new static($string);
180✔
27
    }
28

29
    /**
30
     * Returns information about the path. See {@see pathinfo()}.
31
     */
32
    public function info(int $flags = PATHINFO_ALL): string|array
123✔
33
    {
34
        return pathinfo($this->value, $flags);
123✔
35
    }
36

37
    /**
38
     * Returns the entire path.
39
     */
NEW
40
    public function path(): static
×
41
    {
NEW
42
        return $this->createOrModify($this->value);
×
43
    }
44

45
    /**
46
     * Keeps only the directory name.
47
     */
48
    public function dirname(): static
122✔
49
    {
50
        return $this->createOrModify($this->info(PATHINFO_DIRNAME));
122✔
51
    }
52

53
    /**
54
     * Keeps only the filename.
55
     */
NEW
56
    public function filename(): static
×
57
    {
NEW
58
        return $this->createOrModify($this->info(PATHINFO_FILENAME));
×
59
    }
60

61
    /**
62
     * Keeps only the basename.
63
     */
NEW
64
    public function basename(string $suffix = ''): static
×
65
    {
NEW
66
        return $this->createOrModify($this->info(PATHINFO_BASENAME))->stripEnd($suffix);
×
67
    }
68

69
    /**
70
     * Keeps only the extension.
71
     */
72
    public function extension(): static
1✔
73
    {
74
        return $this->createOrModify($this->info(PATHINFO_EXTENSION));
1✔
75
    }
76

77
    /**
78
     * Appends a glob and returns an immutable array with the resulting paths.
79
     */
80
    public function glob(string $pattern): ImmutableArray
93✔
81
    {
82
        return new ImmutableArray(glob(namespace\normalize($this->value, $pattern)));
93✔
83
    }
84

85
    /**
86
     * Determines whether the path is a directory.
87
     */
88
    public function isDirectory(): bool
104✔
89
    {
90
        return is_dir($this->value);
104✔
91
    }
92

93
    /**
94
     * Determines whether the path is a file.
95
     */
NEW
96
    public function isFile(): bool
×
97
    {
NEW
98
        return is_file($this->value);
×
99
    }
100

101
    /**
102
     * Determines whether the path exists on the local filesystem.
103
     */
104
    public function exists(): bool
1✔
105
    {
106
        return file_exists($this->value);
1✔
107
    }
108
}
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