44
55class Driver {
66 protected string $ channel ;
7+ /**
8+ * @var array<int, string>
9+ */
710 protected array $ filenames = [];
11+ /**
12+ * @var array<int, Log>
13+ */
814 protected array $ logs = [];
15+ /**
16+ * @var array<int, LogRecord>
17+ */
918 protected array $ records ;
1019
1120 public function __construct (string $ channel ) {
@@ -14,26 +23,36 @@ public function __construct(string $channel) {
1423 $ this ->createLogs ();
1524 }
1625
17- protected function generateFilenames () {
26+ protected function generateFilenames (): void {
1827 $ this ->filenames = [];
1928 }
2029
21- protected function createLogs () {
30+ protected function createLogs (): void {
2231 $ this ->logs = array_map (fn ($ filename ) => new Log ($ filename ), $ this ->filenames );
2332 }
2433
2534 public function getLaravelChannel (): string {
2635 return $ this ->channel ;
2736 }
2837
38+ /**
39+ * @return array<string>
40+ */
2941 public function getFilenames (): array {
3042 return $ this ->filenames ;
3143 }
3244
45+ /**
46+ * @return array<Log>
47+ */
3348 public function getLogs (): array {
3449 return $ this ->logs ;
3550 }
3651
52+ /**
53+ * @param array<string, int|string> $filter
54+ * @return array<LogRecord>
55+ */
3756 public function getRecords (array $ filter = []): array {
3857 // check if we have generated it before
3958 if (!isset ($ this ->records ) || empty ($ this ->records )) {
@@ -43,7 +62,11 @@ public function getRecords(array $filter = []): array {
4362 return $ this ->getFilteredRecords ($ filter );
4463 }
4564
46- public function getFilteredRecords (array $ filter ): array {
65+ /**
66+ * @param array<string, int|string> $filter
67+ * @return array<LogRecord>
68+ */
69+ protected function getFilteredRecords (array $ filter ): array {
4770 $ records = $ this ->records ;
4871 if (isset ($ filter ['level ' ])) {
4972 // filter all that have this level
@@ -55,12 +78,15 @@ public function getFilteredRecords(array $filter): array {
5578 }
5679 if (isset ($ filter ['count ' ]) && count ($ records ) > $ filter ['count ' ]) {
5780 // only return the last $count
58- $ records = array_slice ($ records , -$ filter ['count ' ]);
81+ $ records = array_slice ($ records , -(( int ) $ filter ['count ' ]) );
5982 }
6083 return $ records ;
6184 }
6285
63- protected function accumulateRecords (array $ filter = []) {
86+ /**
87+ * @param array<string, int|string> $filter
88+ */
89+ protected function accumulateRecords (array $ filter = []): void {
6490 $ this ->records = [];
6591 foreach ($ this ->logs as $ log ) {
6692 // get all the records from this logfile and merge them into the others
@@ -85,7 +111,7 @@ protected function accumulateRecords(array $filter = []) {
85111 $ this ->sortRecords ();
86112 }
87113
88- protected function sortRecords () {
89- usort ($ this ->records , fn ($ a , $ b ) => ($ a ['datetime ' ]->format ('U ' ) > $ b ['datetime ' ]->format ('U ' )));
114+ protected function sortRecords (): void {
115+ usort ($ this ->records , fn ($ a , $ b ): int => ( int ) ($ a ['datetime ' ]->format ('U ' ) > $ b ['datetime ' ]->format ('U ' )));
90116 }
91117}
0 commit comments