Skip to content

Commit e909fd8

Browse files
Martinlaurentdavid
authored andcommitted
Refactoring the plugin and fix ci issues
* Correction 'Error and warnings' phpcs, fix oval btn and validation of behat tests * Adding github folder and getting rid of .travis.yml * Fixing pull request commands * Fix behat test file so it works on moodle 3 * Validating Grunt and PHPDoc tests * Added status badge to README * Last try to fix PhpDoc * Fix PhpDoc * Fix PhpDoc another time
1 parent 0606cec commit e909fd8

File tree

11 files changed

+158
-96
lines changed

11 files changed

+158
-96
lines changed

.github/workflows/main.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: Moodle Plugin CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test:
7+
runs-on: ubuntu-22.04
8+
9+
services:
10+
postgres:
11+
image: postgres:12
12+
env:
13+
POSTGRES_USER: 'postgres'
14+
POSTGRES_HOST_AUTH_METHOD: 'trust'
15+
ports:
16+
- 5432:5432
17+
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3
18+
mariadb:
19+
image: mariadb:10
20+
env:
21+
MYSQL_USER: 'root'
22+
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
23+
MYSQL_CHARACTER_SET_SERVER: "utf8mb4"
24+
MYSQL_COLLATION_SERVER: "utf8mb4_unicode_ci"
25+
26+
ports:
27+
- 3306:3306
28+
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3
29+
30+
strategy:
31+
fail-fast: false
32+
matrix:
33+
php: ['7.4', '8.0']
34+
moodle-branch: ['MOODLE_311_STABLE','MOODLE_400_STABLE']
35+
database: [pgsql, mariadb]
36+
37+
steps:
38+
- name: Check out repository code
39+
uses: actions/checkout@v2
40+
with:
41+
path: plugin
42+
43+
- name: Setup PHP ${{ matrix.php }}
44+
uses: shivammathur/setup-php@v2
45+
with:
46+
php-version: ${{ matrix.php }}
47+
extensions: ${{ matrix.extensions }}
48+
ini-values: max_input_vars=5000
49+
# none to use phpdbg fallback. Specify pcov (Moodle 3.10 and up) or xdebug to use them instead.
50+
coverage: none
51+
52+
- name: Initialise moodle-plugin-ci
53+
run: |
54+
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
55+
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
56+
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
57+
sudo locale-gen en_AU.UTF-8
58+
echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV
59+
60+
- name: Install moodle-plugin-ci
61+
run: |
62+
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
63+
env:
64+
DB: ${{ matrix.database }}
65+
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
66+
67+
- name: PHP Lint
68+
if: ${{ always() }}
69+
run: moodle-plugin-ci phplint
70+
71+
- name: PHP Copy/Paste Detector
72+
continue-on-error: true # This step will show errors but will not fail
73+
if: ${{ always() }}
74+
run: moodle-plugin-ci phpcpd
75+
76+
- name: PHP Mess Detector
77+
continue-on-error: true # This step will show errors but will not fail
78+
if: ${{ always() }}
79+
run: moodle-plugin-ci phpmd
80+
81+
- name: Moodle Code Checker
82+
if: ${{ always() }}
83+
run: moodle-plugin-ci codechecker --max-warnings 0
84+
85+
- name: Moodle PHPDoc Checker
86+
if: ${{ always() }}
87+
run: moodle-plugin-ci phpdoc
88+
89+
- name: Validating
90+
if: ${{ always() }}
91+
run: moodle-plugin-ci validate
92+
93+
- name: Check upgrade savepoints
94+
if: ${{ always() }}
95+
run: moodle-plugin-ci savepoints
96+
97+
- name: Mustache Lint
98+
if: ${{ always() }}
99+
run: moodle-plugin-ci mustache
100+
101+
- name: Grunt
102+
if: ${{ always() }}
103+
run: moodle-plugin-ci grunt --max-lint-warnings 0
104+
105+
- name: PHPUnit tests
106+
if: ${{ always() }}
107+
run: moodle-plugin-ci phpunit --fail-on-warning
108+
109+
- name: Behat features
110+
if: ${{ always() }}
111+
run: moodle-plugin-ci behat --profile chrome

