51    public static function calculate($trendType = self::TREND_BEST_FIT, $yValues = [], $xValues = [], $const = 
true)
 
   54        $nY = count($yValues);
 
   55        $nX = count($xValues);
 
   59            $xValues = range(1, $nY);
 
   60        } elseif ($nY !== $nX) {
 
   62            trigger_error(
'Trend(): Number of elements in coordinate arrays do not match.', E_USER_ERROR);
 
   65        $key = md5($trendType . $const . serialize($yValues) . serialize($xValues));
 
   73                if (!isset(self::$trendCache[
$key])) {
 
   74                    $className = 
'\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 
'BestFit';
 
   75                    self::$trendCache[
$key] = 
new $className($yValues, $xValues, $const);
 
   78                return self::$trendCache[
$key];
 
   84                if (!isset(self::$trendCache[
$key])) {
 
   85                    $order = substr($trendType, -1);
 
   89                return self::$trendCache[
$key];
 
   96                foreach (self::$trendTypes as $trendMethod) {
 
   97                    $className = 
'\PhpOffice\PhpSpreadsheet\Shared\Trend\\' . $trendType . 
'BestFit';
 
   98                    $bestFit[$trendMethod] = 
new $className($yValues, $xValues, $const);
 
   99                    $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
 
  101                if ($trendType != self::TREND_BEST_FIT_NO_POLY) {
 
  102                    foreach (self::$trendTypePolynomialOrders as $trendMethod) {
 
  103                        $order = substr($trendMethod, -1);
 
  105                        if ($bestFit[$trendMethod]->
getError()) {
 
  106                            unset($bestFit[$trendMethod]);
 
  108                            $bestFitValue[$trendMethod] = $bestFit[$trendMethod]->getGoodnessOfFit();
 
  113                arsort($bestFitValue);
 
  114                $bestFitType = key($bestFitValue);
 
  116                return $bestFit[$bestFitType];
 
An exception for terminatinating execution or to throw for unit testing.
static $trendTypePolynomialOrders
static calculate($trendType=self::TREND_BEST_FIT, $yValues=[], $xValues=[], $const=true)
const TREND_BEST_FIT_NO_POLY
getError()
returns error @access public