Fixed violations CI

Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
Valentin Popov 2019-05-11 13:49:04 +04:00
parent 7dc023b05a
commit c42e13d182
Signed by: Valentin Popov
GPG Key ID: 269A00ACA90A8EA3
3 changed files with 14 additions and 47 deletions

View File

@ -250,14 +250,14 @@ final class api {
$CFG->debugdisplay = false; $CFG->debugdisplay = false;
$directory = $CFG->libdir . '/classes/event'; $directory = $CFG->libdir . '/classes/event';
$events = [];
$files = self::get_file_list($directory); $files = self::get_file_list($directory);
if (isset($files['unknown_logged'])) { if (isset($files['unknown_logged'])) {
unset($files['unknown_logged']); unset($files['unknown_logged']);
} }
$events = []; foreach (array_keys($files) as $file) {
foreach ($files as $file => $location) {
$name = '\\core\\event\\' . $file; $name = '\\core\\event\\' . $file;
if (method_exists($name, 'get_static_info')) { if (method_exists($name, 'get_static_info')) {
@ -286,18 +286,14 @@ final class api {
private static function get_file_list(string $directory): array { private static function get_file_list(string $directory): array {
global $CFG; global $CFG;
$files = [];
$root = $CFG->dirroot; $root = $CFG->dirroot;
$files = [];
if (is_dir($directory) && is_readable($directory)) { if (is_dir($directory) && is_readable($directory)) {
$handle = opendir($directory); $handle = opendir($directory);
if ($handle) { if ($handle) {
foreach (scandir($directory, SCANDIR_SORT_NONE) as $file) { foreach (scandir($directory, SCANDIR_SORT_NONE) as $file) {
if (!is_string($file)) {
continue;
}
if ($file !== '.' && $file !== '..' && strrpos($directory, $root) !== false) { if ($file !== '.' && $file !== '..' && strrpos($directory, $root) !== false) {
$location = substr($directory, strlen($root)); $location = substr($directory, strlen($root));
$eventname = substr($file, 0, -4); $eventname = substr($file, 0, -4);
@ -332,7 +328,8 @@ final class api {
$CFG->debugdisplay = false; $CFG->debugdisplay = false;
$events = []; $events = [];
foreach (core_component::get_plugin_types() as $type => $unused) {
foreach (array_keys(core_component::get_plugin_types()) as $type) {
foreach (core_component::get_plugin_list($type) as $plugin => $directory) { foreach (core_component::get_plugin_list($type) as $plugin => $directory) {
$directory .= '/classes/event'; $directory .= '/classes/event';
$files = self::get_file_list($directory); $files = self::get_file_list($directory);
@ -341,7 +338,7 @@ final class api {
unset($files['unknown_logged']); unset($files['unknown_logged']);
} }
foreach ($files as $file => $location) { foreach (array_keys($files) as $file) {
$name = '\\' . $type . '_' . $plugin . '\\event\\' . $file; $name = '\\' . $type . '_' . $plugin . '\\event\\' . $file;
if (method_exists($name, 'get_static_info')) { if (method_exists($name, 'get_static_info')) {

View File

@ -20,10 +20,6 @@ defined('MOODLE_INTERNAL') || die();
use stdClass; use stdClass;
use function defined; use function defined;
use function is_array;
use function is_bool;
use function is_int;
use function is_string;
/** /**
* It's a class description record. * It's a class description record.
@ -88,38 +84,12 @@ final class record extends stdClass {
* @param array|null $conditions * @param array|null $conditions
*/ */
public function __construct(array $conditions = null) { public function __construct(array $conditions = null) {
if (isset($conditions['events']) && is_array($conditions['events'])) { $this->events = $conditions['events'] ?? null;
$this->events = []; $this->header = $conditions['header'] ?? null;
$this->id = $conditions['id'] ?? null;
foreach ($conditions['events'] as $event) { $this->name = $conditions['name'] ?? null;
if (is_string($event)) { $this->point = $conditions['point'] ?? null;
$this->events[] = $event; $this->status = $conditions['status'] ?? null;
} $this->token = $conditions['token'] ?? null;
}
}
if (isset($conditions['header']) && is_string($conditions['header'])) {
$this->header = $conditions['header'];
}
if (isset($conditions['id']) && is_int($conditions['id'])) {
$this->id = $conditions['id'];
}
if (isset($conditions['name']) && is_string($conditions['name'])) {
$this->name = $conditions['name'];
}
if (isset($conditions['point']) && is_string($conditions['point'])) {
$this->point = $conditions['point'];
}
if (isset($conditions['status']) && is_bool($conditions['status'])) {
$this->status = $conditions['status'];
}
if (isset($conditions['token']) && is_string($conditions['token'])) {
$this->token = $conditions['token'];
}
} }
} }

View File

@ -150,7 +150,7 @@ final class local_webhooks_api_testcase extends advanced_testcase {
self::assertNotCount(0, $events); self::assertNotCount(0, $events);
foreach ($events as $name => $event) { foreach ($events as $event) {
self::assertInternalType('array', $event); self::assertInternalType('array', $event);
self::assertEquals([ self::assertEquals([