Skip to content
This repository has been archived by the owner on Feb 1, 2022. It is now read-only.

Commit

Permalink
Coding Style: The use of function print_r() is forbidden
Browse files Browse the repository at this point in the history
  • Loading branch information
adamfranco committed Dec 11, 2013
1 parent 1a05c80 commit 9ad94d5
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 12 deletions.
20 changes: 15 additions & 5 deletions adaptiveattempt.class.php
Expand Up @@ -131,6 +131,16 @@ protected function print_debug($message = '') {
}
}

/**
* Answer a string view of a variable for debugging purposes
* @param mixed $variable
*/
protected function vardump($variable) {
ob_start();
var_dump($variable);
return ob_get_clean();
}

/**
* This function returns the debug array
* @return array array of debugging messages
Expand Down Expand Up @@ -364,7 +374,7 @@ protected function get_question_ready($fetchquestion) {
$questiontodisplay = 0;

if (empty($questionids)) {
$this->print_debug('get_question_ready() - Unable to fetch a question $questionsids:'.print_r($questionids, true));
$this->print_debug('get_question_ready() - Unable to fetch a question $questionsids:'.$this->vardump($questionids));
return false;
}
// Select one random question.
Expand Down Expand Up @@ -398,7 +408,7 @@ protected function get_question_ready($fetchquestion) {

// Set class level property to the difficulty level of the question returned from fetchquestion class.
$this->level = $fetchquestion->get_level();
$this->print_debug('get_question_ready() - Question: '.print_r($question, true).' loaded and attempt started. '.
$this->print_debug('get_question_ready() - Question: '.$this->vardump($question).' loaded and attempt started. '.
'Question_usage_by_activity saved.');
return true;
}
Expand Down Expand Up @@ -488,12 +498,12 @@ public function get_attempt() {
$attempt->id = $id;
$this->adpqattempt = $attempt;

$this->print_debug('get_attempt() - new attempt created: '.print_r($attempt, true));
$this->print_debug('get_attempt() - new attempt created: '.$this->vardump($attempt));
} else {
$attempt = current($attempt);
$this->adpqattempt = $attempt;

$this->print_debug('get_attempt() - previous attempt loaded: '.print_r($attempt, true));
$this->print_debug('get_attempt() - previous attempt loaded: '.$this->vardump($attempt));
}

return $attempt;
Expand All @@ -508,7 +518,7 @@ public function get_attempt() {
public function find_last_quest_used_by_attempt($quba) {
if (!$quba instanceof question_usage_by_activity) {
throw new coding_exception('find_last_quest_used_by_attempt() - Argument was not a question_usage_by_activity object',
print_r($quba, true));
$this->vardump($quba));
}

// The last slot in the array should be the last question that was attempted (meaning it was either shown to the user
Expand Down
14 changes: 12 additions & 2 deletions catalgo.class.php
Expand Up @@ -125,6 +125,16 @@ protected function print_debug($message = '') {
}
}

/**
* Answer a string view of a variable for debugging purposes
* @param mixed $variable
*/
protected function vardump($variable) {
ob_start();
var_dump($variable);
return ob_get_clean();
}

/**
* This function returns the debug array
* @return array array of debugging messages
Expand Down Expand Up @@ -571,14 +581,14 @@ public function get_current_diff_level($quba, $level, $attemptobj) {
// Check if attempt object has required properties defined.
if (!isset($attemptobj->lowestlevel) || !isset($attemptobj->highestlevel)) {
throw new coding_exception('get_current_diff_level: Arg 3 needs to have lowestlevel and highestlevel properties',
'Invalid attemptobj of :'.print_r($attemptobj, true));
'Invalid attemptobj of :'.$this->vardump($attemptobj));
}
// Check if attempt object has required property value types.
$conditions = !is_int($attemptobj->lowestlevel) || 0 >= $attemptobj->lowestlevel || !is_int($attemptobj->highestlevel)
|| 0 >= $attemptobj->highestlevel || $attemptobj->lowestlevel >= $attemptobj->highestlevel;
if ($conditions) {
throw new coding_exception('get_current_diff_level: Arg 3 lowestlevel and highestlevel properties must be positive '.
'integers', 'Invalid attemptobj of :'.print_r($attemptobj, true));
'integers', 'Invalid attemptobj of :'.$this->vardump($attemptobj));
}

return $this->return_current_diff_level($quba, $level, $attemptobj);
Expand Down
20 changes: 15 additions & 5 deletions fetchquestion.class.php
Expand Up @@ -178,6 +178,16 @@ protected function print_debug($message = '') {
}
}

/**
* Answer a string view of a variable for debugging purposes
* @param mixed $variable
*/
protected function vardump($variable) {
ob_start();
var_dump($variable);
return ob_get_clean();
}

/**
* This function returns the debug array
* @return array - array of debugging messages
Expand Down Expand Up @@ -364,7 +374,7 @@ public function retrieve_all_tag_ids($minimumlevel, $maximumlevel, $tagprefix) {
try {
$substr = $DB->sql_substr('name', $length);
} catch (coding_exception $e) {
$this->print_debug('retrieve_all_tag_ids() - Missing tag prefix '.print_r($tagprefix, true));
$this->print_debug('retrieve_all_tag_ids() - Missing tag prefix '.$this->vardump($tagprefix));
print_error('missingtagprefix', 'adaptivequiz');
}

Expand Down Expand Up @@ -427,7 +437,7 @@ public function retrieve_tags_with_question_count($tagids, $categories, $tagpref
$records = $DB->get_records_sql_menu($sql, $params);
return $records;
} catch (coding_exception $e) {
$this->print_debug('retrieve_tags_with_question_count() - Missing tag prefix '.print_r($tagprefix, true));
$this->print_debug('retrieve_tags_with_question_count() - Missing tag prefix '.$this->vardump($tagprefix));
print_error('missingtagprefix', 'adaptivequiz');
}
}
Expand Down Expand Up @@ -524,7 +534,7 @@ public function find_questions_with_tags($tagids = array(), $exclude = array())

$records = $DB->get_records_sql($query, $params);

$this->print_debug('find_questions() - question ids returned: '.print_r($records, true));
$this->print_debug('find_questions() - question ids returned: '.$this->vardump($records));

return $records;
}
Expand All @@ -539,7 +549,7 @@ protected function retrieve_question_categories() {
// Check cached result.
if (!empty($this->questcatids)) {
$this->print_debug('retrieve_question_categories() - question category ids (from cache): '.
print_r($this->questcatids, true));
$this->vardump($this->questcatids));
return $this->questcatids;
}

Expand All @@ -550,7 +560,7 @@ protected function retrieve_question_categories() {
// Cache the results.
$this->questcatids = $records;

$this->print_debug('retrieve_question_categories() - question category ids: '.print_r($records, true));
$this->print_debug('retrieve_question_categories() - question category ids: '.$this->vardump($records));

return $records;
}
Expand Down

0 comments on commit 9ad94d5

Please sign in to comment.