MDL-80005 core: Emit deprecation notices for params

Most params are formally deprecated here. This was originally planned
for MDL-80042, but I realised that having an emit, and final param is a
very useful option going forward.

This patch also moves the is_deprecated(), and related methods to the
\core\deprecated attribute.
This commit is contained in:
Andrew Nicols
2024-01-17 12:19:45 +08:00
parent a61658da17
commit b05fc42db9
12 changed files with 647 additions and 10 deletions
+33
View File
@@ -97,6 +97,39 @@ class param_test extends \advanced_testcase {
// Some deprecated parameters.
[param::INTEGER, true],
[param::NUMBER, true],
[param::CLEAN, true],
];
}
/**
* Test that finally deprecated params throw an exception when cleaning.
*
* @dataProvider deprecated_param_provider
* @param param $params
*/
public function test_deprecated_params_except(param $param): void {
$this->expectException(\coding_exception::class);
$param->clean('foo');
}
/**
* Provider for deprecated parameters.
*
* @return array
*/
public static function deprecated_param_provider(): array {
return array_map(
fn (param $param): array => [$param],
array_filter(
param::cases(),
function (param $param): bool {
if ($attribute = deprecation::from($param)) {
return $attribute->emit && $attribute->final;
}
return false;
},
),
);
}
}