From 123456781c6b4973f3c0fab0f98bbfd801f5dd22 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Thu, 10 Oct 2024 11:18:46 +1100 Subject: [PATCH] fix: phpcs fixes - update providers to static functions - @param phpdocs - phpdocs, trait docs, static providers --- classes/admin/readonly_trait.php | 8 ++- classes/external/trigger_dataflow.php | 2 +- classes/form/dataflow_form.php | 2 +- classes/form/import_form.php | 2 +- classes/form/step_form.php | 2 +- classes/local/execution/engine.php | 22 ++++++-- classes/local/step/abort_trait.php | 5 +- classes/local/step/append_file_trait.php | 1 + classes/local/step/compression_trait.php | 11 ++-- .../step/connector_debug_file_display.php | 1 - classes/local/step/copy_file_trait.php | 1 + .../local/step/directory_file_list_trait.php | 18 +++---- classes/local/step/file_put_content_trait.php | 2 +- classes/local/step/gpg_trait.php | 1 + classes/local/step/hash_file_trait.php | 9 ++-- classes/local/step/log_trait.php | 11 ++-- classes/local/step/remove_file_trait.php | 1 + classes/local/step/s3_trait.php | 9 ++-- classes/local/step/set_variable_trait.php | 1 + classes/local/step/sftp_trait.php | 6 +-- classes/local/step/sql_trait.php | 6 +-- classes/parser.php | 4 +- classes/run.php | 2 +- classes/visualiser.php | 2 +- dataflow-action.php | 1 - db/services.php | 2 +- db/upgrade.php | 2 +- lang/en/tool_dataflows.php | 2 +- runs.php | 1 - settings.php | 2 +- step.php | 1 - tests/application_trait.php | 9 ---- .../execution/tool_dataflows_engine_test.php | 4 +- tests/tool_dataflows_ad_hoc_task_test.php | 2 +- .../tool_dataflows_append_file_step_test.php | 6 +-- ...l_dataflows_connector_compression_test.php | 6 +-- tests/tool_dataflows_connector_curl_test.php | 2 +- ...ws_connector_directory_file_count_test.php | 2 +- tests/tool_dataflows_connector_s3_test.php | 20 +++---- tests/tool_dataflows_dot_escape_test.php | 2 +- .../tool_dataflows_flow_compression_test.php | 16 +++--- tests/tool_dataflows_flow_hash_file_test.php | 2 +- tests/tool_dataflows_flow_sql_test.php | 12 ++--- ..._dataflows_flow_transformer_alter_test.php | 35 ++++++------ ...dataflows_flow_transformer_filter_test.php | 53 ++++++++++--------- ..._dataflows_flow_transformer_regex_test.php | 19 ++++--- tests/tool_dataflows_gpg_test.php | 5 +- tests/tool_dataflows_helper_test.php | 12 ++--- tests/tool_dataflows_json_reader_test.php | 5 +- tests/tool_dataflows_parser_test.php | 5 +- tests/tool_dataflows_permitted_dir_test.php | 4 +- tests/tool_dataflows_remove_file_test.php | 8 ++- tests/tool_dataflows_sftp_test.php | 4 +- tests/tool_dataflows_step_test.php | 4 +- tests/tool_dataflows_stream_writer_test.php | 2 +- tests/tool_dataflows_test.php | 2 +- tests/tool_dataflows_upgrade_test.php | 1 + tests/tool_dataflows_variables_new_test.php | 2 +- .../tool_dataflows_web_service_flow_test.php | 2 - 59 files changed, 189 insertions(+), 197 deletions(-) diff --git a/classes/admin/readonly_trait.php b/classes/admin/readonly_trait.php index 743bf839..3f6ebf50 100644 --- a/classes/admin/readonly_trait.php +++ b/classes/admin/readonly_trait.php @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_dataflows\admin; + +use tool_dataflows\manager; /** * Read only trait @@ -25,11 +28,6 @@ * @copyright Catalyst IT, 2023 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_dataflows\admin; - -use tool_dataflows\manager; - trait readonly_trait { /** diff --git a/classes/external/trigger_dataflow.php b/classes/external/trigger_dataflow.php index 432453ab..efd2146e 100644 --- a/classes/external/trigger_dataflow.php +++ b/classes/external/trigger_dataflow.php @@ -45,7 +45,7 @@ public static function execute_parameters() { return new external_function_parameters([ 'dataflow' => new external_single_structure([ 'id' => new external_value(PARAM_INT, 'dataflow record id'), - ]) + ]), ]); } diff --git a/classes/form/dataflow_form.php b/classes/form/dataflow_form.php index b4a06aad..bb073ab6 100644 --- a/classes/form/dataflow_form.php +++ b/classes/form/dataflow_form.php @@ -46,7 +46,7 @@ public function definition() { $mform->addElement( 'html', \html_writer::div( - get_string( 'readonly_active', 'tool_dataflows'), + get_string('readonly_active', 'tool_dataflows'), 'alert alert-warning' ) ); diff --git a/classes/form/import_form.php b/classes/form/import_form.php index 25db365f..128e9d04 100644 --- a/classes/form/import_form.php +++ b/classes/form/import_form.php @@ -44,7 +44,7 @@ public function definition() { $mform->addElement( 'html', \html_writer::div( - get_string( 'readonly_active', 'tool_dataflows'), + get_string('readonly_active', 'tool_dataflows'), 'alert alert-warning' ) ); diff --git a/classes/form/step_form.php b/classes/form/step_form.php index 7e3af96e..e09e2069 100644 --- a/classes/form/step_form.php +++ b/classes/form/step_form.php @@ -49,7 +49,7 @@ public function definition() { $mform->addElement( 'html', \html_writer::div( - get_string( 'readonly_active', 'tool_dataflows'), + get_string('readonly_active', 'tool_dataflows'), 'alert alert-warning' ) ); diff --git a/classes/local/execution/engine.php b/classes/local/execution/engine.php index a49b31c5..d832571a 100644 --- a/classes/local/execution/engine.php +++ b/classes/local/execution/engine.php @@ -22,6 +22,7 @@ use Monolog\Handler\StreamHandler; use Monolog\Processor\PsrLogMessageProcessor; use Symfony\Bridge\Monolog\Logger; +use Throwable; use tool_dataflows\dataflow; use tool_dataflows\exportable; use tool_dataflows\helper; @@ -223,6 +224,7 @@ public function __construct(dataflow $dataflow, bool $isdryrun = false, $automat /** * Destructor function. * Releases any locks that are still held. + * @return void */ public function __destruct() { $this->release_lock(); @@ -274,6 +276,7 @@ public function get_lock($timeout = 0) { * Release any locks that have been previously obtained. * * @throws \dml_exception + * @return void */ public function release_lock() { global $DB; @@ -322,6 +325,7 @@ public function is_aborted(): bool { /** * Initialises the dataflow. + * @return void */ public function initialise() { $this->status_check(self::STATUS_NEW); @@ -380,6 +384,7 @@ public function initialise() { /** * Finds the steps that are sinks for their respective flow blocks and create flow caps for them. + * @return void */ protected function create_flow_caps() { // TODO Currently assumes flow blocks have no branches. @@ -451,6 +456,7 @@ protected function count_flow_steps(array $list): int { /** * Runs the data flow as a single action. This function initialises the dataflow, * runs the dataflow, and finalises it. + * @return void */ public function execute() { $this->initialise(); @@ -487,6 +493,7 @@ public function execute() { * Adds an engine step to the queues for processing. * * @param engine_step $step + * @return void */ public function add_to_queue(engine_step $step) { if (!in_array($step, $this->enginesteps, true) && !in_array($step, $this->flowcaps, true)) { @@ -497,6 +504,7 @@ public function add_to_queue(engine_step $step) { /** * Executes a single step. Must be initialised prior to calling. Does not finalise. + * @return void */ public function execute_step() { if ($this->status === self::STATUS_INITIALISED) { @@ -515,6 +523,7 @@ public function execute_step() { /** * Finalises the execution. Any remaining resources should be released. + * @return void */ public function finalise() { try { @@ -545,6 +554,7 @@ public function finalise() { * * @param \Throwable|null $reason * @throws \Throwable + * @return void */ public function abort(?\Throwable $reason = null) { // If already aborted, do nothing. @@ -610,6 +620,7 @@ public function abort(?\Throwable $reason = null) { * @param string $message * @param mixed $context * @param mixed $level + * @return void */ public function log(string $message, $context = [], $level = Logger::INFO) { $this->logger->log($level, $message, $context); @@ -647,6 +658,7 @@ public function __get($parameter) { * This also records some metadata in the relevant objects e.g. the dataflow's state. * * @param int $status a status from the engine class + * @return void */ public function set_status(int $status) { if ($status === $this->status) { @@ -679,8 +691,8 @@ public function set_status(int $status) { $this->get_variables()->set("states.$statusstring", microtime(true)); $context = [ - 'isdryrun' => $this->isdryrun, - 'status' => get_string('engine_status:'.self::STATUS_LABELS[$this->status], 'tool_dataflows'), + 'isdryrun' => $this->isdryrun, + 'status' => get_string('engine_status:'.self::STATUS_LABELS[$this->status], 'tool_dataflows'), ]; $level = Logger::INFO; @@ -716,6 +728,7 @@ public function get_export_data(): array { * * @param int $expected * @throws \moodle_exception + * @return void */ protected function status_check(int $expected) { if ($this->status !== $expected) { @@ -760,6 +773,7 @@ public function create_temporary_file($prefix = '____') { * Sets the currently processing step for the engine. * * @param engine_step|null $step + * @return void */ public function set_current_step(?engine_step $step) { $this->currentstep = $step; @@ -771,6 +785,7 @@ public function set_current_step(?engine_step $step) { * This will enable any adapters / handlers enabled from the dataflow configuration. * The preference for applying the rules will be from most specific to more * general settings. + * @return void */ private function setup_logging() { global $CFG; @@ -865,7 +880,8 @@ private function setup_logging() { /** * Send a notification email for abort if required. * - * @param \Throwable $reason A throwable representing the reason for abort. + * @param ?\Throwable $reason A throwable representing the reason for abort. + * @return void */ public function notify_on_abort(?\Throwable $reason) { // If configured to send email, attempt to notify of the abort reason. diff --git a/classes/local/step/abort_trait.php b/classes/local/step/abort_trait.php index 67f02667..da6617b8 100644 --- a/classes/local/step/abort_trait.php +++ b/classes/local/step/abort_trait.php @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_dataflows\local\step; + /** * Abort Step ..Trait * @@ -27,9 +29,6 @@ * @copyright Catalyst IT, 2022 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_dataflows\local\step; - trait abort_trait { /** diff --git a/classes/local/step/append_file_trait.php b/classes/local/step/append_file_trait.php index 19aec629..da5be005 100644 --- a/classes/local/step/append_file_trait.php +++ b/classes/local/step/append_file_trait.php @@ -28,6 +28,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ trait append_file_trait { + /** * Returns whether or not the step configured, has a side effect. * diff --git a/classes/local/step/compression_trait.php b/classes/local/step/compression_trait.php index 7e1a43c6..8adb1d62 100644 --- a/classes/local/step/compression_trait.php +++ b/classes/local/step/compression_trait.php @@ -29,6 +29,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ trait compression_trait { + /** * Returns whether or not the step configured, has a side effect. * @@ -188,10 +189,10 @@ private function get_supported_methods(): array { return [ 'gzip' => (object) [ 'name' => get_string('compression:method:gzip', 'tool_dataflows'), - 'isexecutable' => function() { + 'isexecutable' => function () { return self::validate_executable(get_config('tool_dataflows', 'gzip_exec_path')); - } - ] + }, + ], ]; } @@ -203,9 +204,7 @@ private function get_supported_methods(): array { */ private static function validate_executable(string $path) { if (!is_executable($path)) { - return get_string('compression:error:invalidexecutable', 'tool_dataflows', [ - 'path' => $path - ]); + return get_string('compression:error:invalidexecutable', 'tool_dataflows', ['path' => $path]); } return true; diff --git a/classes/local/step/connector_debug_file_display.php b/classes/local/step/connector_debug_file_display.php index 2b9338eb..b2b06e5a 100644 --- a/classes/local/step/connector_debug_file_display.php +++ b/classes/local/step/connector_debug_file_display.php @@ -94,4 +94,3 @@ public function form_add_custom_inputs(\MoodleQuickForm &$mform) { } } - diff --git a/classes/local/step/copy_file_trait.php b/classes/local/step/copy_file_trait.php index 05cc866b..5ee60ce8 100644 --- a/classes/local/step/copy_file_trait.php +++ b/classes/local/step/copy_file_trait.php @@ -27,6 +27,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ trait copy_file_trait { + /** * Return the definition of the fields available in this form. * diff --git a/classes/local/step/directory_file_list_trait.php b/classes/local/step/directory_file_list_trait.php index c9bd4e64..f1171800 100644 --- a/classes/local/step/directory_file_list_trait.php +++ b/classes/local/step/directory_file_list_trait.php @@ -88,18 +88,18 @@ public function form_add_custom_inputs(\MoodleQuickForm &$mform) { // Return value. $mform->addElement( 'select', 'config_returnvalue', get_string('directory_file_list:returnvalue', 'tool_dataflows'), [ - 'basename' => get_string('directory_file_list:basename', 'tool_dataflows'), - 'relativepath' => get_string('directory_file_list:relativepath', 'tool_dataflows'), - 'absolutepath' => get_string('directory_file_list:absolutepath', 'tool_dataflows'), + 'basename' => get_string('directory_file_list:basename', 'tool_dataflows'), + 'relativepath' => get_string('directory_file_list:relativepath', 'tool_dataflows'), + 'absolutepath' => get_string('directory_file_list:absolutepath', 'tool_dataflows'), ] ); // Sort. $mform->addElement( 'select', 'config_sort', get_string('directory_file_list:sort', 'tool_dataflows'), [ - 'alpha' => get_string('directory_file_list:alpha', 'tool_dataflows'), - 'alpha_reverse' => get_string('directory_file_list:alpha_reverse', 'tool_dataflows'), - 'natural' => get_string('directory_file_list:natural', 'tool_dataflows'), + 'alpha' => get_string('directory_file_list:alpha', 'tool_dataflows'), + 'alpha_reverse' => get_string('directory_file_list:alpha_reverse', 'tool_dataflows'), + 'natural' => get_string('directory_file_list:natural', 'tool_dataflows'), ] ); @@ -180,10 +180,10 @@ public function validate_for_run() { * @param string $returnvalue * @param string $sort * @param int $offset - * @param int $limit + * @param ?int $limit * @param bool $includedir * @param string $basepath - * @param string $pattern + * @param ?string $pattern * @return array new file list */ public function apply_list_constraints( @@ -194,7 +194,7 @@ public function apply_list_constraints( ?int $limit, bool $includedir, string $basepath, - string $pattern = null + ?string $pattern ): array { // Apply filter for excluding directories/folders. // This is not related to recursive lookups in any way. diff --git a/classes/local/step/file_put_content_trait.php b/classes/local/step/file_put_content_trait.php index ba1221fd..061b0d25 100644 --- a/classes/local/step/file_put_content_trait.php +++ b/classes/local/step/file_put_content_trait.php @@ -27,6 +27,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ trait file_put_content_trait { + /** * Return the definition of the fields available in this form. * @@ -101,7 +102,6 @@ public function validate_for_run() { return $errors ?: true; } - /** * Executes the step * diff --git a/classes/local/step/gpg_trait.php b/classes/local/step/gpg_trait.php index de747214..56196cc0 100644 --- a/classes/local/step/gpg_trait.php +++ b/classes/local/step/gpg_trait.php @@ -27,6 +27,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ trait gpg_trait { + /** * Returns whether or not the step configured, has a side effect. * diff --git a/classes/local/step/hash_file_trait.php b/classes/local/step/hash_file_trait.php index b2c97f66..883ef851 100644 --- a/classes/local/step/hash_file_trait.php +++ b/classes/local/step/hash_file_trait.php @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_dataflows\local\step; + +use tool_dataflows\helper; + /** * Hash file flow step * @@ -22,11 +26,6 @@ * @copyright Catalyst IT, 2022 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_dataflows\local\step; - -use tool_dataflows\helper; - trait hash_file_trait { /** diff --git a/classes/local/step/log_trait.php b/classes/local/step/log_trait.php index 01432a14..16725e97 100644 --- a/classes/local/step/log_trait.php +++ b/classes/local/step/log_trait.php @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_dataflows\local\step; + +use Symfony\Bridge\Monolog\Logger; + /** * Log trait * @@ -22,17 +26,12 @@ * @copyright Catalyst IT, 2023 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_dataflows\local\step; - -use Symfony\Bridge\Monolog\Logger; - trait log_trait { /** * Logging levels from syslog protocol defined in RFC 5424 * - * @var array $levels Logging levels + * @var array Logging levels */ protected static $levels = [ Logger::DEBUG => 'DEBUG', diff --git a/classes/local/step/remove_file_trait.php b/classes/local/step/remove_file_trait.php index f4893eb6..701eed29 100644 --- a/classes/local/step/remove_file_trait.php +++ b/classes/local/step/remove_file_trait.php @@ -27,6 +27,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ trait remove_file_trait { + /** * Returns whether or not the step configured, has a side effect. * diff --git a/classes/local/step/s3_trait.php b/classes/local/step/s3_trait.php index a3f2fbf4..6a149b1a 100644 --- a/classes/local/step/s3_trait.php +++ b/classes/local/step/s3_trait.php @@ -14,6 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +namespace tool_dataflows\local\step; + +use tool_dataflows\helper; + /** * S3 copy step ..trait * @@ -23,11 +27,6 @@ * @copyright Catalyst IT, 2022 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ - -namespace tool_dataflows\local\step; - -use tool_dataflows\helper; - trait s3_trait { /** diff --git a/classes/local/step/set_variable_trait.php b/classes/local/step/set_variable_trait.php index cd3eff67..1a573d2d 100644 --- a/classes/local/step/set_variable_trait.php +++ b/classes/local/step/set_variable_trait.php @@ -35,6 +35,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ trait set_variable_trait { + /** * Returns whether or not the step configured, has a side effect * diff --git a/classes/local/step/sftp_trait.php b/classes/local/step/sftp_trait.php index 0c61c53b..eff76213 100644 --- a/classes/local/step/sftp_trait.php +++ b/classes/local/step/sftp_trait.php @@ -34,13 +34,13 @@ */ trait sftp_trait { - /** Shorthand sftp scheme for use in config. */ + /** @var string Shorthand sftp scheme for use in config. */ protected static $sftpprefix = 'sftp'; - /** Default port to connect to. */ + /** @var int Default port to connect to. */ protected static $defaultport = 22; - /** Array of SFTP objects to use for performance reasons. */ + /** @var array SFTP objects to use for performance reasons. */ protected $sftp = []; /** diff --git a/classes/local/step/sql_trait.php b/classes/local/step/sql_trait.php index e3c13762..ba5ac55e 100644 --- a/classes/local/step/sql_trait.php +++ b/classes/local/step/sql_trait.php @@ -57,7 +57,7 @@ private function evaluate_expressions(string $sql) { $sql = preg_replace($pattern, '?', $sql); // Now we can map all the variables to their real values. - $vars = array_map(function($el) use ($variables, $parser) { + $vars = array_map(function ($el) use ($variables, $parser) { $hasexpression = true; $max = 5; while ($hasexpression && $max) { @@ -88,7 +88,7 @@ private function evaluate_expressions(string $sql) { * Returns a clarified error message if applicable. * * @param string $message - * @param string $sql replacement for the expression held by default. + * @param ?string $sql replacement for the expression held by default. * @return string clarified message if applicable */ private function clarify_parser_error(string $message, ?string $sql = null): string { @@ -256,7 +256,7 @@ public function execute($input = null) { $token = $matches[0] ?? ''; $emptydefault = new \stdClass(); - switch(strtoupper($token)) { + switch (strtoupper($token)) { case 'SELECT': // Execute the query using get_records instead of get_record. // This is so we can expose the number of records returned which diff --git a/classes/parser.php b/classes/parser.php index d9d4d530..da95cd74 100644 --- a/classes/parser.php +++ b/classes/parser.php @@ -244,7 +244,7 @@ public function evaluate(string $expression, array $variables) { * * @param string $expression * @param array $variables containing anything relevant to the evaluation of the result - * @param callable $failcallback containing anything relevant to the evaluation of the result + * @param ?callable $failcallback containing anything relevant to the evaluation of the result * @return mixed */ public function evaluate_or_fail(string $expression, array $variables, ?callable $failcallback = null) { @@ -267,7 +267,7 @@ public function has_expression(string $expression): array { * * @param string $string * @param array $variables containing anything relevant to the evaluation of the result - * @param callable $failcallback containing anything relevant to the evaluation of the result + * @param ?callable $failcallback containing anything relevant to the evaluation of the result * @return mixed */ private function internal_evaluator(string $string, array $variables, ?callable $failcallback) { diff --git a/classes/run.php b/classes/run.php index bd8097b0..6d7feb06 100644 --- a/classes/run.php +++ b/classes/run.php @@ -119,7 +119,7 @@ public function initialise(string $status, string $startstate) { * Sets the snapshot of the current state of the run * * @param string $status the engine's status - * @param string $currentstate the yaml string representation of the state of the dataflow + * @param ?string $currentstate the yaml string representation of the state of the dataflow */ public function snapshot(string $status, ?string $currentstate = null) { $this->status = $status; diff --git a/classes/visualiser.php b/classes/visualiser.php index 6be9c990..6bf6d301 100644 --- a/classes/visualiser.php +++ b/classes/visualiser.php @@ -66,7 +66,7 @@ public static function breadcrumb_navigation(array $crumbs) { * generated image content. * * @param string $dotscript the script for DOT to generate the image. - * @param string $type supported image types: jpg, gif, png, svg, ps. + * @param ?string $type supported image types: jpg, gif, png, svg, ps. * @return binary|string content of the generated image on success, empty string on failure. * * @author cjiang diff --git a/dataflow-action.php b/dataflow-action.php index d982edbd..7b1c7641 100644 --- a/dataflow-action.php +++ b/dataflow-action.php @@ -81,7 +81,6 @@ break; } - // Redirect to the dataflows details page. if ($notifystring !== null) { redirect($returnurl, get_string($action.'_dataflow_successful', 'tool_dataflows', $dataflow->name), diff --git a/db/services.php b/db/services.php index 40bacc76..4065f457 100644 --- a/db/services.php +++ b/db/services.php @@ -55,5 +55,5 @@ 'functions' => ['tool_dataflows_trigger_dataflow'], 'restrictedusers' => 0, 'shortname' => 'dataflow_service', - ] + ], ]; diff --git a/db/upgrade.php b/db/upgrade.php index 5ca6b2be..32a34450 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -333,7 +333,7 @@ function xmldb_tool_dataflows_upgrade($oldversion) { $type = \tool_dataflows\local\step\trigger_cron::class; $newfields = [ 'retryinterval' => 0, - 'retrycount' => 0 + 'retrycount' => 0, ]; xmldb_tool_dataflows_step_config_helper($type, $newfields); diff --git a/lang/en/tool_dataflows.php b/lang/en/tool_dataflows.php index 3f556173..0df4c283 100644 --- a/lang/en/tool_dataflows.php +++ b/lang/en/tool_dataflows.php @@ -110,7 +110,7 @@ See the run logs for further details.'; $string['notifyonabort_subject'] = 'Dataflow run aborted: {$a}'; $string['minloglevel'] = 'Minimum Log level'; -$string['minloglevel_desc'] = 'This defines the minimum level to log. For example, if set at WARNING, it will only log WARNING messages and above, like ERROR, CRITICAL, ALERT, and EMERGENCY'; +$string['minloglevel_desc'] = 'This defines the minimum level to log. For example, if set at WARNING, it will only log WARNING messages and above, like ERROR, CRITICAL, ALERT, and EMERGENCY.'; // Dataflow import form. $string['dataflow_file'] = 'Dataflow file'; diff --git a/runs.php b/runs.php index 274ba655..608c356b 100644 --- a/runs.php +++ b/runs.php @@ -97,7 +97,6 @@ $PAGE->set_heading($dataflow->name . ': ' . $pageheading); echo $output->header(); - // No hide/show links under each column. $table->attributes['class'] = 'table-sm w-auto'; $table->build(); diff --git a/settings.php b/settings.php index e2bce68c..a7d77a0f 100644 --- a/settings.php +++ b/settings.php @@ -52,7 +52,7 @@ 'tool_dataflows/readonly_active', '', html_writer::div( - get_string( 'readonly_active', 'tool_dataflows'), + get_string('readonly_active', 'tool_dataflows'), 'alert alert-warning' ) )); diff --git a/step.php b/step.php index fb0887e8..0cdf822e 100644 --- a/step.php +++ b/step.php @@ -71,7 +71,6 @@ redirect($overviewurl); } - // Set the PAGE URL (and mandatory context). Note the ID being recorded, this is important. $PAGE->set_context($context); $PAGE->set_url($url); diff --git a/tests/application_trait.php b/tests/application_trait.php index 24934d48..47f1d6d3 100644 --- a/tests/application_trait.php +++ b/tests/application_trait.php @@ -14,15 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** - * Helper unit test methods that are highly related to the application. - * - * @package tool_dataflows - * @author Kevin Pham - * @copyright Catalyst IT, 2022 - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - namespace tool_dataflows; /** diff --git a/tests/local/execution/tool_dataflows_engine_test.php b/tests/local/execution/tool_dataflows_engine_test.php index 8bcc2dd0..86f2849e 100644 --- a/tests/local/execution/tool_dataflows_engine_test.php +++ b/tests/local/execution/tool_dataflows_engine_test.php @@ -144,7 +144,7 @@ function ($s) { * * @return array */ - public function dataflow_provider(): array { + public static function dataflow_provider(): array { $dataflow = new dataflow(); $dataflow->name = 'two-step'; $dataflow->enabled = true; @@ -241,7 +241,7 @@ public function test_finished_engine() { 'tool_dataflows', [ 'to' => engine::STATUS_LABELS[engine::STATUS_INITIALISED], - 'from' => engine::STATUS_LABELS[engine::STATUS_FINALISED] + 'from' => engine::STATUS_LABELS[engine::STATUS_FINALISED], ] )); $engine->set_status(engine::STATUS_INITIALISED); diff --git a/tests/tool_dataflows_ad_hoc_task_test.php b/tests/tool_dataflows_ad_hoc_task_test.php index 76fcddbb..95672e3c 100644 --- a/tests/tool_dataflows_ad_hoc_task_test.php +++ b/tests/tool_dataflows_ad_hoc_task_test.php @@ -67,7 +67,7 @@ public function test_task_execute() { */ public function test_cron_adhoc_task_creation() { // Create three CRON triggered dataflows. - array_map(function($i) { + array_map(function ($i) { return $this->create_dataflow(); }, range(0, 2)); diff --git a/tests/tool_dataflows_append_file_step_test.php b/tests/tool_dataflows_append_file_step_test.php index 4fc565c8..92bf7e91 100644 --- a/tests/tool_dataflows_append_file_step_test.php +++ b/tests/tool_dataflows_append_file_step_test.php @@ -54,7 +54,7 @@ class tool_dataflows_append_file_step_test extends \advanced_testcase { /** File list name. */ const FILE_LIST_NAME = 'files.csv'; - /** @var string Base directory. */ + /** @var string Base directory. */ private $basedir; /** @@ -111,7 +111,7 @@ public function test_has_sideeffect(string $file, bool $expected) { Yaml::dump([ 'dir1' => 'everywhere', 'dir2' => '/anywhere', - 'dir3' => 'sftp://somewhere' + 'dir3' => 'sftp://somewhere', ]), 'tool_dataflows' ); @@ -126,7 +126,7 @@ public function test_has_sideeffect(string $file, bool $expected) { * * @return array[] */ - public function has_sideeffect_provider(): array { + public static function has_sideeffect_provider(): array { return [ ['test.txt', false], ['/test.txt', true], diff --git a/tests/tool_dataflows_connector_compression_test.php b/tests/tool_dataflows_connector_compression_test.php index e5bdebc0..3e43e2f8 100644 --- a/tests/tool_dataflows_connector_compression_test.php +++ b/tests/tool_dataflows_connector_compression_test.php @@ -30,7 +30,7 @@ * @covers \tool_dataflows\local\step\connector_compression */ class tool_dataflows_connector_compression_test extends \advanced_testcase { - /** @var string $basedir base test directory for files **/ + /** @var string base test directory for files * */ private $basedir; /** @@ -67,7 +67,7 @@ private function create_test_dataflow(string $from, string $tocompressed, string 'from' => $from, 'to' => $tocompressed, 'method' => $method, - 'command' => 'compress' + 'command' => 'compress', ]); $compress->name = 'compress'; @@ -80,7 +80,7 @@ private function create_test_dataflow(string $from, string $tocompressed, string 'from' => $tocompressed, 'to' => $todecompressed, 'method' => $method, - 'command' => 'decompress' + 'command' => 'decompress', ]); $decompress->depends_on([$compress]); diff --git a/tests/tool_dataflows_connector_curl_test.php b/tests/tool_dataflows_connector_curl_test.php index 66ccd644..ffeb60c2 100644 --- a/tests/tool_dataflows_connector_curl_test.php +++ b/tests/tool_dataflows_connector_curl_test.php @@ -324,7 +324,7 @@ public function test_has_side_effect(string $destination, string $method, bool $ * * @return array[] */ - public function has_side_effect_provider(): array { + public static function has_side_effect_provider(): array { return [ ['my/in.txt', 'get', false, false], ['my/in.txt', 'head', false, false], diff --git a/tests/tool_dataflows_connector_directory_file_count_test.php b/tests/tool_dataflows_connector_directory_file_count_test.php index b0da66b2..df4629d5 100644 --- a/tests/tool_dataflows_connector_directory_file_count_test.php +++ b/tests/tool_dataflows_connector_directory_file_count_test.php @@ -87,7 +87,7 @@ public function test_non_existent_directory_also_returns_zero() { * * @return array of expected counts */ - public function count_provider(): array { + public static function count_provider(): array { return [ [0], [10], diff --git a/tests/tool_dataflows_connector_s3_test.php b/tests/tool_dataflows_connector_s3_test.php index 13cbf6f3..348cd755 100644 --- a/tests/tool_dataflows_connector_s3_test.php +++ b/tests/tool_dataflows_connector_s3_test.php @@ -56,7 +56,7 @@ public function test_path_is_in_s3_or_not(string $path, bool $isins3) { * * @return array */ - public function path_in_s3_data_provider(): array { + public static function path_in_s3_data_provider(): array { return [ ['s3://path/to/file', true], ['s3://path/to/', true], @@ -131,7 +131,7 @@ public function test_path_is_resolved_as_expected(string $path, string $expected * * @return array */ - public function path_input_and_expected_data_provider(): array { + public static function path_input_and_expected_data_provider(): array { return [ ['s3://path/to/file', 'path/to/file'], ['s3://path/to/', 'path/to/'], @@ -181,7 +181,7 @@ public function test_validate_for_run(string $source, string $target, $expected) * * @return array[] */ - public function validate_for_run_provider(): array { + public static function validate_for_run_provider(): array { $s3file = 's3://test/source.csv'; $relativefile = 'test/source.csv'; $absolutefile = '/var/source.csv'; @@ -290,14 +290,14 @@ public function test_has_side_effect(string $source, string $target, bool $expec * * @return array[] */ - public function has_side_effect_provider(): array { + public static function has_side_effect_provider(): array { return [ - [ 's3://test/source.csv', 's3://test/target.csv', true], - [ 's3://test/source.csv', 'test/target.csv', false], - [ 'test/source.csv', 's3://test/target.csv', true], - [ 's3://test/source.csv', '${{global.vars.abs}}', true], - [ 's3://test/source.csv', '${{global.vars.rel}}', false], - [ 'test/source.csv', 's3://${{global.vars.rel}}', true], + ['s3://test/source.csv', 's3://test/target.csv', true], + ['s3://test/source.csv', 'test/target.csv', false], + ['test/source.csv', 's3://test/target.csv', true], + ['s3://test/source.csv', '${{global.vars.abs}}', true], + ['s3://test/source.csv', '${{global.vars.rel}}', false], + ['test/source.csv', 's3://${{global.vars.rel}}', true], ]; } } diff --git a/tests/tool_dataflows_dot_escape_test.php b/tests/tool_dataflows_dot_escape_test.php index 916caa2f..d01c9c05 100644 --- a/tests/tool_dataflows_dot_escape_test.php +++ b/tests/tool_dataflows_dot_escape_test.php @@ -48,7 +48,7 @@ protected function setUp(): void { * * @return array */ - public function escape_dot_dataprovider() { + public static function escape_dot_dataprovider(): array { $sqlinput = <<<'INPUT' ' " \ / \\ SQL diff --git a/tests/tool_dataflows_flow_compression_test.php b/tests/tool_dataflows_flow_compression_test.php index 77ea4596..6ce4a5fe 100644 --- a/tests/tool_dataflows_flow_compression_test.php +++ b/tests/tool_dataflows_flow_compression_test.php @@ -31,10 +31,10 @@ * @covers \tool_dataflows\local\step\connector_compression */ class tool_dataflows_flow_compression_test extends \advanced_testcase { - /** @var string $readdir directory with files in it to read from for flow step */ + /** @var string directory with files in it to read from for flow step */ private $readdir; - /** @var string $outdir directory where the compressed/decompressed files are outputted to */ + /** @var string directory where the compressed/decompressed files are outputted to */ private $outdir; /** @@ -80,7 +80,7 @@ private function create_test_dataflow(string $method) { 'returnvalue' => 'basename', 'sort' => 'alpha', 'offset' => '0', - 'limit' => '0' + 'limit' => '0', ]); $reader->name = 'reader'; $reader->type = reader_directory_file_list::class; @@ -91,7 +91,7 @@ private function create_test_dataflow(string $method) { 'from' => $this->readdir . '/${{record.filename}}', 'to' => $this->outdir . '/${{record.filename}}-out.gz', 'method' => $method, - 'command' => 'compress' + 'command' => 'compress', ]); $compress->depends_on([$reader]); $compress->name = 'compress'; @@ -103,7 +103,7 @@ private function create_test_dataflow(string $method) { 'from' => $this->outdir . '/${{record.filename}}-out.gz', 'to' => $this->outdir . '/${{record.filename}}-out-decompressed.txt', 'method' => $method, - 'command' => 'decompress' + 'command' => 'decompress', ]); $decompress->depends_on([$compress]); $decompress->name = 'decompress'; @@ -136,16 +136,16 @@ public function test_gzip_compression_decompression() { // Check the files were outputted correctly. // Note we check the mime type rather than the file extension // since the extension may be misleading. - $outdircontenttypes = array_map(function($filename) { + $outdircontenttypes = array_map(function ($filename) { $fullpath = $this->outdir . '/' . $filename; return mime_content_type($fullpath); }, scandir($this->outdir)); - $this->assertCount(2, array_filter($outdircontenttypes, function($type) { + $this->assertCount(2, array_filter($outdircontenttypes, function ($type) { return $type == 'application/gzip' || $type == 'application/x-gzip'; })); - $this->assertCount(2, array_filter($outdircontenttypes, function($type) { + $this->assertCount(2, array_filter($outdircontenttypes, function ($type) { return $type == 'text/plain'; })); } diff --git a/tests/tool_dataflows_flow_hash_file_test.php b/tests/tool_dataflows_flow_hash_file_test.php index aa804a4f..ff698a92 100644 --- a/tests/tool_dataflows_flow_hash_file_test.php +++ b/tests/tool_dataflows_flow_hash_file_test.php @@ -70,7 +70,7 @@ public function create_dataflow() { * * @return array */ - public function hash_file_provider() { + public static function hash_file_provider(): array { $combinations = []; $content = 'Hello World'; diff --git a/tests/tool_dataflows_flow_sql_test.php b/tests/tool_dataflows_flow_sql_test.php index de3d684c..001cb301 100644 --- a/tests/tool_dataflows_flow_sql_test.php +++ b/tests/tool_dataflows_flow_sql_test.php @@ -155,9 +155,7 @@ public function test_execute_with_expressions() { ]); $this->dataflow->save(); - $this->flow->config = Yaml::dump([ - 'sql' => 'SELECT * FROM {course} WHERE id = ${{dataflow.vars.courseid}}', - ]); + $this->flow->config = Yaml::dump(['sql' => 'SELECT * FROM {course} WHERE id = ${{dataflow.vars.courseid}}']); $this->flow->save(); ob_start(); @@ -186,9 +184,7 @@ public function test_execute_bad_sql() { // Execute a query where the sql is not well formed. // This should return null and a count of 0. - $this->flow->config = Yaml::dump([ - 'sql' => 'SELECT *', - ]); + $this->flow->config = Yaml::dump(['sql' => 'SELECT *']); $this->flow->save(); ob_start(); @@ -213,9 +209,7 @@ public function test_execute_no_records() { // Execute a query where no records are returned. // This should return null and a count of 0. - $this->flow->config = Yaml::dump([ - 'sql' => 'SELECT * FROM {course} WHERE id = -1', - ]); + $this->flow->config = Yaml::dump(['sql' => 'SELECT * FROM {course} WHERE id = -1']); $this->flow->save(); ob_start(); diff --git a/tests/tool_dataflows_flow_transformer_alter_test.php b/tests/tool_dataflows_flow_transformer_alter_test.php index 09ff0924..4f820103 100644 --- a/tests/tool_dataflows_flow_transformer_alter_test.php +++ b/tests/tool_dataflows_flow_transformer_alter_test.php @@ -29,15 +29,14 @@ */ class tool_dataflows_flow_transformer_alter_test extends \advanced_testcase { - /** Test data. */ const TEST_DATA1 = [ - [ 'a' => '1', 'b' => '1' ], - [ 'a' => '5', 'b' => '9' ], - [ 'a' => '8', 'b' => '3' ], - [ 'a' => '0', 'b' => '2' ], - [ 'a' => '0', 'b' => '1' ], - [ 'a' => '0', 'b' => '6' ], + ['a' => '1', 'b' => '1'], + ['a' => '5', 'b' => '9'], + ['a' => '8', 'b' => '3'], + ['a' => '0', 'b' => '2'], + ['a' => '0', 'b' => '1'], + ['a' => '0', 'b' => '6'], ]; /** Expression config */ @@ -49,12 +48,12 @@ class tool_dataflows_flow_transformer_alter_test extends \advanced_testcase { /** To be expected. */ const EXPECTED1 = [ - [ 'a' => 'o', 'b' => '1', 'c' => '1 1', 'd' => 2 ], - [ 'a' => 'o', 'b' => '9', 'c' => '5 9', 'd' => 14 ], - [ 'a' => 'o', 'b' => '3', 'c' => '8 3', 'd' => 11 ], - [ 'a' => 'o', 'b' => '2', 'c' => '0 2', 'd' => 2 ], - [ 'a' => 'o', 'b' => '1', 'c' => '0 1', 'd' => 1 ], - [ 'a' => 'o', 'b' => '6', 'c' => '0 6', 'd' => 6 ], + ['a' => 'o', 'b' => '1', 'c' => '1 1', 'd' => 2], + ['a' => 'o', 'b' => '9', 'c' => '5 9', 'd' => 14], + ['a' => 'o', 'b' => '3', 'c' => '8 3', 'd' => 11], + ['a' => 'o', 'b' => '2', 'c' => '0 2', 'd' => 2], + ['a' => 'o', 'b' => '1', 'c' => '0 1', 'd' => 1], + ['a' => 'o', 'b' => '6', 'c' => '0 6', 'd' => 6], ]; /** Input file name. */ @@ -63,7 +62,7 @@ class tool_dataflows_flow_transformer_alter_test extends \advanced_testcase { /** Output file name. */ const OUTPUT_FILE_NAME = 'output.json'; - /** @var string Base directory. */ + /** @var string Base directory. */ private $basedir; /** @@ -118,9 +117,9 @@ public function test_alter(array $data, array $exprs, array $expected) { * * @return array[] */ - public function alter_provider(): array { + public static function alter_provider(): array { return [ - [ self::TEST_DATA1, self::EXPRESSIONS1, self::EXPECTED1 ], + [self::TEST_DATA1, self::EXPRESSIONS1, self::EXPECTED1], ]; } @@ -164,9 +163,7 @@ private function make_dataflow(array $data, array $exprs): dataflow { $alter->name = 'filter'; $alter->type = $namespace . 'flow_transformer_alter'; $alter->depends_on([$reader]); - $alter->config = Yaml::dump([ - 'expressions' => $exprs - ]); + $alter->config = Yaml::dump(['expressions' => $exprs]); $dataflow->add_step($alter); $writer = new step(); diff --git a/tests/tool_dataflows_flow_transformer_filter_test.php b/tests/tool_dataflows_flow_transformer_filter_test.php index e46dd216..25b145ef 100644 --- a/tests/tool_dataflows_flow_transformer_filter_test.php +++ b/tests/tool_dataflows_flow_transformer_filter_test.php @@ -30,12 +30,12 @@ class tool_dataflows_flow_transformer_filter_test extends \advanced_testcase { /** Test data. */ const TEST_DATA = [ - [ 'a' => '1', 'b' => 'a_1_b' ], - [ 'a' => '5', 'b' => 'a_9_b' ], - [ 'a' => 'x', 'b' => 'a_3_b' ], - [ 'a' => '0', 'b' => 'a_2_b' ], - [ 'a' => '0', 'b' => 'a_1_b' ], - [ 'a' => '0', 'b' => 'a_6_b' ], + ['a' => '1', 'b' => 'a_1_b'], + ['a' => '5', 'b' => 'a_9_b'], + ['a' => 'x', 'b' => 'a_3_b'], + ['a' => '0', 'b' => 'a_2_b'], + ['a' => '0', 'b' => 'a_1_b'], + ['a' => '0', 'b' => 'a_6_b'], ]; /** Input file name. */ @@ -44,7 +44,7 @@ class tool_dataflows_flow_transformer_filter_test extends \advanced_testcase { /** Output file name. */ const OUTPUT_FILE_NAME = 'output.json'; - /** @var string Base directory. */ + /** @var string Base directory. */ private $basedir; /** @@ -70,7 +70,6 @@ protected function tearDown(): void { $this->basedir = null; } - /** * Tests appending to many files, declared 1:1. * @@ -100,21 +99,27 @@ public function test_filter(string $expr, array $expected) { * * @return array[] */ - public function filter_provider() { + public static function filter_provider(): array { return [ - [ 'record.a == 1', [ - [ 'a' => '1', 'b' => 'a_1_b' ], - ]], - [ "record.a == '0'", [ - [ 'a' => '0', 'b' => 'a_2_b' ], - [ 'a' => '0', 'b' => 'a_1_b' ], - [ 'a' => '0', 'b' => 'a_6_b' ], - ]], - [ "record.b >= 'a_3_b'", [ - [ 'a' => '5', 'b' => 'a_9_b' ], - [ 'a' => 'x', 'b' => 'a_3_b' ], - [ 'a' => '0', 'b' => 'a_6_b' ], - ]], + [ + 'record.a == 1', [ + ['a' => '1', 'b' => 'a_1_b'], + ], + ], + [ + "record.a == '0'", [ + ['a' => '0', 'b' => 'a_2_b'], + ['a' => '0', 'b' => 'a_1_b'], + ['a' => '0', 'b' => 'a_6_b'], + ], + ], + [ + "record.b >= 'a_3_b'", [ + ['a' => '5', 'b' => 'a_9_b'], + ['a' => 'x', 'b' => 'a_3_b'], + ['a' => '0', 'b' => 'a_6_b'], + ], + ], ]; } @@ -157,9 +162,7 @@ private function make_dataflow(string $expr): dataflow { $filter->name = 'filter'; $filter->type = $namespace . 'flow_transformer_filter'; $filter->depends_on([$reader]); - $filter->config = Yaml::dump([ - 'filter' => $expr - ]); + $filter->config = Yaml::dump(['filter' => $expr]); $dataflow->add_step($filter); $writer = new step(); diff --git a/tests/tool_dataflows_flow_transformer_regex_test.php b/tests/tool_dataflows_flow_transformer_regex_test.php index 3410cba0..611c76be 100644 --- a/tests/tool_dataflows_flow_transformer_regex_test.php +++ b/tests/tool_dataflows_flow_transformer_regex_test.php @@ -29,12 +29,11 @@ */ class tool_dataflows_flow_transformer_regex_test extends \advanced_testcase { - /** Test data. */ const TEST_DATA = [ - [ 'test' => 'hello world' ], - [ 'test' => 'hello earth' ], - [ 'test' => '' ], + ['test' => 'hello world'], + ['test' => 'hello earth'], + ['test' => ''], ]; /** Expression config */ @@ -45,9 +44,9 @@ class tool_dataflows_flow_transformer_regex_test extends \advanced_testcase { /** To be expected. */ const EXPECTED = [ - [ 'test' => 'hello world', 'regex' => 'world' ], - [ 'test' => 'hello earth', 'regex' => null ], - [ 'test' => '', 'regex' => null ], + ['test' => 'hello world', 'regex' => 'world'], + ['test' => 'hello earth', 'regex' => null], + ['test' => '', 'regex' => null], ]; /** Input file name. */ @@ -56,7 +55,7 @@ class tool_dataflows_flow_transformer_regex_test extends \advanced_testcase { /** Output file name. */ const OUTPUT_FILE_NAME = 'output.json'; - /** @var string Base directory. */ + /** @var string Base directory. */ private $basedir; /** @@ -111,9 +110,9 @@ public function test_regex(array $data, array $config, array $expected) { * * @return array[] */ - public function regex_provider(): array { + public static function regex_provider(): array { return [ - [ self::TEST_DATA, self::CONFIG, self::EXPECTED ], + [self::TEST_DATA, self::CONFIG, self::EXPECTED], [ [['test' => '1,2,3,4,5,6,7,8,9']], [ diff --git a/tests/tool_dataflows_gpg_test.php b/tests/tool_dataflows_gpg_test.php index 98b0f415..176bf5b4 100644 --- a/tests/tool_dataflows_gpg_test.php +++ b/tests/tool_dataflows_gpg_test.php @@ -29,6 +29,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class tool_dataflows_gpg_test extends \advanced_testcase { + /** * Set up before each test */ @@ -61,7 +62,7 @@ public function test_has_sideeffect(string $file, bool $expected) { Yaml::dump([ 'dir1' => 'everywhere', 'dir2' => '/anywhere', - 'dir3' => 'sftp://somewhere' + 'dir3' => 'sftp://somewhere', ]), 'tool_dataflows' ); @@ -76,7 +77,7 @@ public function test_has_sideeffect(string $file, bool $expected) { * * @return array[] */ - public function has_sideeffect_provider(): array { + public static function has_sideeffect_provider(): array { return [ ['test.txt', false], ['/test.txt', true], diff --git a/tests/tool_dataflows_helper_test.php b/tests/tool_dataflows_helper_test.php index 4dc7f3cb..364c05c4 100644 --- a/tests/tool_dataflows_helper_test.php +++ b/tests/tool_dataflows_helper_test.php @@ -51,7 +51,7 @@ public function test_is_relative(string $path, bool $expected) { * * @return array[] */ - public function is_relative_provider(): array { + public static function is_relative_provider(): array { global $CFG; return [ ['one/path', true], @@ -81,7 +81,7 @@ public function test_is_scheme(string $scheme, string $path, bool $expected) { * * @return array[] */ - public function is_scheme_provider(): array { + public static function is_scheme_provider(): array { return [ ['file', 'one/path', false], ['file', '/one/path', false], @@ -113,7 +113,7 @@ public function test_get_permitted_dirs(string $data, array $expected) { * * @return array[] */ - public function dir_provider(): array { + public static function dir_provider(): array { global $CFG; return [ ['', []], @@ -157,7 +157,7 @@ public function test_path_validate(string $path, bool $expected) { * * @return array[] */ - public function path_validate_provider(): array { + public static function path_validate_provider(): array { return [ ['one/path', true], ['/one/path', false], @@ -185,7 +185,7 @@ public function test_bash_escape(string $value, string $expected) { * * @return \string[][] */ - public function bash_escape_provider(): array { + public static function bash_escape_provider(): array { return [ ['', "''"], ['something with a space', "'something with a space'"], @@ -210,7 +210,7 @@ public function test_extract_http_headers(string $content, $expected) { * * @return array[] */ - public function extract_http_headers_provider(): array { + public static function extract_http_headers_provider(): array { return [ ['', []], ['0', false], diff --git a/tests/tool_dataflows_json_reader_test.php b/tests/tool_dataflows_json_reader_test.php index 500d39f4..d6ff8f3b 100644 --- a/tests/tool_dataflows_json_reader_test.php +++ b/tests/tool_dataflows_json_reader_test.php @@ -35,6 +35,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class tool_dataflows_json_reader_test extends \advanced_testcase { + /** * Set up before each test */ @@ -202,7 +203,7 @@ public function test_reader_json_sort_function() { $sorteduserarray = [ $this->users[1], $this->users[2], - $this->users[0] + $this->users[0], ]; $writer->config = Yaml::dump([ @@ -281,7 +282,7 @@ public function test_json_sort_order() { $reversesorteduserarray = [ $this->users[0], $this->users[2], - $this->users[1] + $this->users[1], ]; $writer->config = Yaml::dump([ diff --git a/tests/tool_dataflows_parser_test.php b/tests/tool_dataflows_parser_test.php index f8517609..98cdcbec 100644 --- a/tests/tool_dataflows_parser_test.php +++ b/tests/tool_dataflows_parser_test.php @@ -16,7 +16,6 @@ namespace tool_dataflows; - /** * Tests the parser. * @@ -46,7 +45,7 @@ public function test_find_variable_names(string $expression, array $expected) { * * @return array[] */ - public function find_variable_names_provider(): array { + public static function find_variable_names_provider(): array { return [ ['', []], ['${{a}}', ['a']], @@ -79,7 +78,7 @@ public function test_parser_functions(string $expression, array $variables, $exp * * @return array of data */ - public function parser_functions_data_provider() { + public static function parser_functions_data_provider(): array { $example = [ 'a' => [ 'b' => null, diff --git a/tests/tool_dataflows_permitted_dir_test.php b/tests/tool_dataflows_permitted_dir_test.php index c2a14565..c53b8af5 100644 --- a/tests/tool_dataflows_permitted_dir_test.php +++ b/tests/tool_dataflows_permitted_dir_test.php @@ -59,7 +59,7 @@ public function test_validate_valid(string $data) { * * @return \string[][] */ - public function valid_data_provider(): array { + public static function valid_data_provider(): array { return [ [''], ['/* A comment */'], @@ -91,7 +91,7 @@ public function test_validate_invalid(string $data, string $error) { * * @return \string[][] */ - public function invalid_data_provider(): array { + public static function invalid_data_provider(): array { return [ ['/tmp/* A comment', 'path_invalid'], ['http://tmp', 'path_invalid'], diff --git a/tests/tool_dataflows_remove_file_test.php b/tests/tool_dataflows_remove_file_test.php index 1200b3f5..46a8c15c 100644 --- a/tests/tool_dataflows_remove_file_test.php +++ b/tests/tool_dataflows_remove_file_test.php @@ -65,7 +65,7 @@ public function test_has_sideeffect(string $file, bool $expected) { Yaml::dump([ 'dir1' => 'everywhere', 'dir2' => '/anywhere', - 'dir3' => 'sftp://somewhere' + 'dir3' => 'sftp://somewhere', ]), 'tool_dataflows' ); @@ -80,7 +80,7 @@ public function test_has_sideeffect(string $file, bool $expected) { * * @return array[] */ - public function has_sideeffect_provider(): array { + public static function has_sideeffect_provider(): array { return [ ['test.txt', false], ['/test.txt', true], @@ -138,9 +138,7 @@ private function make_dataflow(string $file): dataflow { $step = new step(); $step->name = 'hoover'; $step->type = connector_remove_file::class; - $step->config = Yaml::dump([ - 'file' => $file, - ]); + $step->config = Yaml::dump(['file' => $file]); $dataflow->add_step($step); return $dataflow; diff --git a/tests/tool_dataflows_sftp_test.php b/tests/tool_dataflows_sftp_test.php index ba74b6f6..bbbf9717 100644 --- a/tests/tool_dataflows_sftp_test.php +++ b/tests/tool_dataflows_sftp_test.php @@ -87,7 +87,7 @@ public function test_has_sideeffect(string $file, bool $expected) { * * @return array[] */ - public function sftp_list_constraints_provider(): array { + public static function sftp_list_constraints_provider(): array { return [ [ ['relativepath', 'alpha', 0, null, false, '', '*.csv'], @@ -165,7 +165,7 @@ public function test_list_constraints_on_sftp_files($params, $expected) { * * @return array[] */ - public function has_sideeffect_provider(): array { + public static function has_sideeffect_provider(): array { return [ ['test.txt', false], ['/test.txt', true], diff --git a/tests/tool_dataflows_step_test.php b/tests/tool_dataflows_step_test.php index 2aff7e23..52309158 100644 --- a/tests/tool_dataflows_step_test.php +++ b/tests/tool_dataflows_step_test.php @@ -65,7 +65,7 @@ public function access_validate_alias(string $alias) { * * @return array[] */ - public function alias_validation_provider(): array { + public static function alias_validation_provider(): array { return [ ['simplename', true], ['snake_name', true], @@ -117,7 +117,7 @@ public function test_set_name_effects_alias(string $name, string $expectedalias) * * @return \string[][] */ - public function set_name_effects_alias_provider(): array { + public static function set_name_effects_alias_provider(): array { return [ ['simplename', 'simplename'], ['snake_name', 'snake_name'], diff --git a/tests/tool_dataflows_stream_writer_test.php b/tests/tool_dataflows_stream_writer_test.php index 705d9eb1..cc975525 100644 --- a/tests/tool_dataflows_stream_writer_test.php +++ b/tests/tool_dataflows_stream_writer_test.php @@ -106,7 +106,7 @@ public function test_writer_json($inputdata, $isdryrun, $prettyprint) { * * @return array */ - public function data_provider(): array { + public static function data_provider(): array { return [ [[['a' => 1, 'b' => 2, 'c' => 3], ['a' => 4, 'b' => 5, 'c' => 6]], false, true], [[['a' => 1], ['b' => 5], ['c' => 6]], true, false], diff --git a/tests/tool_dataflows_test.php b/tests/tool_dataflows_test.php index c94cc1a4..50ce0010 100644 --- a/tests/tool_dataflows_test.php +++ b/tests/tool_dataflows_test.php @@ -301,7 +301,7 @@ public function test_dataflows_import_cron_trigger() { $this->assertCount(3, (array) $steps); // Find the CRON step. - $cronstep = current(array_filter((array) $steps, function($step) { + $cronstep = current(array_filter((array) $steps, function ($step) { return $step->alias == 'cron'; })); $this->assertNotEmpty($cronstep); diff --git a/tests/tool_dataflows_upgrade_test.php b/tests/tool_dataflows_upgrade_test.php index a955017e..2ae450f4 100644 --- a/tests/tool_dataflows_upgrade_test.php +++ b/tests/tool_dataflows_upgrade_test.php @@ -29,6 +29,7 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class tool_dataflows_upgrade_test extends \advanced_testcase { + /** * Test config upgrade helper. * diff --git a/tests/tool_dataflows_variables_new_test.php b/tests/tool_dataflows_variables_new_test.php index 79a53346..c374150f 100644 --- a/tests/tool_dataflows_variables_new_test.php +++ b/tests/tool_dataflows_variables_new_test.php @@ -245,7 +245,7 @@ public function test_types(var_object_for_testing $vars, $value) { * * @return array[] */ - public function types_provider() { + public static function types_provider(): array { $vars = new var_object_for_testing('one'); $vars->set('d', '${{a}}'); return [ diff --git a/tests/tool_dataflows_web_service_flow_test.php b/tests/tool_dataflows_web_service_flow_test.php index 3219bae1..969446e8 100644 --- a/tests/tool_dataflows_web_service_flow_test.php +++ b/tests/tool_dataflows_web_service_flow_test.php @@ -20,8 +20,6 @@ require_once(__DIR__ . '/application_trait.php'); - - use Symfony\Component\ExpressionLanguage\ExpressionLanguage; use Symfony\Component\Yaml\Yaml; use tool_dataflows\dataflow;