Passed
Push — master ( 514dc4...3085cf )
by Roeland
10:26 queued 13s
created

ScopedPsrLogger::error()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright 2020 Christoph Wurst <[email protected]>
7
 *
8
 * @author 2020 Christoph Wurst <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 */
25
26
namespace OC\AppFramework;
27
28
use Psr\Log\LoggerInterface;
29
use function array_merge;
30
31
class ScopedPsrLogger implements LoggerInterface {
32
33
	/** @var LoggerInterface */
34
	private $inner;
35
36
	/** @var string */
37
	private $appId;
38
39
	public function __construct(LoggerInterface $inner,
40
								string $appId) {
41
		$this->inner = $inner;
42
		$this->appId = $appId;
43
	}
44
45
	public function emergency($message, array $context = []) {
46
		$this->inner->emergency(
47
			$message,
48
			array_merge(
49
				[
50
					'app' => $this->appId,
51
				],
52
				$context
53
			)
54
		);
55
	}
56
57
	public function alert($message, array $context = []) {
58
		$this->inner->alert(
59
			$message,
60
			array_merge(
61
				[
62
					'app' => $this->appId,
63
				],
64
				$context
65
			)
66
		);
67
	}
68
69
	public function critical($message, array $context = []) {
70
		$this->inner->critical(
71
			$message,
72
			array_merge(
73
				[
74
					'app' => $this->appId,
75
				],
76
				$context
77
			)
78
		);
79
	}
80
81
	public function error($message, array $context = []) {
82
		$this->inner->error(
83
			$message,
84
			array_merge(
85
				[
86
					'app' => $this->appId,
87
				],
88
				$context
89
			)
90
		);
91
	}
92
93
	public function warning($message, array $context = []) {
94
		$this->inner->warning(
95
			$message,
96
			array_merge(
97
				[
98
					'app' => $this->appId,
99
				],
100
				$context
101
			)
102
		);
103
	}
104
105
	public function notice($message, array $context = []) {
106
		$this->inner->notice(
107
			$message,
108
			array_merge(
109
				[
110
					'app' => $this->appId,
111
				],
112
				$context
113
			)
114
		);
115
	}
116
117
	public function info($message, array $context = []) {
118
		$this->inner->info(
119
			$message,
120
			array_merge(
121
				[
122
					'app' => $this->appId,
123
				],
124
				$context
125
			)
126
		);
127
	}
128
129
	public function debug($message, array $context = []) {
130
		$this->inner->debug(
131
			$message,
132
			array_merge(
133
				[
134
					'app' => $this->appId,
135
				],
136
				$context
137
			)
138
		);
139
	}
140
141
	public function log($level, $message, array $context = []) {
142
		$this->inner->log(
143
			$message,
144
			array_merge(
0 ignored issues
show
Bug introduced by
array_merge(array('app' ...this->appId), $context) of type array is incompatible with the type string expected by parameter $message of Psr\Log\LoggerInterface::log(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

144
			/** @scrutinizer ignore-type */ array_merge(
Loading history...
145
				[
146
					'app' => $this->appId,
147
				],
148
				$context
149
			)
150
		);
151
	}
152
}
153