Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00%
0 / 1
66.67%
2 / 3
CRAP
88.89%
8 / 9
SampleClass
0.00%
0 / 1
66.67%
2 / 3
5.03
88.89%
8 / 9
 fib($n)
0.00%
0 / 1
3.03
85.71%
6 / 7
 aryToStr($a)
100.00%
1 / 1
1
100.00%
1 / 1
 printFibSequence($n)
100.00%
1 / 1
1
100.00%
1 / 1
<?php
/**
* A sample PHP class with some public interface methods.
*/
class SampleClass {
/**
* Return an array of Fibonacci values for the given starting values.
*
* @access public
* @param integer $n Starting value. Must be a non-negative integer.
* @return array An array of all Fibonacci values from $n.
*/
public function fib($n) {
if ($n == 0) {
return array(0);
}
$f = array(0, 1);
for ($x = 2; $x <= $n; $x++) {
$f[] = $f[$x-1] + $f[$x-2];
}
return $f;
}
/**
* Takes an array of integers and formats it into a string for display.
*
* @access public
* @param int[] $a An array of integers.
* @return string A formatted string containing all values from `$a`.
*/
public function aryToStr($a) {
return implode(' ', $a);
}
/**
* Produces a formatted string of Fibonacci values for $n.
*
* @access public
* @param integer $n Starting value. Must be a non-negative integer.
* @return string A formatted string containing all values from `$n`.
*/
public function printFibSequence($n) {
return $this->aryToStr($this->fib($n));
}
}