Skip to content

Commit

Permalink
Merge pull request #15 from stronk7/phpcs_phpdoc_fixes
Browse files Browse the repository at this point in the history
Phpcs phpdoc fixes
  • Loading branch information
mudrd8mz authored Apr 25, 2024
2 parents 1a27649 + f10ecaf commit 45852c9
Show file tree
Hide file tree
Showing 24 changed files with 273 additions and 239 deletions.
58 changes: 33 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

services:
mysql:
Expand All @@ -18,13 +18,27 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [8.0, 8.1]
moodle-branch: [MOODLE_401_STABLE, MOODLE_402_STABLE, master]
database: [mysqli]
include:
# Always the max supported PHP version on every branch.
- php: 8.3
moodle-branch: main
database: mysqli
- php: 8.3
moodle-branch: MOODLE_404_STABLE
database: mysqli
- php: 8.2
moodle-branch: MOODLE_403_STABLE
database: mysqli
- php: 8.2
moodle-branch: MOODLE_402_STABLE
database: mysqli
- php: 8.1
moodle-branch: MOODLE_401_STABLE
database: mysqli

steps:
- name: Check out repository code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
path: plugin

Expand Down Expand Up @@ -53,48 +67,42 @@ jobs:
IGNORE_PATHS: tests/fixtures

- name: PHP Lint
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci phplint

- name: PHP Copy/Paste Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: PHP Mess Detector
continue-on-error: true # This step will show errors but will not fail
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpmd

- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker

# Disabled, it needs real fixes.
#- name: Moodle PHPDoc Checker
# if: ${{ always() }}
# run: moodle-plugin-ci phpdoc
if: ${{ !cancelled() }}
run: moodle-plugin-ci codechecker --max-warnings 0

- name: Validating
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci validate

- name: Check upgrade savepoints
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci savepoints

- name: Mustache Lint
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci mustache

- name: Grunt
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci grunt --max-lint-warnings 0

- name: PHPUnit tests
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci phpunit

- name: Behat features
if: ${{ always() }}
if: ${{ !cancelled() }}
run: moodle-plugin-ci behat --profile chrome

- name: Mark cancelled jobs as failed.
if: ${{ cancelled() }}
run: exit 1
24 changes: 12 additions & 12 deletions admin/jabber-aliases-search.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -12,7 +12,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* AJAX search for the user on jabber aliases search..
Expand All @@ -21,7 +21,7 @@
*
* @package local_chatlogs
* @copyright 2012 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

define('AJAX_SCRIPT', true);
Expand All @@ -44,7 +44,7 @@
$response = new stdClass();
$response->status = 'ok';
$response->query = $query;
$response->results = array();
$response->results = [];

if (!empty($query)) {

Expand All @@ -63,33 +63,33 @@
FROM {user}
WHERE ".$DB->sql_like("firstname", "?", false, false)."
AND ".$DB->sql_like("lastname", "?", false, false);
$params = array(
$params = [
$DB->sql_like_escape($parts[0]).'%',
$DB->sql_like_escape($parts[1]).'%'
);
$DB->sql_like_escape($parts[1]).'%',
];
} else {
$sql = "SELECT id, firstname, lastname, email
FROM {user}
WHERE ".$DB->sql_like("firstname", "?", false, false)."
OR ".$DB->sql_like("lastname", "?", false, false)."
OR ".$DB->sql_like("email", "?", false, false);
$params = array(
$params = [
'%'.$DB->sql_like_escape($query).'%',
'%'.$DB->sql_like_escape($query).'%',
'%'.$DB->sql_like_escape($query).'%'
);
'%'.$DB->sql_like_escape($query).'%',
];
}

$rs = $DB->get_recordset_sql($sql, $params, 0, 10);

foreach ($rs as $r) {
$response->results[] = (object)array(
$response->results[] = (object)[
'userid' => $r->id,
'firstname' => $r->firstname,
'lastname' => $r->lastname,
'email' => $r->email,
'signature' => sprintf('%s <%s>', fullname($r), $r->email),
);
];
}

$rs->close();
Expand Down
46 changes: 23 additions & 23 deletions admin/jabber-aliases.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -12,7 +12,7 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* Displays the list of jabber users and lets the user to assign them to real user accounts
Expand All @@ -21,7 +21,7 @@
*
* @package local_chatlogs
* @copyright 2012 Dan Poltawski <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require(dirname(dirname(dirname(dirname(__FILE__)))).'/config.php');
Expand All @@ -45,7 +45,7 @@
if (!empty($userid)) {
$status = link_jabberid_to_user($jabberid, $userid);
if ($status === false) {
print_error('failed');
throw new moodle_exception('failed');
}
}
redirect($PAGE->url);
Expand All @@ -64,32 +64,32 @@

$table = new html_table();
$table->id = 'aliaseseditor';
$table->head = array(
$table->head = [
get_string('jabberfullname', 'local_chatlogs'),
get_string('jabberid', 'local_chatlogs'),
get_string('jabberaliasesassign', 'local_chatlogs'),
);
];


