diff --git a/src/Coduo/PHPHumanizer/String/HtmlTruncate.php b/src/Coduo/PHPHumanizer/String/HtmlTruncate.php
index 7830d58..45ebd05 100644
--- a/src/Coduo/PHPHumanizer/String/HtmlTruncate.php
+++ b/src/Coduo/PHPHumanizer/String/HtmlTruncate.php
@@ -2,7 +2,7 @@
namespace Coduo\PHPHumanizer\String;
-class HtmlTruncate extends TextTruncate
+class HtmlTruncate implements Truncate
{
/**
* @var string
@@ -24,6 +24,11 @@ class HtmlTruncate extends TextTruncate
*/
private $allowedTags;
+ /**
+ * @var Breakpoint
+ */
+ private $breakpoint;
+
/**
* @param string $text
* @param int $charactersCount
@@ -38,6 +43,48 @@ public function __construct($text, $charactersCount, $allowedTags = 'allowedTags = $allowedTags;
}
+ /**
+ * @param Breakpoint $breakpoint
+ *
+ * @return TextTruncate
+ */
+ public function setBreakpoint($breakpoint)
+ {
+ $this->breakpoint = $breakpoint;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function truncate()
+ {
+ $string = strip_tags($this->text, $this->allowedTags);
+ return $this->truncateHtml($string);
+ }
+
+ public function __toString()
+ {
+ return $this->truncate();
+ }
+
+ /**
+ * Return the length of the newly truncated string using the breakpoint
+ *
+ * @param string $text
+ * @param int $charCount
+ *
+ * @return int
+ */
+ private function getLength($text, $charCount)
+ {
+ $length = $this->charactersCount;
+ if (!empty($this->breakpoint)) {
+ $length = $this->breakpoint->calculatePosition($text, $charCount);
+ }
+ return $length;
+ }
+
/**
* Truncates a string to the given length. It will optionally preserve
* HTML tags if $is_html is set to true.
@@ -84,12 +131,4 @@ private function truncateHtml($string)
return $new_string;
}
- /**
- * @return string
- */
- public function truncate()
- {
- $string = strip_tags($this->text, $this->allowedTags);
- return $this->truncateHtml($string);
- }
}
diff --git a/src/Coduo/PHPHumanizer/String/TextTruncate.php b/src/Coduo/PHPHumanizer/String/TextTruncate.php
index 4a065a6..76145bd 100644
--- a/src/Coduo/PHPHumanizer/String/TextTruncate.php
+++ b/src/Coduo/PHPHumanizer/String/TextTruncate.php
@@ -38,30 +38,15 @@ public function __construct($text, $charactersCount, $append = '')
/**
* @param Breakpoint $breakpoint
+ *
* @return TextTruncate
*/
- public function setBreakpoint($breakpoint) {
+ public function setBreakpoint($breakpoint)
+ {
$this->breakpoint = $breakpoint;
return $this;
}
- /**
- * Return the length of the newly truncated string using the breakpoint
- *
- * @param string $text
- * @param int $charCount
- *
- * @return int
- */
- protected function getLength($text, $charCount)
- {
- $length = $this->charactersCount;
- if (!empty($this->breakpoint)) {
- $length = $this->breakpoint->calculatePosition($text, $charCount);
- }
- return $length;
- }
-
/**
* @return string
*/
@@ -79,4 +64,21 @@ public function __toString()
{
return $this->truncate();
}
+
+ /**
+ * Return the length of the newly truncated string using the breakpoint
+ *
+ * @param string $text
+ * @param int $charCount
+ *
+ * @return int
+ */
+ private function getLength($text, $charCount)
+ {
+ $length = $this->charactersCount;
+ if (!empty($this->breakpoint)) {
+ $length = $this->breakpoint->calculatePosition($text, $charCount);
+ }
+ return $length;
+ }
}