Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
IOState
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createFromStat
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\Core\IO;
6
7use DateTimeImmutable;
8use PeServer\Core\Utc;
9
10/**
11 * `stat` でもらえる情報。
12 */
13readonly class IOState
14{
15    /**
16     * 生成。
17     *
18     * @param int $deviceNumber デバイス番号
19     * @param int $inode inode 番号
20     * @param int $mode inode プロテクトモード
21     * @param int $linkCount リンク数
22     * @param int $userId 所有者のユーザー ID
23     * @param int $groupId 所有者のグループ ID
24     * @param int $deviceType inode デバイス の場合、デバイスの種類
25     * @param int $size バイト単位のサイズ
26     * @param DateTimeImmutable $accessDateTime 最終アクセス時間
27     * @param DateTimeImmutable $updatedDateTime 最終修正時間
28     * @param DateTimeImmutable $createdDateTime 最終 inode 変更時間
29     * @param int $blockSize ファイル IO のブロックサイズ
30     * @param int $blockCount 512 バイトのブロックの確保数
31     */
32    public function __construct(
33        public int $deviceNumber,
34        public int $inode,
35        public int $mode,
36        public int $linkCount,
37        public int $userId,
38        public int $groupId,
39        public int $deviceType,
40        public int $size,
41        public DateTimeImmutable $accessDateTime,
42        public DateTimeImmutable $updatedDateTime,
43        public DateTimeImmutable $createdDateTime,
44        public int $blockSize,
45        public int $blockCount
46    ) {
47    }
48
49    #region function
50
51    /**
52     * `stat` 的なものから作成。
53     *
54     * @param array<string|int,int> $values
55     * @return self
56     */
57    public static function createFromStat(array $values): self
58    {
59        return new IOState(
60            $values['dev'],
61            $values['ino'],
62            $values['mode'],
63            $values['nlink'], //cspell:disable-line
64            $values['uid'],
65            $values['gid'],
66            $values['rdev'], //cspell:disable-line
67            $values['size'],
68            Utc::toDateTimeFromUnixTime($values['atime']),
69            Utc::toDateTimeFromUnixTime($values['mtime']),
70            Utc::toDateTimeFromUnixTime($values['ctime']),
71            $values['blksize'], //cspell:disable-line
72            $values['blocks']
73        );
74    }
75
76    #endregion
77}