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

tempestphp / tempest-framework / 11904119374

18 Nov 2024 12:08PM UTC coverage: 81.946% (-0.1%) from 82.07%
11904119374

push

github

web-flow
chore(core): fixes to path helper (#744)

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

27 existing lines in 3 files now uncovered.

7848 of 9577 relevant lines covered (81.95%)

52.03 hits per line

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

73.33
/src/Tempest/Support/src/PathHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Support;
6

7
use Stringable;
8

9
final readonly class PathHelper implements Stringable
10
{
11
    private string $path;
12

13
    public function __construct(Stringable|string ...$paths)
409✔
14
    {
15
        $paths = array_map(
409✔
16
            fn (self|string $path) => (string)$path,
409✔
17
            $paths,
409✔
18
        );
409✔
19

20
        // Split paths items on forward and backward slashes
21
        $parts = array_reduce($paths, fn (array $carry, string $part) => [...$carry, ...explode('/', $part)], []);
409✔
22
        $parts = array_reduce($parts, fn (array $carry, string $part) => [...$carry, ...explode('\\', $part)], []);
409✔
23

24
        // Trim forward and backward slashes
25
        $parts = array_map(fn (string $part) => trim($part, '/\\'), $parts);
409✔
26
        $parts = array_filter($parts);
409✔
27

28
        // Glue parts together
29
        $path = implode('/', $parts);
409✔
30

31
        // Add / if first entry starts with forward- or backward slash
32
        $firstEntry = $paths[0];
409✔
33

34
        if (str_starts_with($firstEntry, '/') || str_starts_with($firstEntry, '\\')) {
409✔
35
            $path = '/' . $path;
403✔
36
        }
37

38
        // Add / if last entry ends with forward- or backward slash
39
        $lastEntry = $paths[count($paths) - 1];
409✔
40

41
        if ((count($paths) > 1 || strlen($lastEntry) > 1) && (str_ends_with($lastEntry, '/') || str_ends_with($lastEntry, '\\'))) {
409✔
42
            $path .= '/';
390✔
43
        }
44

45
        $this->path = $path;
409✔
46
    }
47

48
    public function toString(): string
408✔
49
    {
50
        return $this->path;
408✔
51
    }
52

53
    public function info(int $flags = PATHINFO_ALL): string|array
2✔
54
    {
55
        return pathinfo($this->path, $flags);
2✔
56
    }
57

58
    public function path(): string
2✔
59
    {
60
        return $this->path;
2✔
61
    }
62

63
    public function dirname(): string
2✔
64
    {
65
        return $this->info(PATHINFO_DIRNAME);
2✔
66
    }
67

UNCOV
68
    public function filename(): string
×
69
    {
UNCOV
70
        return $this->info(PATHINFO_FILENAME);
×
71
    }
72

UNCOV
73
    public function basename(): string
×
74
    {
UNCOV
75
        return $this->info(PATHINFO_BASENAME);
×
76
    }
77

UNCOV
78
    public function extension(): string
×
79
    {
UNCOV
80
        return $this->info(PATHINFO_EXTENSION);
×
81
    }
82

83
    public function glob(string $pattern): ArrayHelper
70✔
84
    {
85
        return arr(
70✔
86
            glob((new self($this->path, $pattern))->toString()),
70✔
87
        );
70✔
88
    }
89

90
    public function isDirectory(): bool
78✔
91
    {
92
        return is_dir($this->path);
78✔
93
    }
94

UNCOV
95
    public function isFile(): bool
×
96
    {
UNCOV
97
        return is_file($this->path);
×
98
    }
99

UNCOV
100
    public function exists(): bool
×
101
    {
UNCOV
102
        return file_exists($this->path);
×
103
    }
104

UNCOV
105
    public function equals(Stringable $other): bool
×
106
    {
UNCOV
107
        return $this->path === (string)$other;
×
108
    }
109

110
    public function __toString(): string
381✔
111
    {
112
        return $this->path;
381✔
113
    }
114
}
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