Skip to content

Commit

Permalink
Merge pull request #43 from carleton/master
Browse files Browse the repository at this point in the history
Added maxGradeLevel parameter to override hardcoded max grade level
  • Loading branch information
DaveChild authored Feb 13, 2018
2 parents d90054d + da354f8 commit 95b1b25
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions src/DaveChild/TextStatistics/TextStatistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 95b1b25

Please sign in to comment.