Skip to content

Commit fa84fc2

Browse files
committed
Add missing typehints and docblocks for arrays
1 parent 939b6c9 commit fa84fc2

File tree

9 files changed

+63
-19
lines changed

9 files changed

+63
-19
lines changed

src/Commands/ShowLog.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class ShowLog extends Command
4646

4747
protected int $terminalWidth;
4848

49+
/**
50+
* @var array<string, int|string|null>
51+
*/
4952
protected array $filter = [
5053
'count' => null,
5154
'level' => null,
@@ -146,7 +149,7 @@ public function handle()
146149
return Command::SUCCESS;
147150
}
148151

149-
protected function printSeparator() {
152+
protected function printSeparator(): void {
150153
$this->newLine();
151154
$this->line('<bg=gray>'.str_pad('', $this->terminalWidth, ' ').'</>');
152155
$this->newLine();

src/Helpers/CommandHelper.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
class CommandHelper extends Command {
1010
/**
1111
* Print a section component
12+
* @param array<string> $data
1213
*/
1314
public static function displaySection(Command $cmd, string $section, array $data): void {
1415
$cmd->newLine();

src/Models/Driver.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@
44

55
class 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
}

src/Models/DriverMultiple.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@
77
use Devdot\LogArtisan\Models\Drivers\Stack;
88

99
class DriverMultiple extends Driver {
10+
/**
11+
* @var array<int, Driver>
12+
*/
1013
protected array $drivers;
1114

15+
/**
16+
* @param array<int, string> $channels
17+
*/
1218
public function __construct(string $channel, array $channels = []) {
1319
$this->channel = $channel;
1420
$this->createDrivers($channels);
1521
parent::__construct($channel);
1622
}
1723

18-
protected function createDrivers(array $channels) {
24+
/**
25+
* @param array<int, string> $channels
26+
*/
27+
protected function createDrivers(array $channels): void {
1928
foreach($channels as $channel) {
2029
// create a new driver for each subchannel
2130
$driver = config('logging.channels.'.$channel.'.driver');
@@ -57,13 +66,12 @@ public function getLogs(): array {
5766
return $this->logs;
5867
}
5968

60-
protected function accumulateRecords(array $filter = []) {
69+
protected function accumulateRecords(array $filter = []): void {
6170
$this->records = [];
6271
foreach($this->drivers as $driver) {
6372
$this->records = array_merge($this->records, $driver->getRecords($filter));
6473
}
6574
// make sure to sort after merging
6675
$this->sortRecords();
67-
return $this->records;
6876
}
6977
}

src/Models/Drivers/Daily.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Devdot\LogArtisan\Models\Driver;
66

77
class Daily extends Driver {
8-
protected function generateFilenames() {
8+
protected function generateFilenames(): void {
99
// get the config data
1010
$filename = config('logging.channels.'.$this->channel.'.path');
1111
$days = config('logging.channels.'.$this->channel.'.days');

src/Models/Drivers/Single.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Devdot\LogArtisan\Models\Driver;
66

77
class Single extends Driver {
8-
protected function generateFilenames() {
8+
protected function generateFilenames(): void {
99
// get the file from the config
1010
$filename = config('logging.channels.'.$this->channel.'.path');
1111
// check if the file exists

src/Models/Drivers/Stack.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
use Devdot\LogArtisan\Models\DriverMultiple;
66

77
class Stack extends DriverMultiple {
8-
protected function createDrivers(array $channels) {
8+
/**
9+
* @param array<int, string> $channels
10+
*/
11+
protected function createDrivers(array $channels): void {
912
if(empty($channels)) {
1013
$channels = config('logging.channels.'.$this->channel.'.channels') ?? [];
1114
}

src/Models/Log.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct(string $filename = '') {
2020
}
2121
}
2222

23-
public function setFile(string $filename) {
23+
public function setFile(string $filename): bool {
2424
// set in object
2525
$this->filename = $filename;
2626
// now attempt to set in parser
@@ -33,11 +33,14 @@ public function setFile(string $filename) {
3333
return true;
3434
}
3535

36-
public function getFilename() {
36+
public function getFilename(): string {
3737
return $this->filename;
3838
}
3939

40-
public function getRecords() {
40+
/**
41+
* @return array<int, \Devdot\Monolog\LogRecord>
42+
*/
43+
public function getRecords(): array {
4144
// simply access the parser
4245
return $this->parser->get();
4346
}

src/Models/LogRecord.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
class LogRecord extends \Devdot\Monolog\LogRecord {
66
private Driver $driver;
77

8-
public function getDriver() {
8+
public function getDriver(): Driver {
99
return $this->driver;
1010
}
1111

12-
public function setDriver(Driver $driver) {
12+
public function setDriver(Driver $driver): void {
1313
$this->driver = $driver;
1414
}
1515
}

0 commit comments

Comments
 (0)