Code Duplication    Length = 16-19 lines in 3 locations

src/Math/Stats.php 3 locations

@@ 374-392 (lines=19) @@
371
     * @see calc()
372
     * @see max()
373
     */
374
    public function min()
375
    {
376
        if ($this->_data == null) {
377
            throw new \PEAR_Exception('data has not been set');
378
        }
379
380
        if (!array_key_exists('min', $this->_calculatedValues)) {
381
            if ($this->_dataOption == self::STATS_DATA_CUMMULATIVE) {
382
                $min = min(array_keys($this->_data));
383
            } else {
384
                $min = min($this->_data);
385
            }
386
387
            $this->_calculatedValues['min'] = $min;
388
        }
389
390
        return $this->_calculatedValues['min'];
391
    }
392
393
    /**
394
     * Calculates the maximum of a data set.
395
     * Handles cummulative data sets correctly
@@ 402-417 (lines=16) @@
399
     * @see calc()
400
     * @see min()
401
     */
402
    public function max()
403
    {
404
        if ($this->_data == null) {
405
            throw new \PEAR_Exception('data has not been set');
406
        }
407
        if (!array_key_exists('max', $this->_calculatedValues)) {
408
            if ($this->_dataOption == self::STATS_DATA_CUMMULATIVE) {
409
                $max = max(array_keys($this->_data));
410
            } else {
411
                $max = max($this->_data);
412
            }
413
            $this->_calculatedValues['max'] = $max;
414
        }
415
        return $this->_calculatedValues['max'];
416
    }
417
418
    /**
419
     * Calculates SUM { xi }
420
     * Handles cummulative data sets correctly
@@ 582-597 (lines=16) @@
579
     * @return  mixed   the count on success, a PEAR_Error object otherwise
580
     * @see calc()
581
     */
582
    public function count()
583
    {
584
        if ($this->_data == null) {
585
            throw new \PEAR_Exception('data has not been set');
586
        }
587
        if (!array_key_exists('count', $this->_calculatedValues)) {
588
            if ($this->_dataOption == self::STATS_DATA_CUMMULATIVE) {
589
                $count = count($this->_dataExpanded);
590
            } else {
591
                $count = count($this->_data);
592
            }
593
            $this->_calculatedValues['count'] = $count;
594
        }
595
        return $this->_calculatedValues['count'];
596
    }
597
598
    /**
599
     * Calculates the mean (average) of the data points in the set
600
     * Handles cummulative data sets correctly