Skip to content

Commit

Permalink
Remove extract().
Browse files Browse the repository at this point in the history
This function makes grokking local scope hard. We've been removing uses
incrementally, and here goes another one.
  • Loading branch information
markstory committed Apr 20, 2016
1 parent 623e662 commit 228cee7
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/Utility/Text.php
Expand Up @@ -570,13 +570,12 @@ public static function truncate($text, $length = 100, array $options = [])
$default['ellipsis'] = "\xe2\x80\xa6";
}
$options += $default;
extract($options);

if ($html) {
if ($options['html']) {
if (mb_strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
$totalLength = mb_strlen(strip_tags($ellipsis));
$totalLength = mb_strlen(strip_tags($options['ellipsis']));
$openTags = [];
$truncate = '';

Expand Down Expand Up @@ -623,11 +622,11 @@ public static function truncate($text, $length = 100, array $options = [])
if (mb_strlen($text) <= $length) {
return $text;
}
$truncate = mb_substr($text, 0, $length - mb_strlen($ellipsis));
$truncate = mb_substr($text, 0, $length - mb_strlen($options['ellipsis']));
}
if (!$exact) {
if (!$options['exact']) {
$spacepos = mb_strrpos($truncate, ' ');
if ($html) {
if ($options['html']) {
$truncateCheck = mb_substr($truncate, 0, $spacepos);
$lastOpenTag = mb_strrpos($truncateCheck, '<');
$lastCloseTag = mb_strrpos($truncateCheck, '>');
Expand Down Expand Up @@ -660,9 +659,9 @@ public static function truncate($text, $length = 100, array $options = [])
}
}

$truncate .= $ellipsis;
$truncate .= $options['ellipsis'];

if ($html) {
if ($options['html']) {
foreach ($openTags as $tag) {
$truncate .= '</' . $tag . '>';
}
Expand Down

0 comments on commit 228cee7

Please sign in to comment.