Skip to content

Commit

Permalink
fix: phpcs fixes
Browse files Browse the repository at this point in the history
- update providers to static functions
- @param phpdocs
- phpdocs, trait docs, static providers
  • Loading branch information
keevan committed Oct 14, 2024
1 parent e9c0230 commit 1234567
Show file tree
Hide file tree
Showing 59 changed files with 195 additions and 203 deletions.
8 changes: 3 additions & 5 deletions classes/admin/readonly_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows\admin;

use tool_dataflows\manager;

/**
* Read only trait
Expand All @@ -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 {

/**
Expand Down
2 changes: 1 addition & 1 deletion classes/external/trigger_dataflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
])
]),
]);
}

Expand Down
2 changes: 1 addition & 1 deletion classes/form/dataflow_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
);
Expand Down
2 changes: 1 addition & 1 deletion classes/form/import_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
);
Expand Down
2 changes: 1 addition & 1 deletion classes/form/step_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
);
Expand Down
22 changes: 19 additions & 3 deletions classes/local/execution/engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -322,6 +325,7 @@ public function is_aborted(): bool {

/**
* Initialises the dataflow.
* @return void
*/
public function initialise() {
$this->status_check(self::STATUS_NEW);
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Expand All @@ -515,6 +523,7 @@ public function execute_step() {

/**
* Finalises the execution. Any remaining resources should be released.
* @return void
*/
public function finalise() {
try {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions classes/local/step/abort_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows\local\step;

/**
* Abort Step ..Trait
*
Expand All @@ -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 {

/**
Expand Down
1 change: 1 addition & 0 deletions classes/local/step/append_file_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
11 changes: 5 additions & 6 deletions classes/local/step/compression_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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'));
}
]
},
],
];
}

Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion classes/local/step/connector_debug_file_display.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,3 @@ public function form_add_custom_inputs(\MoodleQuickForm &$mform) {
}
}


1 change: 1 addition & 0 deletions classes/local/step/copy_file_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
30 changes: 15 additions & 15 deletions classes/local/step/directory_file_list_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]
);

Expand Down Expand Up @@ -176,14 +176,14 @@ public function validate_for_run() {
/**
* Apply various constraints/transforms to the list of files
*
* @param array $filelist
* @param string $returnvalue
* @param string $sort
* @param int $offset
* @param int $limit
* @param bool $includedir
* @param string $basepath
* @param string $pattern
* @param array $filelist
* @param string $returnvalue
* @param string $sort
* @param int $offset
* @param ?int $limit
* @param bool $includedir
* @param string $basepath
* @param ?string $pattern
* @return array new file list
*/
public function apply_list_constraints(
Expand All @@ -194,7 +194,7 @@ public function apply_list_constraints(
?int $limit,
bool $includedir,
string $basepath,
string $pattern = null
?string $pattern = null
): array {
// Apply filter for excluding directories/folders.
// This is not related to recursive lookups in any way.
Expand Down
2 changes: 1 addition & 1 deletion classes/local/step/file_put_content_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -101,7 +102,6 @@ public function validate_for_run() {
return $errors ?: true;
}


/**
* Executes the step
*
Expand Down
1 change: 1 addition & 0 deletions classes/local/step/gpg_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 4 additions & 5 deletions classes/local/step/hash_file_trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

namespace tool_dataflows\local\step;

use tool_dataflows\helper;

/**
* Hash file flow step
*
Expand All @@ -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 {

/**
Expand Down
Loading

0 comments on commit 1234567

Please sign in to comment.