.travis.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Featured courses #
22

3+
[![Moodle Plugin CI](https://github.com/martin-call-learning/moodle-block_featured_courses/actions/workflows/main.yml/badge.svg)](https://github.com/martin-call-learning/moodle-block_featured_courses/actions/workflows/main.yml)
4+
35
[![Build Status](https://travis-ci.org/call-learning/moodle-block-featured_courses.svg?branch=master)](https://travis-ci.org/call-learning/moodle-block-featured_courses)
46

57
A block to display of courses from the global list of courses.

block_featured_courses.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
use block_featured_courses\output\featured_courses;
2626

27-
defined('MOODLE_INTERNAL') || die();
28-
2927
/**
3028
* Class block_featured_courses
3129
*
@@ -55,8 +53,9 @@ public function specialization() {
5553
/**
5654
* Content for the block
5755
*
58-
* @return \stdClass|string|null
56+
* @return stdClass|string|null
5957
* @throws coding_exception
58+
* @throws dml_exception
6059
*/
6160
public function get_content() {
6261

@@ -87,7 +86,7 @@ public function get_content() {
8786
*
8887
* @return array
8988
*/
90-
public function applicable_formats() {
89+
public function applicable_formats(): array {
9190
return array('all' => true);
9291
}
9392

@@ -96,7 +95,7 @@ public function applicable_formats() {
9695
*
9796
* @return bool
9897
*/
99-
public function instance_allow_multiple() {
98+
public function instance_allow_multiple(): bool {
10099
return true;
101100
}
102101

@@ -105,7 +104,7 @@ public function instance_allow_multiple() {
105104
*
106105
* @return bool
107106
*/
108-
public function has_config() {
107+
public function has_config(): bool {
109108
return false;
110109
}
111110
}

classes/mini_course_summary_exporter.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
*/
2424

2525
namespace block_featured_courses;
26-
defined('MOODLE_INTERNAL') || die();
27-
global $CFG;
2826

2927
use core_course\external\course_summary_exporter;
28+
use core_course_category;
29+
use moodle_exception;
3030
use moodle_url;
3131
use renderer_base;
3232

@@ -45,7 +45,7 @@ class mini_course_summary_exporter extends course_summary_exporter {
4545
*
4646
* @return array|array[]
4747
*/
48-
public static function define_other_properties() {
48+
public static function define_other_properties(): array {
4949
return array(
5050
'fullnamedisplay' => array(
5151
'type' => PARAM_TEXT,
@@ -65,22 +65,12 @@ public static function define_other_properties() {
6565
);
6666
}
6767

68-
/**
69-
* Constructor - saves the persistent object, and the related objects.
70-
*
71-
* @param mixed $data - Either an stdClass or an array of values.
72-
* @param array $related - An optional list of pre-loaded objects related to this object.
73-
*/
74-
public function __construct($data, $related = array()) {
75-
\core\external\exporter::__construct($data, $related);
76-
}
77-
7868
/**
7969
* Define related variables
8070
*
8171
* @return string[]
8272
*/
83-
protected static function define_related() {
73+
protected static function define_related(): array {
8474
// We cache the context so it does not need to be retrieved from the course.
8575
return array('context' => '\\context');
8676
}
@@ -90,15 +80,15 @@ protected static function define_related() {
9080
*
9181
* @param renderer_base $output
9282
* @return array
93-
* @throws \moodle_exception
83+
* @throws moodle_exception
9484
*/
95-
protected function get_other_values(renderer_base $output) {
85+
protected function get_other_values(renderer_base $output): array {
9686
global $CFG;
9787
$courseimage = self::get_course_image($this->data);
9888
if (!$courseimage) {
9989
$courseimage = $output->get_generated_image_for_id($this->data->id);
10090
}
101-
$coursecategory = \core_course_category::get($this->data->category, MUST_EXIST, true);
91+
$coursecategory = core_course_category::get($this->data->category, MUST_EXIST, true);
10292
$urlparam = array('id' => $this->data->id);
10393
$courseurl = new moodle_url('/course/view.php', $urlparam);
10494
if (!empty($CFG->enablesyllabus) && class_exists('\\local_syllabus\\locallib\utils')) {
@@ -108,9 +98,9 @@ protected function get_other_values(renderer_base $output) {
10898
'fullnamedisplay' => get_course_display_name_for_list($this->data),
10999
'viewurl' => $courseurl->out(false),
110100
'courseimage' => $courseimage,
111-
'showshortname' => $CFG->courselistshortnames ? true : false,
101+
'showshortname' => (bool) ($CFG->courselistshortnames ?? false),
112102
'coursecategory' => $coursecategory->name
113103
);
114104
}
115105

116-
}
106+
}

classes/output/featured_courses.php

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
*/
2424

2525
namespace block_featured_courses\output;
26-
defined('MOODLE_INTERNAL') || die();
2726

2827
use block_featured_courses\mini_course_summary_exporter;
28+
use coding_exception;
2929
use context_course;
3030
use context_helper;
31+
use dml_exception;
3132
use renderable;
3233
use renderer_base;
3334
use templatable;
@@ -42,23 +43,25 @@
4243
class featured_courses implements renderable, templatable {
4344

4445
/**
45-
* @var array course
46+
* The list of the courses. Initialized empty
47+
*
48+
* @var array $courses
4649
*/
4750
public $courses = [];
4851

4952
/**
5053
* featured_courses constructor.
5154
* Retrieve matchin courses
5255
*
53-
* @param int $coursesid
54-
* @throws \coding_exception
55-
* @throws \dml_exception
56+
* @param array $coursesid
57+
* @throws coding_exception
58+
* @throws dml_exception
5659
*/
57-
public function __construct($coursesid) {
60+
public function __construct(array $coursesid) {
5861
global $DB;
5962
// First make sure that we have id in the table and not empty strings.
6063
$realcourseids = [];
61-
foreach($coursesid as $cid) {
64+
foreach ($coursesid as $cid) {
6265
if ($cid && is_numeric($cid)) {
6366
$realcourseids[] = $cid;
6467
}
@@ -72,19 +75,17 @@ public function __construct($coursesid) {
7275
*
7376
* @param renderer_base $renderer
7477
* @return array
75-
* @throws \coding_exception
78+
* @throws coding_exception
7679
*/
77-
public function export_for_template(renderer_base $renderer) {
80+
public function export_for_template(renderer_base $renderer): array {
7881
$formattedcourses = array_map(function($course) use ($renderer) {
7982
context_helper::preload_from_record($course);
8083
$context = context_course::instance($course->id);
8184
$exporter = new mini_course_summary_exporter($course, ['context' => $context]);
82-
$exported = (array) $exporter->export($renderer);
83-
return $exported;
85+
return (array) $exporter->export($renderer);
8486
}, $this->courses);
85-
$exportedvalue = [
86-
'courses' => array_values((array) $formattedcourses),
87+
return [
88+
'courses' => array_values($formattedcourses),
8789
];
88-
return $exportedvalue;
8990
}
9091
}

classes/privacy/provider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
*/
2424
namespace block_featured_courses\privacy;
2525

26-
defined('MOODLE_INTERNAL') || die();
26+
use core_privacy\local\metadata\null_provider;
2727

2828
/**
2929
* Privacy Subsystem for block_featured_courses implementing null_provider.
3030
*
3131
* @copyright 2020 - CALL Learning - Laurent David <laurent@call-learning>
3232
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
3333
*/
34-
class provider implements \core_privacy\local\metadata\null_provider {
34+
class provider implements null_provider {
3535

3636
/**
3737
* Get the language string identifier with the component's language

0 commit comments

Comments
 (0)