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

krakjoe / phathom / 26996743271

05 Jun 2026 05:11AM UTC coverage: 98.199% (-1.8%) from 100.0%
26996743271

push

github

krakjoe
drop unused member

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

29 existing lines in 2 files now uncovered.

1581 of 1610 relevant lines covered (98.2%)

22.79 hits per line

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

77.78
/src/phathom/File.php
1
<?php
2
namespace pharos\phathom 
3
{
4
    use \pharos\phathom\Exception\IO as IOException;
5

6
    final class File implements Interface\Buffer
7
    {
8
        const int REGULAR   = 1;
9
        const int DIRECTORY = 2;
10

11
        public private(set) string       $path;
12
        public private(set) int          $kind;
13
        private             string|false $buffer = false;
14
        private             int|false    $limit  = false;
15
        
16
        public string $contents {
17
            get {
UNCOV
18
                if ($this->buffer !== false) {
×
UNCOV
19
                    return $this->buffer;
×
UNCOV
20
                }
×
21

22
                // @codeCoverageIgnoreStart
23
                $this->buffer = @\file_get_contents($this->path);
24

25
                if ($this->buffer === false) {
26
                    throw new IOException(
27
                        "{$this->path} cannot be read");
28
                }
29
                // @codeCoverageIgnoreEnd
30

UNCOV
31
                return $this->buffer;
×
32
            }
33
        }
34

35
        public int $length {
36
            get {
UNCOV
37
                if ($this->limit !== false) {
×
UNCOV
38
                    return $this->limit;
×
UNCOV
39
                }
×
40

UNCOV
41
                if ($this->buffer === false) {
×
UNCOV
42
                    $this->limit =
×
UNCOV
43
                        \strlen(
×
UNCOV
44
                            $this->contents);
×
UNCOV
45
                    return $this->limit;
×
UNCOV
46
                }
×
47

UNCOV
48
                $this->limit =
×
UNCOV
49
                    \strlen($this->buffer);
×
UNCOV
50
                return $this->limit;
×
51
            }
52
        }
53

54
        public function __construct(string $path) {
113✔
55
            $realpath = \realpath($path);
113✔
56

57
            if ($realpath === false) {
113✔
58
                throw new IOException(
20✔
59
                    "{$path} cannot be found on the local filesystem");
20✔
60
            }
61

62
            $this->path = $realpath;
112✔
63

64
            if (\is_dir($this->path)) {
112✔
65
                $this->kind =
33✔
66
                    FILE::DIRECTORY;
33✔
67
            } else {
68
                $this->kind =
112✔
69
                    FILE::REGULAR;
112✔
70
            }
71
        }
72

73
        public function realpath(string $path) : string|false {
43✔
74
            return \realpath(\sprintf(
43✔
75
                "%s%s%s",
43✔
76
                $this->kind == FILE::DIRECTORY ?
43✔
77
                    $this->path : \dirname($this->path),
43✔
78
                \DIRECTORY_SEPARATOR,
43✔
79
                $path
43✔
80
            ));
43✔
81
        }
82

83
        public function relative(string $path) : self {
103✔
84
            return new self(\sprintf(
103✔
85
                "%s%s%s",
103✔
86
                $this->kind == FILE::DIRECTORY ?
103✔
87
                    $this->path : \dirname($this->path),
103✔
88
                \DIRECTORY_SEPARATOR,
103✔
89
                $path
103✔
90
            ));
103✔
91
        }
92

93
        public function writable() : bool {
18✔
94
            return \is_writable($this->path);
18✔
95
        }
96

97
        public function put(string $relative, string $contents) : self {
19✔
98
            if ($this->kind != FILE::DIRECTORY) {
19✔
99
                throw new IOException(
1✔
100
                    "{$this->path} is not a directory");
1✔
101
            }
102

103
            if (!$this->writable()) {
18✔
104
                // @codeCoverageIgnoreStart
105
                throw new IOException(
106
                    "{$this->path} is not writable");
107
                // @codeCoverageIgnoreEnd
108
            }
109

110
            $path = \sprintf(
18✔
111
                "%s%s%s",
18✔
112
                $this->path,
18✔
113
                \DIRECTORY_SEPARATOR,
18✔
114
                $relative);
18✔
115

116
            if (\file_put_contents($path, $contents) === false) {
18✔
117
                // @codeCoverageIgnoreStart
118
                throw new IOException(
119
                    "cannot write {$path}, write failed");
120
                // @codeCoverageIgnoreEnd
121
            }
122

123
            return new self($path);
18✔
124
        }
125

126
        public function __serialize() : array {
3✔
127
            return [
3✔
128
                'path' => $this->path,
3✔
129
                'kind' => $this->kind
3✔
130
            ];
3✔
131
        }
132

133
        public function __unserialize(array $array) : void {
3✔
134
            foreach ($array as $member => $value) {
3✔
135
                $this->$member = $value;
3✔
136
            }
137
        }
138

139
        public function __debugInfo() : array {
1✔
140
            return [
1✔
141
                'path' => $this->path,
1✔
142
                'kind' => $this->kind,
1✔
143
            ];
1✔
144
        }
145

146
        public function __toString() : string {
58✔
147
            return $this->path;
58✔
148
        }
149
    }
150
}
151
?>
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