Skip to content

Commit

Permalink
Making 3.11 compliant.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchurchward committed May 26, 2021
1 parent b782b33 commit f8722a6
Show file tree
Hide file tree
Showing 37 changed files with 312 additions and 172 deletions.
122 changes: 122 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Moodle plugin CI
on: [push, pull_request]

jobs:
test:
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
include:
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.3'
moodle-branch: 'MOODLE_310_STABLE'
database: 'mariadb'
node: '14.15.0'
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
database: 'pgsql'
node: '14.15.0'
- php: '7.3'
moodle-branch: 'MOODLE_310_STABLE'
database: 'pgsql'
node: '14.15.0'

services:
postgres:
image: postgres
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432

mariadb:
image: mariadb
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: plugin

- name: Install node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: zip, gd, mbstring, pgsql, mysqli

- name: Deploy moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
- name: Install Moodle
# Need explicit IP to stop mysql client fail on attempt to use unix socket.
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
IGNORE_NAMES: 'mobile_*.mustache'

- name: phplint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: phpcpd
if: ${{ always() }}
run: moodle-plugin-ci phpcpd || true

- name: phpmd
if: ${{ always() }}
run: moodle-plugin-ci phpmd

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

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

- name: savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints

- name: mustache
if: ${{ always() }}
run: moodle-plugin-ci mustache

- name: grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt

- name: phpunit
if: ${{ always() }}
run: moodle-plugin-ci phpunit