foreach ($rs as $record) {
$table->data[] = array(
html_writer::tag('div', s($record->nickname), array('class' => 'aliasdata-authorname')),
html_writer::tag('div', s($record->fromemail), array('class' => 'aliasdata-authoremail')),
$table->data[] = [
html_writer::tag('div', s($record->nickname), ['class' => 'aliasdata-authorname']),
html_writer::tag('div', s($record->fromemail), ['class' => 'aliasdata-authoremail']),
html_writer::tag('form',
html_writer::tag('div',
html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'jabbernick', 'value' => $record->nickname)).
html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'jabberid', 'value' => $record->fromemail)).
html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())).
html_writer::empty_tag('input', array('type' => 'text', 'name' => 'search', 'class' => 'aliasdata-search',
'maxlength' => 100, 'size' => 50)).
html_writer::empty_tag('input', array('type' => 'text', 'name' => 'userid', 'class' => 'aliasdata-userid',
'maxlength' => 100, 'size' => 5)).
html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('submit'))).
html_writer::empty_tag('input', array('type' => 'reset', 'value' => get_string('reset'))).
html_writer::tag('span', ' ', array('class' => 'aliasdata-icon'))
html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'jabbernick', 'value' => $record->nickname]).
html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'jabberid', 'value' => $record->fromemail]).
html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]).
html_writer::empty_tag('input', ['type' => 'text', 'name' => 'search', 'class' => 'aliasdata-search',
'maxlength' => 100, 'size' => 50]).
html_writer::empty_tag('input', ['type' => 'text', 'name' => 'userid', 'class' => 'aliasdata-userid',
'maxlength' => 100, 'size' => 5]).
html_writer::empty_tag('input', ['type' => 'submit', 'value' => get_string('submit')]).
html_writer::empty_tag('input', ['type' => 'reset', 'value' => get_string('reset')]).
html_writer::tag('span', ' ', ['class' => 'aliasdata-icon'])
),
array('method' => 'post', 'action' => $PAGE->url->out()))
);
['method' => 'post', 'action' => $PAGE->url->out()]),
];
}
echo html_writer::table($table);
$rs->close();
Expand All @@ -105,11 +105,11 @@
function link_jabberid_to_user($jabberid, $userid) {
global $DB;

if (is_null($userid) or is_null($jabberid)) {
if (is_null($userid) || is_null($jabberid)) {
throw new coding_exception('NULL parameter values not allowed here');
}

$record = $DB->get_record('local_chatlogs_participants', array('fromemail' => $jabberid));
$record = $DB->get_record('local_chatlogs_participants', ['fromemail' => $jabberid]);

if ($record) {
$record->userid = $userid;
Expand Down
28 changes: 10 additions & 18 deletions adminlib.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -12,33 +12,25 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* Admin tree class for lazyloading config box
*
* @package local_chatlogs
* @copyright 2012 Dan Poltawski <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* admin_setting_configselect for the seleted cohort
* simply so we can lazy-load the choices.
* admin_setting_configselect for the seleted cohort, so we can lazy-load the choices.
*
* @package local_chatlogs
* @copyright Dan Poltawski <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class local_chatlogs_cohort_selector extends admin_setting_configselect {

/** Lazy-load the available choices for the select box */
/**
* Lazy-load the available choices for the select box
*/
public function load_choices() {
global $DB;

$this->choices = array(0 => get_string('none'));
if ($cohorts = $DB->get_records_menu('cohort', array('contextid' => context_system::instance()->id), 'name', 'id, name')) {
$this->choices = [0 => get_string('none')];
if ($cohorts = $DB->get_records_menu('cohort', ['contextid' => context_system::instance()->id], 'name', 'id, name')) {
foreach ($cohorts as $key => $value) {
$this->choices[$key] = $value;
}
Expand Down
16 changes: 7 additions & 9 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -12,21 +12,19 @@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* Defines {@link \local_chatlogs\privacy\provider} class.
* Defines {@see \local_chatlogs\privacy\provider} class.
*
* @package local_chatlogs
* @category privacy
* @copyright 2018 David Mudrák <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace local_chatlogs\privacy;

defined('MOODLE_INTERNAL') || die();

use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\contextlist;
Expand All @@ -38,7 +36,7 @@
* Privacy API implementation for the Developer chat plugin.
*
* @copyright 2018 David Mudrák <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
\core_privacy\local\metadata\provider,
Expand All @@ -50,7 +48,7 @@ class provider implements
* @param collection $collection Collection of items to add metadata to.
* @return collection Collection with our added items.
*/
public static function get_metadata(collection $collection) : collection {
public static function get_metadata(collection $collection): collection {

$collection->add_database_table('local_chatlogs_messages', [
'conversationid' => 'privacy:metadata:db:messages:conversationid',
Expand All @@ -76,7 +74,7 @@ public static function get_metadata(collection $collection) : collection {
* @param int $userid ID of the user.
* @return contextlist List of contexts containing the user's personal data.
*/
public static function get_contexts_for_userid(int $userid) : contextlist {
public static function get_contexts_for_userid(int $userid): contextlist {

$contextlist = new contextlist();
$contextlist->add_system_context();
Expand Down
Loading

0 comments on commit 45852c9

Please sign in to comment.