-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathget_change_time.php
41 lines (33 loc) · 955 Bytes
/
get_change_time.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
declare(strict_types=1);
namespace Psl\Filesystem;
use Psl;
use Psl\Str;
use function filectime;
/**
* Get the last time the inode of $filename
* was changed ( e.g: permission change, ownership change .. etc ).
*
* @throws Psl\Exception\InvariantViolationException If $filename does not exist.
* @throws Exception\RuntimeException In case of an error.
*/
function get_change_time(string $filename): int
{
Psl\invariant(exists($filename), '$filename does not exists.');
[$result, $message] = Psl\Internal\box(
/**
* @return false|int
*/
static fn() => filectime($filename)
);
// @codeCoverageIgnoreStart
if (false === $result) {
throw new Exception\RuntimeException(Str\format(
'Failed to retrieve the change time of "%s": %s',
$filename,
$message ?? 'internal error'
));
}
// @codeCoverageIgnoreEnd
return $result;
}