- name: behat
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function define_my_steps() {
* Code the transformations to perform in the activity in
* order to get transportable (encoded) links
*/
static public function encode_content_links($content) {
public static function encode_content_links($content) {
global $CFG;

$base = preg_quote($CFG->wwwroot, "/");
Expand Down
4 changes: 2 additions & 2 deletions backup/moodle2/backup_questionnaire_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,10 @@ protected function define_structure() {
// Define id annotations.
$response->annotate_ids('user', 'userid');
}
// Define file annotations
// Define file annotations.
$questionnaire->annotate_files('mod_questionnaire', 'intro', null); // This file area hasn't itemid.

$survey->annotate_files('mod_questionnaire', 'info', 'id'); // By survey->id
$survey->annotate_files('mod_questionnaire', 'info', 'id'); // By survey->id.
$survey->annotate_files('mod_questionnaire', 'thankbody', 'id'); // By survey->id.

$question->annotate_files('mod_questionnaire', 'question', 'id'); // By question->id.
Expand Down
8 changes: 4 additions & 4 deletions backup/moodle2/restore_questionnaire_activity_task.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected function define_my_steps() {
* Define the contents in the activity that must be
* processed by the link decoder
*/
static public function define_decode_contents() {
public static function define_decode_contents() {
$contents = array();

$contents[] = new restore_decode_content('questionnaire', array('intro'), 'questionnaire');
Expand All @@ -66,7 +66,7 @@ static public function define_decode_contents() {
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
static public function define_decode_rules() {
public static function define_decode_rules() {
$rules = array();

$rules[] = new restore_decode_rule('QUESTIONNAIREVIEWBYID', '/mod/questionnaire/view.php?id=$1', 'course_module');
Expand All @@ -82,7 +82,7 @@ static public function define_decode_rules() {
* questionnaire logs. It must return one array
* of {@link restore_log_rule} objects
*/
static public function define_restore_log_rules() {
public static function define_restore_log_rules() {
$rules = array();

$rules[] = new restore_log_rule('questionnaire', 'add', 'view.php?id={course_module}', '{questionnaire}');
Expand All @@ -105,7 +105,7 @@ static public function define_restore_log_rules() {
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
static public function define_restore_log_rules_for_course() {
public static function define_restore_log_rules_for_course() {
$rules = array();

// Fix old wrong uses (missing extension).
Expand Down
4 changes: 2 additions & 2 deletions classes/edit_question_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ public function definition() {
$question->required = $SESSION->questionnaire->required;
}
if (!isset($question->type_id)) {
print_error('undefinedquestiontype', 'questionnaire');
throw new \moodle_exception('undefinedquestiontype', 'mod_questionnaire');
}

// Each question can provide its own form elements to the provided form, or use the default ones.
if (!$question->edit_form($this, $questionnaire)) {
print_error("Question type had an unknown error in the edit_form method.");
throw new \moodle_exception('Question type had an unknown error in the edit_form method.', 'mod_questionnaire');
}
}

Expand Down
2 changes: 1 addition & 1 deletion classes/question/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function supports_mobile() {
*/
protected function form_preprocess_choicedata($formdata) {
if (empty($formdata->allchoices)) {
print_error(get_string('enterpossibleanswers', 'questionnaire'));
throw new \moodle_exception('enterpossibleanswers', 'mod_questionnaire');
} else {
// Sanity checks for min and max checked boxes.
$allchoices = $formdata->allchoices;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @copyright 2019, onwards Poet
*/

namespace mod_questionnaire\question\choice;
namespace mod_questionnaire\question;
defined('MOODLE_INTERNAL') || die();

class choice {
Expand Down Expand Up @@ -132,7 +132,7 @@ public function delete_from_db() {
* @param string $content
* @return bool
*/
static public function content_is_other_choice($content) {
public static function content_is_other_choice($content) {
return (strpos($content, '!other') === 0);
}

Expand All @@ -152,7 +152,7 @@ public function is_other_choice() {
* @return string | bool
* @throws \coding_exception
*/
static public function content_other_choice_display($content) {
public static function content_other_choice_display($content) {
if (!self::content_is_other_choice($content)) {
return false;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public function is_named_degree_choice() {
* @param int $choiceid
* @return string
*/
static public function id_other_choice_name($choiceid) {
public static function id_other_choice_name($choiceid) {
return 'o' . $choiceid;
}

Expand Down
2 changes: 1 addition & 1 deletion classes/question/drop.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
namespace mod_questionnaire\question;
defined('MOODLE_INTERNAL') || die();
use \html_writer;
use mod_questionnaire\question\choice\choice;
use mod_questionnaire\question\choice;

class drop extends question {

Expand Down
24 changes: 12 additions & 12 deletions classes/question/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ abstract public function helpname();
* @var object $context The context for the question.
* @return A question object.
*/
static public function question_builder($qtype, $qdata = null, $context = null) {
public static function question_builder($qtype, $qdata = null, $context = null) {
$qclassname = '\\mod_questionnaire\\question\\'.self::qtypename($qtype);
$qid = 0;
if (!empty($qdata) && is_array($qdata)) {
Expand All @@ -204,7 +204,7 @@ static public function question_builder($qtype, $qdata = null, $context = null)
* @param $qtype
* @return string
*/
static public function qtypename($qtype) {
public static function qtypename($qtype) {
if (array_key_exists($qtype, self::$qtypenames)) {
return self::$qtypenames[$qtype];
} else {
Expand All @@ -216,7 +216,7 @@ static public function qtypename($qtype) {
* Return all of the different question type names.
* @return array
*/
static public function qtypenames() {
public static function qtypenames() {
return self::$qtypenames;
}

Expand All @@ -235,7 +235,7 @@ private function get_choices() {

if ($choices = $DB->get_records('questionnaire_quest_choice', ['question_id' => $this->id], 'id ASC')) {
foreach ($choices as $choice) {
$this->choices[$choice->id] = choice\choice::create_from_data($choice);
$this->choices[$choice->id] = \mod_questionnaire\question\choice::create_from_data($choice);
}
} else {
$this->choices = [];
Expand Down Expand Up @@ -704,7 +704,7 @@ public function delete_choice($choice) {
} else {
$cid = $choice->id;
}
if (\mod_questionnaire\question\choice\choice::delete_from_db_by_id($cid)) {
if (\mod_questionnaire\question\choice::delete_from_db_by_id($cid)) {
unset($this->choices[$cid]);
} else {
$retvalue = false;
Expand Down Expand Up @@ -894,7 +894,7 @@ public function questionstart_survey_display($qnum, $response=null) {
if ($response instanceof \mod_questionnaire\responsetype\response\response) {
$skippedquestion = !isset($response->answers[$this->id]);
} else {
$skippedquestion = !empty($response) && !array_key_exists('q'.$this->id, $response);
$skippedquestion = !empty($response) && !isset($response->{'q'.$this->id});
}

// If we are on report page and this questionnaire has dependquestions and this question was skipped.
Expand Down Expand Up @@ -972,7 +972,7 @@ public function edit_form(edit_question_form $form, questionnaire $questionnaire
$this->form_required($mform);
$this->form_length($mform);
$this->form_precise($mform);
$this->form_question_text($mform, $form->_customdata['modcontext']);
$this->form_question_text($mform, ($form->_customdata['modcontext'] ?? ''));

if ($this->has_choices()) {
// This is used only by the question editing form.
Expand Down Expand Up @@ -1228,7 +1228,7 @@ protected function form_extradata(\MoodleQuickForm $mform, $helpname = '') {
* @param int $value
* @return \MoodleQuickForm
*/
static public function form_length_hidden(\MoodleQuickForm $mform, $value = 0) {
public static function form_length_hidden(\MoodleQuickForm $mform, $value = 0) {
$mform->addElement('hidden', 'length', $value);
$mform->setType('length', PARAM_INT);
return $mform;
Expand All @@ -1241,7 +1241,7 @@ static public function form_length_hidden(\MoodleQuickForm $mform, $value = 0) {
* @return \MoodleQuickForm
* @throws \coding_exception
*/
static public function form_length_text(\MoodleQuickForm $mform, $helpname = '', $value = 0) {
public static function form_length_text(\MoodleQuickForm $mform, $helpname = '', $value = 0) {
$mform->addElement('text', 'length', get_string($helpname, 'questionnaire'), ['size' => '1'], $value);
$mform->setType('length', PARAM_INT);
if (!empty($helpname)) {
Expand All @@ -1255,7 +1255,7 @@ static public function form_length_text(\MoodleQuickForm $mform, $helpname = '',
* @param int $value
* @return \MoodleQuickForm
*/
static public function form_precise_hidden(\MoodleQuickForm $mform, $value = 0) {
public static function form_precise_hidden(\MoodleQuickForm $mform, $value = 0) {
$mform->addElement('hidden', 'precise', $value);
$mform->setType('precise', PARAM_INT);
return $mform;
Expand All @@ -1268,7 +1268,7 @@ static public function form_precise_hidden(\MoodleQuickForm $mform, $value = 0)
* @return \MoodleQuickForm
* @throws \coding_exception
*/
static public function form_precise_text(\MoodleQuickForm $mform, $helpname = '', $value = 0) {
public static function form_precise_text(\MoodleQuickForm $mform, $helpname = '', $value = 0) {
$mform->addElement('text', 'precise', get_string($helpname, 'questionnaire'), ['size' => '1']);
$mform->setType('precise', PARAM_INT);
if (!empty($helpname)) {
Expand Down Expand Up @@ -1370,7 +1370,7 @@ public function form_update($formdata, $questionnaire) {
}

while ($nidx < $newcount) {
// New choices...
// New choices.
$choicerecord = new \stdClass();
$choicerecord->question_id = $this->qid;
$choicerecord->content = trim($newchoices[$nidx]);
Expand Down
3 changes: 1 addition & 2 deletions classes/question/radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/

namespace mod_questionnaire\question;
use mod_questionnaire\question\choice\choice;

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

Expand Down Expand Up @@ -84,7 +83,7 @@ public function supports_feedback() {
*
*/
protected function question_survey_display($response, $dependants=[], $blankquestionnaire=false) {
// Radio buttons
// Radio buttons.
global $idcounter; // To make sure all radio buttons have unique ids. // JR 20 NOV 2007.

$otherempty = false;
Expand Down
Loading

0 comments on commit f8722a6

Please sign in to comment.