Skip to content

Commit

Permalink
cleanup, typing fixes, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
Glutamat42 committed Oct 26, 2024
1 parent a3bb7da commit 04ce1a1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
25 changes: 18 additions & 7 deletions classes/condition.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use core_plugin_manager;
use dml_exception;
use invalid_parameter_exception;
use lang_string;
use local_adler\plugin_interface;
use local_logging\logger;
use moodle_exception;
Expand All @@ -26,6 +27,7 @@ class condition extends availability_condition {
/**
* @throws coding_exception
* @throws invalid_parameter_exception
* @throws moodle_exception
*/
public function __construct($structure) {
$this->logger = new logger('availability_adler', 'condition');
Expand All @@ -52,8 +54,7 @@ public function __construct($structure) {
* @throws invalid_parameter_exception
* @throws moodle_exception
*/
public function evaluate_section_requirements($statement, $userid, bool $validation_mode = false): bool {
// TODO: protected
protected function evaluate_section_requirements($statement, $userid, bool $validation_mode = false): bool {
// search for brackets
for ($i = 0; $i < strlen($statement); $i++) {
if ($statement[$i] == '(') {
Expand Down Expand Up @@ -135,7 +136,12 @@ protected function evaluate_section($section_id, $userid): bool {
}


public function is_available($not, info $info, $grabthelot, $userid) {
/**
* @throws moodle_exception
* @throws invalid_parameter_exception
* @throws dml_exception
*/
public function is_available($not, info $info, $grabthelot, $userid): bool {
// check if local_adler is available
$plugins = $this->core_plugin_manager_instance->get_installed_plugins('local');
if (!array_key_exists('adler', $plugins)) {
Expand Down Expand Up @@ -210,16 +216,21 @@ protected function make_condition_user_readable(string $statement): string {
return "\"" . trim($updated_statement) . "\"";
}

public function get_description($full, $not, info $info) {
/**
* @throws moodle_exception
* @throws coding_exception
* @throws dml_exception
*/
public function get_description($full, $not, info $info): lang_string|string {
$translation_key = $not ? 'description_previous_sections_required_not' : 'description_previous_sections_required';
return get_string($translation_key, 'availability_adler', $this->make_condition_user_readable($this->condition));
}

protected function get_debug_string() {
protected function get_debug_string(): string {
return 'Section condition: ' . $this->condition;
}

public function save() {
public function save(): object {
return (object)[
'type' => 'adler',
'condition' => $this->condition,
Expand All @@ -236,7 +247,7 @@ public function save() {
* @return bool
* @throws moodle_exception
*/
public function update_after_restore($restoreid, $courseid, base_logger $logger, $name) {
public function update_after_restore($restoreid, $courseid, base_logger $logger, $name): bool {
$updated_condition = "";
for ($i = 0; $i < strlen($this->condition); $i++) {
$char = $this->condition[$i];
Expand Down
2 changes: 1 addition & 1 deletion classes/frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use section_info;

class frontend extends availability_frontend {
protected function get_javascript_strings() {
protected function get_javascript_strings(): array {
// You can return a list of names within your language file and the
// system will include them here.
// Should you need strings from another language file, you can also
Expand Down
2 changes: 1 addition & 1 deletion lang/de/availability_adler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$string['pluginname'] = 'Raumlogik für local_adler';
$string['title'] = 'Raumlogik';

$string['description_previous_sections_required'] = 'Die vorangegangenen Räume müssen nach der folgenden Regel abgeschlossen sein: {$a}';
$string['description_previous_sections_required'] = 'Die vorangegangenen Räume müssen abgeschlossen sein: {$a}';
$string['description_previous_sections_required_not'] = 'Die vorangegangenen Räume dürfen nicht nach der folgenden Regel abgeschlossen sein: {$a}';
$string['node_adler_rule'] = 'Adler Regel: {$a}';
$string['condition_operator_pretty_and'] = 'und';
Expand Down
2 changes: 1 addition & 1 deletion lang/en/availability_adler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
$string['pluginname'] = 'Room logic for local_adler';
$string['title'] = 'Room logic';

$string['description_previous_sections_required'] = 'The previous rooms have to be completed according to the rule: {$a}';
$string['description_previous_sections_required'] = 'The previous rooms have to be completed: {$a}';
$string['description_previous_sections_required_not'] = 'The previous rooms have not to be completed according to the rule: {$a}';
$string['node_adler_rule'] = 'Adler rule: {$a}';
$string['condition_operator_pretty_and'] = 'and';
Expand Down
10 changes: 7 additions & 3 deletions tests/lib/adler_testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
require_once($CFG->dirroot . '/availability/condition/adler/vendor/autoload.php');

use advanced_testcase;
use externallib_advanced_testcase;
use Mockery;

trait general_testcase_adjustments{
trait general_testcase_adjustments {
public function setUp(): void {
parent::setUp();

Expand All @@ -19,8 +18,13 @@ public function setUp(): void {
// if creating multiple mocks of the same class (in my example context_module) in different tests or
// same test with different parameters Mockery always reused the first mock created for that class.
// This is not desired, because test cases should be independent of each other. Therefore, the
// Mockery container is reset after each test case.
// Mockery container is reset before each test case.
Mockery::resetContainer();

// workaround for beStrictAboutOutputDuringTests = true in default moodle phpunit configuration
if ($this->getTestResultObject()->isStrictAboutOutputDuringTests()){
$this->expectOutputRegex('/.*/');
}
}

public function tearDown(): void {
Expand Down

0 comments on commit 04ce1a1

Please sign in to comment.