From da354f87730b1fff17aefac8ce5a1979ccfd5300 Mon Sep 17 00:00:00 2001 From: Matt Ryan Date: Fri, 1 Dec 2017 15:42:39 -0600 Subject: [PATCH] Added maxGradeLevel parameter to override hardcoded max grade level of 12 --- .../TextStatistics/TextStatistics.php | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/DaveChild/TextStatistics/TextStatistics.php b/src/DaveChild/TextStatistics/TextStatistics.php index a32e225..7460a3a 100644 --- a/src/DaveChild/TextStatistics/TextStatistics.php +++ b/src/DaveChild/TextStatistics/TextStatistics.php @@ -43,6 +43,12 @@ class TextStatistics * by object, if set */ protected $strEncoding = ''; + + /** + * @var Maximum grade level to be reported. Calculated grades above + * this level will be returned as this value. + */ + protected $maxGradeLevel = 12; /** * @var bool $normalise Should the result be normalised? @@ -100,6 +106,23 @@ public function setEncoding($strEncoding) $this->strEncoding = $strEncoding; return true; } + + /** + * Set the maximum grade level for grade-level type indexes + * (Flesch-Kincaid Grade Level, Gunning-Fog, Coleman-Liau, SMOG, Automated Readability) + * @param integer $maxGradeLevel Grade level to use + * @return boolean Success + */ + public function setMaxGradeLevel($maxGradeLevel) + { + $maxGradeLevel = (integer) $maxGradeLevel; + if( $maxGradeLevel ) + { + $this->maxGradeLevel = $maxGradeLevel; + return true; + } + return false; + } /** * Gives the Flesch-Kincaid Reading Ease of text entered rounded to one digit @@ -163,7 +186,7 @@ public function fleschKincaidGradeLevel($strText = false) ); if ($this->normalise) { - return Maths::normaliseScore($score, 0, 12, $this->dps); + return Maths::normaliseScore($score, 0, $this->maxGradeLevel, $this->dps); } else { return Maths::bcCalc($score, '+', 0, true, $this->dps); } @@ -231,7 +254,7 @@ public function colemanLiauIndex($strText = false) ); if ($this->normalise) { - return Maths::normaliseScore($score, 0, 12, $this->dps); + return Maths::normaliseScore($score, 0, $this->maxGradeLevel, $this->dps); } else { return Maths::bcCalc($score, '+', 0, true, $this->dps); } @@ -269,7 +292,7 @@ public function smogIndex($strText = false) ); if ($this->normalise) { - return Maths::normaliseScore($score, 0, 12, $this->dps); + return Maths::normaliseScore($score, 0, $this->maxGradeLevel, $this->dps); } else { return Maths::bcCalc($score, '+', 0, true, $this->dps); } @@ -311,7 +334,7 @@ public function automatedReadabilityIndex($strText = false) ); if ($this->normalise) { - return Maths::normaliseScore($score, 0, 12, $this->dps); + return Maths::normaliseScore($score, 0, $this->maxGradeLevel, $this->dps); } else { return Maths::bcCalc($score, '+', 0, true, $this->dps); }