mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 14:50:17 -04:00
refactor(Log): Use new in initializer instead of constructor body
PHP 8.1 allows us to now move the `new` into the initializer, this makes the code a bit nicer (and 3 lines shorter). Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
parent
81b4ced076
commit
2ec68b1eb9
4 changed files with 9 additions and 15 deletions
|
|
@ -41,13 +41,9 @@ class Log implements ILogger, IDataLogger {
|
|||
public function __construct(
|
||||
private IWriter $logger,
|
||||
private SystemConfig $config,
|
||||
private ?Normalizer $normalizer = null,
|
||||
private Normalizer $normalizer = new Normalizer(),
|
||||
private ?IRegistry $crashReporters = null
|
||||
) {
|
||||
// FIXME: php8.1 allows "private Normalizer $normalizer = new Normalizer()," in initializer
|
||||
if ($normalizer === null) {
|
||||
$this->normalizer = new Normalizer();
|
||||
}
|
||||
}
|
||||
|
||||
public function setEventDispatcher(IEventDispatcher $eventDispatcher): void {
|
||||
|
|
|
|||
|
|
@ -735,7 +735,7 @@ class Server extends ServerContainer implements IServerContainer {
|
|||
$logger = $factory->get($logType);
|
||||
$registry = $c->get(\OCP\Support\CrashReport\IRegistry::class);
|
||||
|
||||
return new Log($logger, $this->get(SystemConfig::class), null, $registry);
|
||||
return new Log($logger, $this->get(SystemConfig::class), crashReporters: $registry);
|
||||
});
|
||||
$this->registerAlias(ILogger::class, \OC\Log::class);
|
||||
/** @deprecated 19.0.0 */
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@
|
|||
resolveFromConfigFile="true"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="https://getpsalm.org/schema/config"
|
||||
xsi:schemaLocation="https://getpsalm.org/schema/config"
|
||||
errorBaseline="build/psalm-baseline.xml"
|
||||
xsi:schemaLocation="https://getpsalm.org/schema/config https://getpsalm.org/schema/config"
|
||||
errorBaseline="build/psalm-baseline.xml"
|
||||
findUnusedBaselineEntry="false"
|
||||
findUnusedCode="false"
|
||||
phpVersion="8.1"
|
||||
|
|
|
|||
|
|
@ -17,14 +17,11 @@ use OCP\Support\CrashReport\IRegistry;
|
|||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
|
||||
class LoggerTest extends TestCase implements IWriter {
|
||||
/** @var SystemConfig|MockObject */
|
||||
private $config;
|
||||
private SystemConfig&MockObject $config;
|
||||
|
||||
/** @var IRegistry|MockObject */
|
||||
private $registry;
|
||||
private IRegistry&MockObject $registry;
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
private Log $logger;
|
||||
|
||||
/** @var array */
|
||||
private array $logs = [];
|
||||
|
|
@ -35,7 +32,7 @@ class LoggerTest extends TestCase implements IWriter {
|
|||
$this->logs = [];
|
||||
$this->config = $this->createMock(SystemConfig::class);
|
||||
$this->registry = $this->createMock(IRegistry::class);
|
||||
$this->logger = new Log($this, $this->config, null, $this->registry);
|
||||
$this->logger = new Log($this, $this->config, crashReporters: $this->registry);
|
||||
}
|
||||
|
||||
private function mockDefaultLogLevel(): void {
|
||||
|
|
@ -165,6 +162,7 @@ class LoggerTest extends TestCase implements IWriter {
|
|||
|
||||
public function testLoggingWithDataArray(): void {
|
||||
$this->mockDefaultLogLevel();
|
||||
/** @var IWriter&MockObject */
|
||||
$writerMock = $this->createMock(IWriter::class);
|
||||
$logFile = new Log($writerMock, $this->config);
|
||||
$writerMock->expects($this->once())->method('write')->with('no app in context', ['something' => 'extra', 'message' => 'Testing logging with john']);
|
||||
|
|
|
|||
Loading…
Reference in a new issue