Skip to content

Commit 3b41377

Browse files
authored
Merge pull request #655 from nextcloud/fix/support-php-8.1
Respect function signatures from PHP 8.1
2 parents d782372 + 9d4bdb0 commit 3b41377

4 files changed

Lines changed: 41 additions & 40 deletions

File tree

.github/workflows/phpunit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
# do not stop on another job's failure
1919
fail-fast: false
2020
matrix:
21-
php-versions: ['7.4', '8.0']
21+
php-versions: ['7.4', '8.0', '8.1']
2222
databases: ['sqlite']
2323
server-versions: ['master']
2424

composer.lock

Lines changed: 20 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Log/LogIterator.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,16 @@ public function __construct($handle, $dateFormat, $timezone) {
6666
$this->next();
6767
}
6868

69-
public function rewind() {
69+
public function rewind(): void {
7070
fseek($this->handle, 0, SEEK_END);
7171
$this->position = ftell($this->handle) - self::CHUNK_SIZE;
7272
$this->currentKey = 0;
7373
}
7474

75+
/**
76+
* @return mixed
77+
*/
78+
#[\ReturnTypeWillChange]
7579
public function current() {
7680
$entry = json_decode($this->lastLine, true);
7781
if ($this->dateFormat !== \DateTime::ATOM) {
@@ -85,11 +89,11 @@ public function current() {
8589
return $entry;
8690
}
8791

88-
public function key() {
92+
public function key(): int {
8993
return $this->currentKey;
9094
}
9195

92-
public function next() {
96+
public function next(): void {
9397
$this->currentLine = '';
9498

9599
// Loop through each character of the file looking for new lines
@@ -119,7 +123,7 @@ public function next() {
119123
}
120124
}
121125

122-
public function valid() {
126+
public function valid(): bool {
123127
if (!is_resource($this->handle)) {
124128
return false;
125129
}

lib/Log/SearchFilter.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,40 +32,37 @@ class SearchFilter extends \FilterIterator {
3232
*/
3333
private $levels;
3434

35-
/**
36-
* @param \Iterator $iterator
37-
* @param string $query
38-
*/
39-
public function __construct(\Iterator $iterator, $query) {
35+
public function __construct(\Iterator $iterator, string $query) {
4036
parent::__construct($iterator);
4137
$this->rewind();
4238
$this->query = strtolower($query);
4339
$this->levels = ['Debug', 'Info', 'Warning', 'Error', 'Fatal'];
4440
}
4541

46-
private function formatLevel($level) {
42+
private function formatLevel(int $level): string {
4743
return isset($this->levels[$level]) ? $this->levels[$level] : 'Unknown';
4844
}
4945

50-
public function accept() {
46+
public function accept(): bool {
5147
if (!$this->query) {
5248
return true;
5349
}
5450
$value = $this->current();
55-
return $this->inMessage($value['message'], $this->query)
56-
|| stripos($value['app'], $this->query) !== false
57-
|| stripos($value['reqId'], $this->query) !== false
58-
|| stripos($value['user'], $this->query) !== false
59-
|| stripos($value['url'], $this->query) !== false
60-
|| stripos($this->formatLevel($value['level']), $this->query) !== false;
51+
return $this->inMessage($value['message'] ?? '', $this->query)
52+
|| stripos($value['app'] ?? '', $this->query) !== false
53+
|| stripos($value['reqId'] ?? '', $this->query) !== false
54+
|| stripos($value['user'] ?? '', $this->query) !== false
55+
|| stripos($value['url'] ?? '', $this->query) !== false
56+
|| stripos($this->formatLevel($value['level'] ?? -1), $this->query) !== false;
6157
}
6258

63-
private function inMessage($message, $query) {
59+
private function inMessage($message, string $query): bool {
6460
if (is_string($message)) {
6561
return stripos($message, $query) !== false;
6662
} elseif (isset($message['Exception'])) {
6763
return stripos($message['Exception'], $query) !== false
68-
|| stripos($message['Message'], $query) !== false;
64+
|| stripos($message['Message'] ?? '', $query) !== false;
6965
}
66+
return false;
7067
}
7168
}

0 commit comments

Comments
 (0)