xAPI-vle/moodle-logstore_xapi

View on GitHub
src/transformer/utils/get_verb.php

Summary

Maintainability
B
4 hrs
Test Coverage
<?php
// This file is part of Moodle - http://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
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// 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/>.
 
/**
* Transformer utility for retrieving the verb.
*
* @package logstore_xapi
* @copyright Jerret Fowler <jerrett.fowler@gmail.com>
* Ryan Smith <https://www.linkedin.com/in/ryan-smith-uk/>
* David Pesce <david.pesce@exputo.com>
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
 
namespace src\transformer\utils;
 
use src\transformer\utils as utils;
 
/**
* Return the requested verb with details.
*
* @param string $verb The requested verb.
* @param array $config Predefined config elements.
* @param string $lang Language string.
* @return array
* @throws \coding_exception
*/
Method `get_verb` has 80 lines of code (exceeds 25 allowed). Consider refactoring.
Function `get_verb` has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
function get_verb(string $verb, array $config, string $lang) {
$verb = strtolower($verb);
$output = array();
switch ($verb) {
case 'completed':
$output = [
'id' => 'http://adlnet.gov/expapi/verbs/completed',
'display' => [
'en' => 'Completed'
],
];
break;
 
case 'loggedin':
$output = [
'id' => 'https://xapi.edlm/profiles/edlm-lms/concepts/verbs/login',
'display' => [
'en' => 'Logged In'
]
];
 
// JISC specific verb id.
if (utils\is_enabled_config($config, 'send_jisc_data')) {
$output['id'] = 'https://brindlewaye.com/xAPITerms/verbs/loggedin';
}
break;
 
case 'loggedout':
$output = [
'id' => 'https://xapi.edlm/profiles/edlm-lms/concepts/verbs/logout',
'display' => [
'en' => 'Logged Out'
],
];
 
// JISC specific verb id.
if (utils\is_enabled_config($config, 'send_jisc_data')) {
$output['id'] = 'https://brindlewaye.com/xAPITerms/verbs/loggedout';
}
break;
 
case 'received':
$output = [
'id' => 'http://activitystrea.ms/schema/1.0/receive',
'display' => [
'en' => 'Received'
],
];
break;
 
case 'scored':
$output = [
'id' => 'https://w3id.org/xapi/tla/verbs/scored',
'display' => [
'en' => 'Scored'
],
];
break;
 
case 'started':
$output = [
'id' => 'http://activitystrea.ms/schema/1.0/start',
'display' => [
'en' => 'Started'
],
];
break;
 
case 'submitted':
$output = [
'id' => 'http://activitystrea.ms/schema/1.0/submit',
'display' => [
'en' => 'Submitted'
],
];
break;
 
case 'viewed':
$output = [
'id' => 'http://id.tincanapi.com/verb/viewed',
'display' => [
'en' => 'Viewed'
],
];
break;
 
default:
break;
}
 
if (empty($output)) {
throw new \coding_exception(get_string('unknownverb', 'logstore_xapi'));
}
 
return $output;
}