Skip to content

Commit

Permalink
refactor database in log_output_db to DI
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed Oct 27, 2024
1 parent 40e80c2 commit 3fc6c1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 3 additions & 5 deletions classes/local/output/log_output_db.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
use stdClass;

class log_output_db implements log_output {
private moodle_database $db;

public function __construct(moodle_database $db = null) {
global $DB;
$this->db = $db ?? $DB;
}
public function __construct(
private readonly moodle_database $db
) {}

/**
* @throws dml_exception
Expand Down
3 changes: 2 additions & 1 deletion tests/local/output/log_output_db_test.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use core\di;
use local_logging\lib\adler_testcase;
use local_logging\local\output\log_output_db;

Expand All @@ -13,7 +14,7 @@ public function test_output() {
global $DB;

// Create an instance of log_output_db.
$logOutput = new log_output_db();
$logOutput = di::get(log_output_db::class);

// Define test data.
$message = 'Test message';
Expand Down

0 comments on commit 3fc6c1b

Please sign in to comment.