Skip to content

Commit e0b287a

Browse files
committed
Run phpcbf to fix CI issues
1 parent 0189696 commit e0b287a

21 files changed

+325
-322
lines changed

classes/local/url.php

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -46,109 +46,109 @@ class url extends \core\persistent {
4646
* @return array
4747
*/
4848
protected static function define_properties() {
49-
return array(
50-
'url' => array(
49+
return [
50+
'url' => [
5151
'type' => PARAM_TEXT,
52-
),
53-
'urlhash' => array(
52+
],
53+
'urlhash' => [
5454
'type' => PARAM_TEXT,
55-
),
56-
'externalurl' => array(
55+
],
56+
'externalurl' => [
5757
'type' => PARAM_TEXT,
5858
'null' => NULL_ALLOWED,
5959
'default' => null,
60-
),
61-
'lastcrawled' => array(
60+
],
61+
'lastcrawled' => [
6262
'type' => PARAM_INT,
6363
'null' => NULL_ALLOWED,
6464
'default' => null,
65-
),
66-
'needscrawl' => array(
65+
],
66+
'needscrawl' => [
6767
'type' => PARAM_INT,
6868
'null' => NULL_ALLOWED,
6969
'default' => null,
70-
),
71-
'httpcode' => array(
70+
],
71+
'httpcode' => [
7272
'type' => PARAM_TEXT,
7373
'null' => NULL_ALLOWED,
7474
'default' => null,
75-
),
76-
'mimetype' => array(
75+
],
76+
'mimetype' => [
7777
'type' => PARAM_TEXT,
7878
'null' => NULL_ALLOWED,
7979
'default' => null,
80-
),
81-
'title' => array(
80+
],
81+
'title' => [
8282
'type' => PARAM_TEXT,
8383
'null' => NULL_ALLOWED,
8484
'default' => null,
85-
),
86-
'downloadduration' => array(
85+
],
86+
'downloadduration' => [
8787
'type' => PARAM_FLOAT,
8888
'null' => NULL_ALLOWED,
8989
'default' => null,
90-
),
91-
'filesize' => array(
90+
],
91+
'filesize' => [
9292
'type' => PARAM_INT,
9393
'null' => NULL_ALLOWED,
9494
'default' => null,
95-
),
96-
'filesizestatus' => array(
95+
],
96+
'filesizestatus' => [
9797
'type' => PARAM_INT,
9898
'null' => NULL_ALLOWED,
9999
'default' => null,
100-
),
101-
'redirect' => array(
100+
],
101+
'redirect' => [
102102
'type' => PARAM_TEXT,
103103
'null' => NULL_ALLOWED,
104104
'default' => null,
105-
),
106-
'courseid' => array(
105+
],
106+
'courseid' => [
107107
'type' => PARAM_INT,
108108
'null' => NULL_ALLOWED,
109109
'default' => null,
110-
),
111-
'contextid' => array(
110+
],
111+
'contextid' => [
112112
'type' => PARAM_INT,
113113
'null' => NULL_ALLOWED,
114114
'default' => null,
115-
),
116-
'cmid' => array(
115+
],
116+
'cmid' => [
117117
'type' => PARAM_INT,
118118
'null' => NULL_ALLOWED,
119119
'default' => null,
120-
),
121-
'ignoreduserid' => array(
120+
],
121+
'ignoreduserid' => [
122122
'type' => PARAM_INT,
123123
'null' => NULL_ALLOWED,
124124
'default' => null,
125-
),
126-
'ignoredtime' => array(
125+
],
126+
'ignoredtime' => [
127127
'type' => PARAM_INT,
128128
'null' => NULL_ALLOWED,
129129
'default' => null,
130-
),
131-
'httpmsg' => array(
130+
],
131+
'httpmsg' => [
132132
'type' => PARAM_TEXT,
133133
'null' => NULL_ALLOWED,
134134
'default' => null,
135-
),
136-
'errormsg' => array(
135+
],
136+
'errormsg' => [
137137
'type' => PARAM_TEXT,
138138
'null' => NULL_ALLOWED,
139139
'default' => null,
140-
),
141-
'priority' => array(
140+
],
141+
'priority' => [
142142
'type' => PARAM_INT,
143143
'null' => NULL_ALLOWED,
144144
'default' => '0',
145-
),
146-
'urllevel' => array(
145+
],
146+
'urllevel' => [
147147
'type' => PARAM_INT,
148148
'null' => NULL_ALLOWED,
149149
'default' => '2',
150-
),
151-
);
150+
],
151+
];
152152
}
153153

154154
/**
@@ -193,7 +193,7 @@ public static function reset_for_recrawl($nodeid) {
193193
// Delete all edges that point to this node.
194194
$DB->delete_records('tool_crawler_edge', ['b' => $nodeid]);
195195
// Delete the 'to' node as it may be completely wrong.
196-
$DB->delete_records('tool_crawler_url', array('id' => $nodeid) );
196+
$DB->delete_records('tool_crawler_url', ['id' => $nodeid] );
197197
}
198198
}
199199

@@ -224,7 +224,7 @@ public function get_processed() {
224224
SELECT COUNT(*)
225225
FROM {tool_crawler_url}
226226
WHERE lastcrawled >= ?",
227-
array(crawler::get_config()->crawlstart));
227+
[crawler::get_config()->crawlstart]);
228228
}
229229

230230
/**

classes/privacy/provider.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
//
1414
// You should have received a copy of the GNU General Public License
1515
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
1617
/**
1718
* Privacy Subsystem implementation for tool_crawler.
1819
*

classes/robot/crawler.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ class crawler {
8181
* @return mixed hash-like object or default array $defaults if no config found.
8282
*/
8383
public static function get_config() {
84-
$defaults = array(
84+
$defaults = [
8585
'crawlstart' => 0,
8686
'crawlend' => 0,
8787
'crawltick' => 0,
8888
'retentionperiod' => 86400, // 1 week.
89-
'recentactivity' => 1
90-
);
89+
'recentactivity' => 1,
90+
];
9191
$config = (object) array_merge( $defaults, (array) get_config('tool_crawler') );
9292
return $config;
9393
}
@@ -105,7 +105,7 @@ public function is_bot_valid() {
105105
if (!$botusername) {
106106
return get_string('configmissing', 'tool_crawler');
107107
}
108-
$botuser = $DB->get_record('user', array('username' => $botusername));
108+
$botuser = $DB->get_record('user', ['username' => $botusername]);
109109
if ( !$botuser ) {
110110
return get_string('botusermissing', 'tool_crawler') .
111111
' <a href="?action=makebot">' . get_string('autocreate', 'tool_crawler') . '</a>';
@@ -118,14 +118,14 @@ public function is_bot_valid() {
118118
}
119119
if ($result->redirect) {
120120
return get_string('bottestpageredirected', 'tool_crawler',
121-
array('resredirect' => htmlspecialchars($result->redirect, ENT_NOQUOTES | ENT_HTML401)));
121+
['resredirect' => htmlspecialchars($result->redirect, ENT_NOQUOTES | ENT_HTML401)]);
122122
}
123123

124124
// When the bot successfully scraped the test page (see above), it was logged in and used its own language. So we have to
125125
// retrieve the expected string in the language set for the _crawler user_, and not in the _current user’s_ language.
126126
$oldforcelang = force_current_language($botuser->lang);
127127
$expectedcontent = get_string('hellorobot', 'tool_crawler',
128-
array('botusername' => self::get_config()->botusername));
128+
['botusername' => self::get_config()->botusername]);
129129
force_current_language($oldforcelang);
130130

131131
$hello = strpos($result->contents, $expectedcontent);
@@ -144,11 +144,11 @@ public function auto_create_bot() {
144144
// TODO roles?
145145
146146
$botusername = self::get_config()->botusername;
147-
$botuser = $DB->get_record('user', array('username' => $botusername) );
147+
$botuser = $DB->get_record('user', ['username' => $botusername] );
148148
if ($botuser) {
149149
return $botuser;
150150
} else {
151-
$botuser = (object) array();
151+
$botuser = (object) [];
152152
$botuser->username = $botusername;
153153
$botuser->password = hash_internal_user_password(self::get_config()->botpassword);
154154
$botuser->firstname = 'Link checker';
@@ -217,7 +217,7 @@ public function absolute_url($base, $rel) {
217217
}
218218

219219
// Replace '//' or '/./' or '/foo/../' with '/' */.
220-
$re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#');
220+
$re = ['#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'];
221221
do {
222222
$abs = preg_replace($re, '/', $abs, -1, $n);
223223
} while ($n > 0);
@@ -341,13 +341,13 @@ public function mark_for_crawl($baseurl, $url, $courseid = null, $priority = TOO
341341
// then avoid scraping the URL at all, if it has been excluded.
342342
$shortname = '';
343343
if (preg_match('/\/course\/(info|view).php\?id=(\d+)/', $url , $matches) ) {
344-
$course = $DB->get_record('course', array('id' => $matches[2]));
344+
$course = $DB->get_record('course', ['id' => $matches[2]]);
345345
if ($course) {
346346
$shortname = $course->shortname;
347347
}
348348
}
349349
if (preg_match('/\/enrol\/index.php\?id=(\d+)/', $url , $matches) ) {
350-
$course = $DB->get_record('course', array('id' => $matches[1]));
350+
$course = $DB->get_record('course', ['id' => $matches[1]]);
351351
if ($course) {
352352
$shortname = $course->shortname;
353353
}
@@ -358,13 +358,13 @@ public function mark_for_crawl($baseurl, $url, $courseid = null, $priority = TOO
358358
c.shortname
359359
FROM {course_modules} cm
360360
JOIN {course} c ON cm.course = c.id
361-
WHERE cm.id = ?", array($matches[3]));
361+
WHERE cm.id = ?", [$matches[3]]);
362362
if ($cm) {
363363
$shortname = $cm->shortname;
364364
}
365365
}
366366
if (preg_match('/\/course\/(.*?)\//', $url, $matches) ) {
367-
$course = $DB->get_record('course', array('shortname' => $matches[1]));
367+
$course = $DB->get_record('course', ['shortname' => $matches[1]]);
368368
if ($course) {
369369
$shortname = $course->shortname;
370370
}
@@ -383,7 +383,7 @@ public function mark_for_crawl($baseurl, $url, $courseid = null, $priority = TOO
383383

384384
if (!$node) {
385385
// If not in the queue then add it.
386-
$node = (object) array();
386+
$node = (object) [];
387387
$node->timecreated = time();
388388
$node->url = $url;
389389
$node->externalurl = self::is_external($url);
@@ -439,7 +439,7 @@ public function get_num_links() {
439439
SELECT COUNT(*)
440440
FROM {tool_crawler_edge}
441441
WHERE lastmod >= ?",
442-
array(self::get_config()->crawlstart));
442+
[self::get_config()->crawlstart]);
443443
}
444444

445445
/**
@@ -503,7 +503,7 @@ public function get_old_queue_size() {
503503
SELECT COUNT(*)
504504
FROM {tool_crawler_url}
505505
WHERE lastcrawled < ?",
506-
array(self::get_config()->crawlstart));
506+
[self::get_config()->crawlstart]);
507507
}
508508

509509
/**
@@ -712,7 +712,7 @@ protected static function clean_html_node_content($node) {
712712

713713
$elementname = mb_strtolower($node->tag, 'UTF-8');
714714

715-
$ignoredelements = array('script', 'style');
715+
$ignoredelements = ['script', 'style'];
716716
if (in_array($elementname, $ignoredelements)) {
717717
return '';
718718
} else if ($elementname == 'img') {
@@ -833,7 +833,7 @@ public function parse_html($node, $external, $verbose = false) {
833833
}
834834

835835
// Finds each link in the html and adds to database.
836-
$seen = array();
836+
$seen = [];
837837

838838
$links = $html->find('a[href]');
839839
foreach ($links as $e) {
@@ -910,7 +910,7 @@ private function link_from_node_to_url($from, $url, $text, $idattr) {
910910
}
911911

912912
// For this link, insert or update with the current time for last modified.
913-
$link = $DB->get_record('tool_crawler_edge', array('a' => $from->id, 'b' => $to->id));
913+
$link = $DB->get_record('tool_crawler_edge', ['a' => $from->id, 'b' => $to->id]);
914914
if (!$link) {
915915
$link = new \stdClass();
916916
$link->a = $from->id;
@@ -1136,7 +1136,7 @@ public function scrape($url) {
11361136
$sizelimit = TOOL_CRAWLER_REDIRECTION_DOWNLOAD_LIMIT; // Assume at first that we will be redirected.
11371137
$abortdownload = false;
11381138

1139-
$chunks = array();
1139+
$chunks = [];
11401140
$targetisexternal = null; // Cache for whether target resource is external.
11411141
$targetishtml = null; // Cache for whether target resource is an HTML document.
11421142
$targetlengthknown = null; // Cache for whether target resource length is known.
@@ -1288,7 +1288,7 @@ public function scrape($url) {
12881288
$method = 'GET';
12891289
}
12901290

1291-
$result = (object) array();
1291+
$result = (object) [];
12921292
$result->url = $url;
12931293

12941294
$needhttprequest = true; // Whether we have to send (a further) HTTP request.
@@ -1401,7 +1401,7 @@ public function scrape($url) {
14011401
$method = 'GET';
14021402

14031403
$sizelimit = TOOL_CRAWLER_REDIRECTION_DOWNLOAD_LIMIT; // Assume at first that we will be redirected.
1404-
$chunks = array();
1404+
$chunks = [];
14051405
$firstheaderline = true;
14061406
$headersize = 0;
14071407
$targetisexternal = null;
@@ -1515,7 +1515,7 @@ public function get_recentcourses() {
15151515

15161516
// Do not try to fetch recent courses if uselogs setting is not enabled.
15171517
if ($config->uselogs == false) {
1518-
return array();
1518+
return [];
15191519
}
15201520

15211521
$startingtimerecentactivity = strtotime("-$config->recentactivity days", time());

classes/task/robot_cleanup.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public function execute($currenttime = null) {
7070
$retentionperiod = \tool_crawler\robot\crawler::get_config()->retentionperiod;
7171
$lastcrawlend = \tool_crawler\robot\crawler::get_config()->crawlend;
7272
if ($retentionperiod) {
73-
$param = array(
73+
$param = [
7474
'currenttime' => $currenttime,
7575
'lastcrawlfinished' => $lastcrawlend,
76-
'expiredate' => $currenttime - $retentionperiod
77-
);
76+
'expiredate' => $currenttime - $retentionperiod,
77+
];
7878
$where = 'lastcrawled <= :currenttime
7979
AND lastcrawled <= :lastcrawlfinished
8080
AND lastcrawled <= :expiredate';
@@ -83,11 +83,11 @@ public function execute($currenttime = null) {
8383
}
8484

8585
// Throw and log event that robot_cleanup task was finished and pass number of deleted records.
86-
$eventdata = array(
87-
'other' => array(
88-
'numrecsdeleted' => $numrecsdeleted
89-
)
90-
);
86+
$eventdata = [
87+
'other' => [
88+
'numrecsdeleted' => $numrecsdeleted,
89+
],
90+
];
9191
$event = \tool_crawler\event\robot_cleanup_completed::create($eventdata);
9292
$event->trigger();
9393
}

0 commit comments

Comments
 (0)