From 37ad62f903570581cd350a19017405e17b2160fe Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 13 Dec 2015 14:44:22 +0100 Subject: [PATCH 1/5] Removed deprecated class and marked facades as final --- .../PHPHumanizer/CollectionHumanizer.php | 2 +- src/Coduo/PHPHumanizer/DateTimeHumanizer.php | 2 +- src/Coduo/PHPHumanizer/NumberHumanizer.php | 2 +- src/Coduo/PHPHumanizer/String/Truncate.php | 50 ------------------- src/Coduo/PHPHumanizer/StringHumanizer.php | 2 +- 5 files changed, 4 insertions(+), 54 deletions(-) delete mode 100644 src/Coduo/PHPHumanizer/String/Truncate.php diff --git a/src/Coduo/PHPHumanizer/CollectionHumanizer.php b/src/Coduo/PHPHumanizer/CollectionHumanizer.php index 0f55792..c68834e 100644 --- a/src/Coduo/PHPHumanizer/CollectionHumanizer.php +++ b/src/Coduo/PHPHumanizer/CollectionHumanizer.php @@ -6,7 +6,7 @@ use Coduo\PHPHumanizer\Collection\Oxford; use Coduo\PHPHumanizer\Translator\Builder; -class CollectionHumanizer +final class CollectionHumanizer { public static function oxford($collection, $limit = null, $locale = 'en') { diff --git a/src/Coduo/PHPHumanizer/DateTimeHumanizer.php b/src/Coduo/PHPHumanizer/DateTimeHumanizer.php index 310d2e4..03fa3df 100644 --- a/src/Coduo/PHPHumanizer/DateTimeHumanizer.php +++ b/src/Coduo/PHPHumanizer/DateTimeHumanizer.php @@ -8,7 +8,7 @@ use Coduo\PHPHumanizer\DateTime\PreciseFormatter; use Coduo\PHPHumanizer\Translator\Builder; -class DateTimeHumanizer +final class DateTimeHumanizer { public static function difference(\DateTime $fromDate, \DateTime $toDate, $locale = 'en') { diff --git a/src/Coduo/PHPHumanizer/NumberHumanizer.php b/src/Coduo/PHPHumanizer/NumberHumanizer.php index 33a530f..ea19aa5 100644 --- a/src/Coduo/PHPHumanizer/NumberHumanizer.php +++ b/src/Coduo/PHPHumanizer/NumberHumanizer.php @@ -7,7 +7,7 @@ use Coduo\PHPHumanizer\String\BinarySuffix; use Coduo\PHPHumanizer\String\MetricSuffix; -class NumberHumanizer +final class NumberHumanizer { /** * @param int|float $number diff --git a/src/Coduo/PHPHumanizer/String/Truncate.php b/src/Coduo/PHPHumanizer/String/Truncate.php deleted file mode 100644 index fa815fa..0000000 --- a/src/Coduo/PHPHumanizer/String/Truncate.php +++ /dev/null @@ -1,50 +0,0 @@ -text = $text; - $this->charactersCount = $charactersCount; - $this->append = $append; - } - - public function __toString() - { - if ($this->charactersCount < 0 || mb_strlen($this->text) <= ($this->charactersCount + mb_strlen($this->append))) { - return $this->text; - } - - $length = $this->charactersCount; - if (false !== ($breakpoint = mb_strpos($this->text, ' ', $this->charactersCount))) { - $length = $breakpoint; - } - - return rtrim(mb_substr($this->text, 0, $length)).$this->append; - } -} \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/StringHumanizer.php b/src/Coduo/PHPHumanizer/StringHumanizer.php index 9b0b5ad..3cd85b3 100644 --- a/src/Coduo/PHPHumanizer/StringHumanizer.php +++ b/src/Coduo/PHPHumanizer/StringHumanizer.php @@ -8,7 +8,7 @@ use Coduo\PHPHumanizer\String\HtmlTruncate; use Coduo\PHPHumanizer\String\WordBreakpoint; -class StringHumanizer +final class StringHumanizer { /** * @param $text From a5aa9616a0924cecce0096bedd9eb818de97ad65 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 13 Dec 2015 14:50:21 +0100 Subject: [PATCH 2/5] Cleanup with php-cs-fixer --- src/Coduo/PHPHumanizer/Collection/Oxford.php | 11 +++ .../PHPHumanizer/CollectionHumanizer.php | 6 ++ .../DateTime/PreciseFormatter.php | 4 +- src/Coduo/PHPHumanizer/DateTimeHumanizer.php | 12 ++++ src/Coduo/PHPHumanizer/Number/Ordinal.php | 6 +- .../PHPHumanizer/Number/Ordinal/Builder.php | 4 +- .../Number/Ordinal/StrategyInterface.php | 1 + src/Coduo/PHPHumanizer/NumberHumanizer.php | 31 ++++++++- .../Resources/Ordinal/EnStrategy.php | 2 +- .../Resources/Ordinal/NlStrategy.php | 4 +- .../Resources/translations/difference.no.yml | 68 +++++++++---------- .../PHPHumanizer/String/BinarySuffix.php | 60 ++++++++-------- src/Coduo/PHPHumanizer/String/Breakpoint.php | 4 +- .../PHPHumanizer/String/HtmlTruncate.php | 16 ++--- src/Coduo/PHPHumanizer/String/Humanize.php | 11 ++- .../String/ShortcodeProcessor.php | 14 ++-- .../PHPHumanizer/String/TextTruncate.php | 7 +- .../PHPHumanizer/String/TruncateInterface.php | 5 +- .../PHPHumanizer/String/WordBreakpoint.php | 6 +- src/Coduo/PHPHumanizer/StringHumanizer.php | 12 +++- 20 files changed, 178 insertions(+), 106 deletions(-) diff --git a/src/Coduo/PHPHumanizer/Collection/Oxford.php b/src/Coduo/PHPHumanizer/Collection/Oxford.php index 47d89f2..055f50f 100644 --- a/src/Coduo/PHPHumanizer/Collection/Oxford.php +++ b/src/Coduo/PHPHumanizer/Collection/Oxford.php @@ -9,11 +9,22 @@ class Oxford */ private $formatter; + /** + * Oxford constructor. + * + * @param Formatter $formatter + */ public function __construct(Formatter $formatter) { $this->formatter = $formatter; } + /** + * @param $collection + * @param null $limit + * + * @return string + */ public function format($collection, $limit = null) { return $this->formatter->format($collection, $limit); diff --git a/src/Coduo/PHPHumanizer/CollectionHumanizer.php b/src/Coduo/PHPHumanizer/CollectionHumanizer.php index c68834e..2858589 100644 --- a/src/Coduo/PHPHumanizer/CollectionHumanizer.php +++ b/src/Coduo/PHPHumanizer/CollectionHumanizer.php @@ -8,6 +8,12 @@ final class CollectionHumanizer { + /** + * @param $collection + * @param null $limit + * @param string $locale + * @return string + */ public static function oxford($collection, $limit = null, $locale = 'en') { $oxford = new Oxford( diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index 7788683..af50f8a 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -31,7 +31,7 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') foreach ($difference->getCompoundResults() as $result) { $diff[] = $this->translator->transChoice( - 'compound.' . $result->getUnit()->getName(), + 'compound.'.$result->getUnit()->getName(), $result->getQuantity(), array('%count%' => $result->getQuantity()), 'difference', @@ -40,7 +40,7 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') } return $this->translator->trans( - 'compound.' . ($difference->isPast() ? 'past' : 'future'), + 'compound.'.($difference->isPast() ? 'past' : 'future'), array('%value%' => implode(', ', $diff)), 'difference', $locale diff --git a/src/Coduo/PHPHumanizer/DateTimeHumanizer.php b/src/Coduo/PHPHumanizer/DateTimeHumanizer.php index 03fa3df..0bac0a3 100644 --- a/src/Coduo/PHPHumanizer/DateTimeHumanizer.php +++ b/src/Coduo/PHPHumanizer/DateTimeHumanizer.php @@ -10,6 +10,12 @@ final class DateTimeHumanizer { + /** + * @param \DateTime $fromDate + * @param \DateTime $toDate + * @param string $locale + * @return string + */ public static function difference(\DateTime $fromDate, \DateTime $toDate, $locale = 'en') { $formatter = new Formatter(Builder::build($locale)); @@ -17,6 +23,12 @@ public static function difference(\DateTime $fromDate, \DateTime $toDate, $local return $formatter->formatDifference(new Difference($fromDate, $toDate), $locale); } + /** + * @param \DateTime $fromDate + * @param \DateTime $toDate + * @param string $locale + * @return string + */ public static function preciseDifference(\DateTime $fromDate, \DateTime $toDate, $locale = 'en') { $formatter = new PreciseFormatter(Builder::build($locale)); diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal.php b/src/Coduo/PHPHumanizer/Number/Ordinal.php index 6058e2a..f9d8619 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal.php @@ -8,18 +8,18 @@ class Ordinal { /** - * @type int|float + * @var int|float */ private $number; /** - * @type StrategyInterface + * @var StrategyInterface */ private $strategy; /** * @param int|float $number - * @param string $locale + * @param string $locale */ public function __construct($number, $locale) { diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php b/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php index f1780b2..7e12f10 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php @@ -9,7 +9,9 @@ class Builder { /** * @param string $locale + * * @return StrategyInterface + * * @throws \RuntimeException */ public static function build($locale) @@ -27,7 +29,7 @@ public static function build($locale) $strategy = "\\Coduo\\PHPHumanizer\\Resources\\Ordinal\\{$strategy}Strategy"; if (class_exists($strategy)) { - return new $strategy; + return new $strategy(); } // Debatable: should we fallback to English? diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php b/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php index 9f2a222..4ae2c53 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php @@ -6,6 +6,7 @@ interface StrategyInterface { /** * @param int|float $number + * * @return string */ public function ordinalSuffix($number); diff --git a/src/Coduo/PHPHumanizer/NumberHumanizer.php b/src/Coduo/PHPHumanizer/NumberHumanizer.php index ea19aa5..ab92ecd 100644 --- a/src/Coduo/PHPHumanizer/NumberHumanizer.php +++ b/src/Coduo/PHPHumanizer/NumberHumanizer.php @@ -11,7 +11,8 @@ final class NumberHumanizer { /** * @param int|float $number - * @param string $locale + * @param string $locale + * * @return string */ public static function ordinalize($number, $locale = 'en') @@ -21,15 +22,22 @@ public static function ordinalize($number, $locale = 'en') /** * @param int|float $number - * @param string $locale + * @param string $locale + * * @return string */ public static function ordinal($number, $locale = 'en') { $ordinal = new Ordinal($number, $locale); + return (string) $ordinal; } + /** + * @param $number + * @param string $locale + * @return bool|int|string + */ public static function binarySuffix($number, $locale = 'en') { $binarySuffix = new BinarySuffix($number, $locale); @@ -37,6 +45,12 @@ public static function binarySuffix($number, $locale = 'en') return $binarySuffix->convert(); } + /** + * @param $number + * @param $precision + * @param string $locale + * @return bool|int|string + */ public static function preciseBinarySuffix($number, $precision, $locale = 'en') { $binarySuffix = new BinarySuffix($number, $locale, $precision); @@ -44,6 +58,11 @@ public static function preciseBinarySuffix($number, $precision, $locale = 'en') return $binarySuffix->convert(); } + /** + * @param $number + * @param string $locale + * @return bool|string + */ public static function metricSuffix($number, $locale = 'en') { $binarySuffix = new MetricSuffix($number, $locale); @@ -51,6 +70,10 @@ public static function metricSuffix($number, $locale = 'en') return $binarySuffix->convert(); } + /** + * @param $number + * @return string + */ public static function toRoman($number) { $romanNumeral = new RomanNumeral(); @@ -58,6 +81,10 @@ public static function toRoman($number) return $romanNumeral->toRoman($number); } + /** + * @param $number + * @return int + */ public static function fromRoman($number) { $romanNumeral = new RomanNumeral(); diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php index b3979fd..1268bfb 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php @@ -6,7 +6,7 @@ class EnStrategy implements StrategyInterface { - /** @inheritdoc */ + /** {@inheritdoc} */ public function ordinalSuffix($number) { $absNumber = abs((integer) $number); diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php index 9510fd3..b9280f8 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php @@ -6,9 +6,9 @@ class NlStrategy implements StrategyInterface { - /** @inheritdoc */ + /** {@inheritdoc} */ public function ordinalSuffix($number) { - return "e"; + return 'e'; } } diff --git a/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml b/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml index a2f4ffe..3e9bac1 100644 --- a/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml +++ b/src/Coduo/PHPHumanizer/Resources/translations/difference.no.yml @@ -1,35 +1,35 @@ -just_now: - past: "[0,Inf] akkurat nå" - future: "[0,Inf] akkurat nå" -second: - past: "{1} %count% sekund siden|[2,Inf] %count% sekunder siden" - future: "{1} %count% sekund fra nå|[2,Inf] %count% sekunder fra nå" -minute: - past: "{1} %count% minutt siden|[2,Inf] %count% minutter siden" - future: "{1} %count% minutt fra nå|[2,Inf] %count% minutter fra nå" -hour: - past: "{1} %count% time siden|[2,Inf] %count% timer siden" - future: "{1} %count% time fra nå|[2,Inf] %count% timer fra nå" -day: - past: "{1} %count% dag siden|[2,Inf] %count% dager siden" - future: "{1} %count% dag fra nå|[2,Inf] %count% dager fra nå" -week: - past: "{1} %count% uke siden|[2,Inf] %count% uker siden" - future: "{1} %count% uke fra nå|[2,Inf] %count% uker fra nå" -month: - past: "{1} %count% måned siden|[2,Inf] %count% måneder siden" - future: "{1} %count% måned fra nå|[2,Inf] %count% måneder fra nå" -year: - past: "{1} %count% år siden|[2,Inf] %count% år siden" - future: "{1} %count% år fra nå|[2,Inf] %count% år fra nå" - -compound: - second: "{1} %count% sekund|[2,Inf] %count% sekunder" - minute: "{1} %count% minutt|[2,Inf] %count% minutter" - hour: "{1} %count% time|[2,Inf] %count% timer" - day: "{1} %count% dag|[2,Inf] %count% dager" - week: "{1} %count% uke|[2,Inf] %count% uker" - month: "{1} %count% måned|[2,Inf] %count% måneder" - year: "{1} %count% år|[2,Inf] %count% år" - past: "%value% siden" +just_now: + past: "[0,Inf] akkurat nå" + future: "[0,Inf] akkurat nå" +second: + past: "{1} %count% sekund siden|[2,Inf] %count% sekunder siden" + future: "{1} %count% sekund fra nå|[2,Inf] %count% sekunder fra nå" +minute: + past: "{1} %count% minutt siden|[2,Inf] %count% minutter siden" + future: "{1} %count% minutt fra nå|[2,Inf] %count% minutter fra nå" +hour: + past: "{1} %count% time siden|[2,Inf] %count% timer siden" + future: "{1} %count% time fra nå|[2,Inf] %count% timer fra nå" +day: + past: "{1} %count% dag siden|[2,Inf] %count% dager siden" + future: "{1} %count% dag fra nå|[2,Inf] %count% dager fra nå" +week: + past: "{1} %count% uke siden|[2,Inf] %count% uker siden" + future: "{1} %count% uke fra nå|[2,Inf] %count% uker fra nå" +month: + past: "{1} %count% måned siden|[2,Inf] %count% måneder siden" + future: "{1} %count% måned fra nå|[2,Inf] %count% måneder fra nå" +year: + past: "{1} %count% år siden|[2,Inf] %count% år siden" + future: "{1} %count% år fra nå|[2,Inf] %count% år fra nå" + +compound: + second: "{1} %count% sekund|[2,Inf] %count% sekunder" + minute: "{1} %count% minutt|[2,Inf] %count% minutter" + hour: "{1} %count% time|[2,Inf] %count% timer" + day: "{1} %count% dag|[2,Inf] %count% dager" + week: "{1} %count% uke|[2,Inf] %count% uker" + month: "{1} %count% måned|[2,Inf] %count% måneder" + year: "{1} %count% år|[2,Inf] %count% år" + past: "%value% siden" future: "%value% fra nå" \ No newline at end of file diff --git a/src/Coduo/PHPHumanizer/String/BinarySuffix.php b/src/Coduo/PHPHumanizer/String/BinarySuffix.php index ab6ac36..f818cd7 100644 --- a/src/Coduo/PHPHumanizer/String/BinarySuffix.php +++ b/src/Coduo/PHPHumanizer/String/BinarySuffix.php @@ -29,9 +29,9 @@ class BinarySuffix ); /** - * @param integer $number - * @param string $locale - * @param integer $precision + * @param int $number + * @param string $locale + * @param int $precision * * @throws \InvalidArgumentException */ @@ -41,7 +41,7 @@ public function __construct($number, $locale = 'en', $precision = null) throw new \InvalidArgumentException('Binary suffix converter accept only numeric values.'); } - if(!is_null($precision)){ + if (!is_null($precision)) { $this->setSpecificPrecisionFormat($precision); } @@ -49,53 +49,53 @@ public function __construct($number, $locale = 'en', $precision = null) $this->locale = $locale; } + public function convert() + { + $formatter = new \NumberFormatter($this->locale, \NumberFormatter::PATTERN_DECIMAL); + if ($this->number < 0) { + return $this->number; + } + + foreach ($this->binaryPrefixes as $size => $unitPattern) { + if ($size <= $this->number) { + $value = ($this->number >= self::CONVERT_THRESHOLD) ? $this->number / (double) $size : $this->number; + $formatter->setPattern($unitPattern); + + return $formatter->format($value); + } + } + + return $formatter->format($this->number); + } + /** * Replaces the default ICU 56.1 decimal formats defined in $binaryPrefixes with ones that provide the same symbols - * but the provided number of decimal places + * but the provided number of decimal places. * - * @param integer $precision + * @param int $precision * * @throws \InvalidArgumentException */ protected function setSpecificPrecisionFormat($precision) { - if($precision < 0){ + if ($precision < 0) { throw new \InvalidArgumentException('Precision must be positive'); } - if($precision > 3){ + if ($precision > 3) { throw new \InvalidArgumentException('Invalid precision. Binary suffix converter can only represent values in '. 'up to three decimal places'); } $icuFormat = '#'; - if($precision > 0){ - $icuFormat .= str_pad('#.', (2+$precision), '0'); + if ($precision > 0) { + $icuFormat .= str_pad('#.', (2 + $precision), '0'); } foreach ($this->binaryPrefixes as $size => $unitPattern) { - if($size >= 1024){ + if ($size >= 1024) { $symbol = substr($unitPattern, strpos($unitPattern, ' ')); $this->binaryPrefixes[$size] = $icuFormat.$symbol; } } } - - public function convert() - { - $formatter = new \NumberFormatter($this->locale, \NumberFormatter::PATTERN_DECIMAL); - if ($this->number < 0) { - return $this->number; - } - - foreach ($this->binaryPrefixes as $size => $unitPattern) { - if ($size <= $this->number) { - $value = ($this->number >= self::CONVERT_THRESHOLD) ? $this->number / (double) $size : $this->number; - $formatter->setPattern($unitPattern); - - return $formatter->format($value); - } - } - - return $formatter->format($this->number); - } } diff --git a/src/Coduo/PHPHumanizer/String/Breakpoint.php b/src/Coduo/PHPHumanizer/String/Breakpoint.php index 48a61e9..23d37f1 100644 --- a/src/Coduo/PHPHumanizer/String/Breakpoint.php +++ b/src/Coduo/PHPHumanizer/String/Breakpoint.php @@ -5,7 +5,7 @@ interface Breakpoint { /** - * Return the length of the truncated $text depending on the $characterCount + * Return the length of the truncated $text depending on the $characterCount. * * @param string $text * @param int $charactersCount @@ -14,4 +14,4 @@ interface Breakpoint * @return int */ public function calculatePosition($text, $charactersCount); -} \ No newline at end of file +} diff --git a/src/Coduo/PHPHumanizer/String/HtmlTruncate.php b/src/Coduo/PHPHumanizer/String/HtmlTruncate.php index 5e011b1..629347f 100644 --- a/src/Coduo/PHPHumanizer/String/HtmlTruncate.php +++ b/src/Coduo/PHPHumanizer/String/HtmlTruncate.php @@ -48,16 +48,16 @@ public function truncate($text, $charactersCount) * Adapted from FuelPHP Str::truncate (https://github.com/fuelphp/common/blob/master/src/Str.php) * * @param string $string - * @param int $charactersCount + * @param int $charactersCount * * @return string the truncated string */ private function truncateHtml($string, $charactersCount) { - $limit = $charactersCount; - $offset = 0; - $tags = array(); - + $limit = $charactersCount; + $offset = 0; + $tags = array(); + // Handle special characters. preg_match_all('/&[a-z]+;/i', strip_tags($string), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); foreach ($matches as $match) { @@ -73,21 +73,21 @@ private function truncateHtml($string, $charactersCount) if ($match[0][1] - $offset >= $limit) { break; } - + $tag = mb_substr(strtok($match[0][0], " \t\n\r\0\x0B>"), 1); if ($tag[0] != '/') { $tags[] = $tag; } elseif (end($tags) == mb_substr($tag, 1)) { array_pop($tags); } - + $offset += $match[1][1] - $match[0][1]; } $newString = mb_substr($string, 0, $limit = min(mb_strlen($string), $this->breakpoint->calculatePosition($string, $limit + $offset))); $newString .= (mb_strlen($string) > $limit ? $this->append : ''); $newString .= (count($tags = array_reverse($tags)) ? '' : ''); - + return $newString; } } diff --git a/src/Coduo/PHPHumanizer/String/Humanize.php b/src/Coduo/PHPHumanizer/String/Humanize.php index c58fa03..548acf5 100644 --- a/src/Coduo/PHPHumanizer/String/Humanize.php +++ b/src/Coduo/PHPHumanizer/String/Humanize.php @@ -10,7 +10,7 @@ class Humanize private $text; /** - * @var boolean + * @var bool */ private $capitalize; @@ -21,9 +21,9 @@ class Humanize /** * @param $text - * @param bool $capitalize + * @param bool $capitalize * @param string $separator - * @param array $forbiddenWords + * @param array $forbiddenWords */ public function __construct($text, $capitalize = true, $separator = '_', array $forbiddenWords = array('id')) { @@ -34,14 +34,13 @@ public function __construct($text, $capitalize = true, $separator = '_', array $ } /** - * @internal param bool $capitalize * @return string */ public function __toString() { $humanized = trim(strtolower(preg_replace(array('/([A-Z])/', "/[{$this->separator}\\s]+/"), array('_$1', ' '), $this->text))); - $humanized = trim(str_replace($this->forbiddenWords, "", $humanized)); - + $humanized = trim(str_replace($this->forbiddenWords, '', $humanized)); + return $this->capitalize ? ucfirst($humanized) : $humanized; } } diff --git a/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php b/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php index ead9472..db2a9f6 100644 --- a/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php +++ b/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php @@ -10,7 +10,7 @@ class ShortcodeProcessor { /** - * Removes all shortcodes from given text + * Removes all shortcodes from given text. * * @param string $text * @@ -18,15 +18,15 @@ class ShortcodeProcessor */ public function removeShortcodes($text) { - $nullHandler = function() { - return null; + $nullHandler = function () { + return; }; return $this->createShortcodeProcessor($nullHandler)->process($text); } /** - * Removes only shortcode tags from given text (leaves their content as it is) + * Removes only shortcode tags from given text (leaves their content as it is). * * @param string $text * @@ -34,13 +34,17 @@ public function removeShortcodes($text) */ public function removeShortcodeTags($text) { - $contentHandler = function(ShortcodeInterface $s) { + $contentHandler = function (ShortcodeInterface $s) { return $s->getContent(); }; return $this->createShortcodeProcessor($contentHandler)->process($text); } + /** + * @param $defaultHandler + * @return Processor + */ private function createShortcodeProcessor($defaultHandler) { $handlers = new HandlerContainer(); diff --git a/src/Coduo/PHPHumanizer/String/TextTruncate.php b/src/Coduo/PHPHumanizer/String/TextTruncate.php index dd99238..df11ba0 100644 --- a/src/Coduo/PHPHumanizer/String/TextTruncate.php +++ b/src/Coduo/PHPHumanizer/String/TextTruncate.php @@ -16,7 +16,7 @@ class TextTruncate implements TruncateInterface /** * @param Breakpoint $breakpoint - * @param string $append + * @param string $append */ public function __construct(Breakpoint $breakpoint, $append = '') { @@ -26,7 +26,8 @@ public function __construct(Breakpoint $breakpoint, $append = '') /** * @param string $text - * @param int $charactersCount + * @param int $charactersCount + * * @return string */ public function truncate($text, $charactersCount) @@ -37,6 +38,6 @@ public function truncate($text, $charactersCount) $truncatedText = rtrim(mb_substr($text, 0, $this->breakpoint->calculatePosition($text, $charactersCount))); - return ($truncatedText === $text) ? $truncatedText : $truncatedText . $this->append; + return ($truncatedText === $text) ? $truncatedText : $truncatedText.$this->append; } } diff --git a/src/Coduo/PHPHumanizer/String/TruncateInterface.php b/src/Coduo/PHPHumanizer/String/TruncateInterface.php index a6e1bb7..2f20dd3 100644 --- a/src/Coduo/PHPHumanizer/String/TruncateInterface.php +++ b/src/Coduo/PHPHumanizer/String/TruncateInterface.php @@ -2,11 +2,12 @@ namespace Coduo\PHPHumanizer\String; -interface TruncateInterface +interface TruncateInterface { /** * @param string $text - * @param int $charactersCount + * @param int $charactersCount + * * @return string mixed */ public function truncate($text, $charactersCount); diff --git a/src/Coduo/PHPHumanizer/String/WordBreakpoint.php b/src/Coduo/PHPHumanizer/String/WordBreakpoint.php index de3d8e2..1ce25fc 100644 --- a/src/Coduo/PHPHumanizer/String/WordBreakpoint.php +++ b/src/Coduo/PHPHumanizer/String/WordBreakpoint.php @@ -9,17 +9,17 @@ public function calculatePosition($text, $charactersCount) if ($charactersCount < 0) { return mb_strlen($text); } - + if ($charactersCount > mb_strlen($text)) { return mb_strlen($text); } $breakpoint = mb_strpos($text, ' ', $charactersCount); - + if (false === $breakpoint) { return mb_strlen($text); } - + return $breakpoint; } } diff --git a/src/Coduo/PHPHumanizer/StringHumanizer.php b/src/Coduo/PHPHumanizer/StringHumanizer.php index 3cd85b3..eb158f3 100644 --- a/src/Coduo/PHPHumanizer/StringHumanizer.php +++ b/src/Coduo/PHPHumanizer/StringHumanizer.php @@ -13,8 +13,8 @@ final class StringHumanizer /** * @param $text * @param bool|true $capitalize - * @param string $separator - * @param array $forbiddenWords + * @param string $separator + * @param array $forbiddenWords * * @return string */ @@ -52,6 +52,10 @@ public static function truncateHtml($text, $charactersCount, $allowedTags = '', return $truncate->truncate($text, $charactersCount); } + /** + * @param $text + * @return string + */ public static function removeShortcodes($text) { $processor = new ShortcodeProcessor(); @@ -59,6 +63,10 @@ public static function removeShortcodes($text) return $processor->removeShortcodes($text); } + /** + * @param $text + * @return string + */ public static function removeShortcodeTags($text) { $processor = new ShortcodeProcessor(); From f093f86db7615c500eec48b8b0ddca60523bb8dd Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 13 Dec 2015 14:59:28 +0100 Subject: [PATCH 3/5] Closed other extension points by adding final to all classes --- .../PHPHumanizer/DateTime/FormatterSpec.php | 20 +++++++------ .../DateTime/PreciseFormatterSpec.php | 28 ++++++++----------- .../PHPHumanizer/Collection/Formatter.php | 2 +- src/Coduo/PHPHumanizer/Collection/Oxford.php | 2 +- .../PHPHumanizer/DateTime/Difference.php | 2 +- .../DateTime/Difference/CompoundResult.php | 2 +- src/Coduo/PHPHumanizer/DateTime/Formatter.php | 2 +- .../DateTime/PreciseDifference.php | 2 +- .../DateTime/PreciseFormatter.php | 2 +- src/Coduo/PHPHumanizer/DateTime/Unit/Day.php | 2 +- src/Coduo/PHPHumanizer/DateTime/Unit/Hour.php | 2 +- .../PHPHumanizer/DateTime/Unit/JustNow.php | 2 +- .../PHPHumanizer/DateTime/Unit/Minute.php | 2 +- .../PHPHumanizer/DateTime/Unit/Month.php | 2 +- .../PHPHumanizer/DateTime/Unit/Second.php | 2 +- src/Coduo/PHPHumanizer/DateTime/Unit/Week.php | 2 +- src/Coduo/PHPHumanizer/DateTime/Unit/Year.php | 2 +- src/Coduo/PHPHumanizer/Number/Ordinal.php | 2 +- .../PHPHumanizer/Number/Ordinal/Builder.php | 2 +- .../PHPHumanizer/Number/RomanNumeral.php | 2 +- .../Resources/Ordinal/EnStrategy.php | 2 +- .../Resources/Ordinal/NlStrategy.php | 2 +- .../PHPHumanizer/String/BinarySuffix.php | 2 +- .../PHPHumanizer/String/HtmlTruncate.php | 2 +- src/Coduo/PHPHumanizer/String/Humanize.php | 2 +- .../PHPHumanizer/String/MetricSuffix.php | 2 +- .../String/ShortcodeProcessor.php | 2 +- .../PHPHumanizer/String/TextTruncate.php | 2 +- .../PHPHumanizer/String/WordBreakpoint.php | 7 ++++- src/Coduo/PHPHumanizer/Translator/Builder.php | 6 +++- 30 files changed, 60 insertions(+), 53 deletions(-) diff --git a/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php b/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php index 97e08d8..4bf48ae 100644 --- a/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php +++ b/spec/Coduo/PHPHumanizer/DateTime/FormatterSpec.php @@ -30,19 +30,23 @@ function let(Translator $translator) )->willReturn('10 minut temu'); } - function it_format_datetime_diff(Difference $diff) + function it_format_datetime_diff() { - $diff->getUnit()->willReturn(new Minute()); - $diff->getQuantity()->willReturn(10); - $diff->isPast()->willReturn(true); + $diff = new Difference( + new \DateTime("2015-01-01 00:10:00"), + new \DateTime("2015-01-01 00:00:00") + ); + $this->formatDifference($diff)->shouldReturn('10 minutes ago'); } - function it_format_datetime_diff_for_specific_locale(Difference $diff) + function it_format_datetime_diff_for_specific_locale() { - $diff->getUnit()->willReturn(new Minute()); - $diff->getQuantity()->willReturn(10); - $diff->isPast()->willReturn(true); + $diff = new Difference( + new \DateTime("2015-01-01 00:10:00"), + new \DateTime("2015-01-01 00:00:00") + ); + $this->formatDifference($diff, 'pl')->shouldReturn('10 minut temu'); } } diff --git a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php index 40ea0f3..1ecf75e 100644 --- a/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php +++ b/spec/Coduo/PHPHumanizer/DateTime/PreciseFormatterSpec.php @@ -62,29 +62,23 @@ function let(Translator $translator) )->willReturn('через 10 дней, 5 часов'); } - function it_format_compound_datetime_diff(PreciseDifference $diff, CompoundResult $dayResult, - CompoundResult $hourResult) + function it_format_compound_datetime_diff() { - $dayResult->getUnit()->willReturn(new Day()); - $dayResult->getQuantity()->willReturn(10); - $hourResult->getUnit()->willReturn(new Hour()); - $hourResult->getQuantity()->willReturn(5); + $diff = new PreciseDifference( + new \DateTime("2015-01-01 00:00:00"), + new \DateTime("2015-01-11 05:00:00") + ); - $diff->getCompoundResults()->willReturn(array($dayResult, $hourResult)); - $diff->isPast()->willReturn(false); $this->formatDifference($diff)->shouldReturn('10 days, 5 hours from now'); } - function it_format_compound_datetime_diff_for_specific_locale(PreciseDifference $diff, - CompoundResult $dayResult, CompoundResult $hourResult) + function it_format_compound_datetime_diff_for_specific_locale() { - $dayResult->getUnit()->willReturn(new Day()); - $dayResult->getQuantity()->willReturn(10); - $hourResult->getUnit()->willReturn(new Hour()); - $hourResult->getQuantity()->willReturn(5); - - $diff->getCompoundResults()->willReturn(array($dayResult, $hourResult)); - $diff->isPast()->willReturn(false); + $diff = new PreciseDifference( + new \DateTime("2015-01-01 00:00:00"), + new \DateTime("2015-01-11 05:00:00") + ); + $this->formatDifference($diff, 'ru')->shouldReturn('через 10 дней, 5 часов'); } } diff --git a/src/Coduo/PHPHumanizer/Collection/Formatter.php b/src/Coduo/PHPHumanizer/Collection/Formatter.php index 4a6a699..926a166 100644 --- a/src/Coduo/PHPHumanizer/Collection/Formatter.php +++ b/src/Coduo/PHPHumanizer/Collection/Formatter.php @@ -4,7 +4,7 @@ use Symfony\Component\Translation\TranslatorInterface; -class Formatter +final class Formatter { /** * @var \Symfony\Component\Translation\TranslatorInterface diff --git a/src/Coduo/PHPHumanizer/Collection/Oxford.php b/src/Coduo/PHPHumanizer/Collection/Oxford.php index 055f50f..13c0fbc 100644 --- a/src/Coduo/PHPHumanizer/Collection/Oxford.php +++ b/src/Coduo/PHPHumanizer/Collection/Oxford.php @@ -2,7 +2,7 @@ namespace Coduo\PHPHumanizer\Collection; -class Oxford +final class Oxford { /** * @var Formatter diff --git a/src/Coduo/PHPHumanizer/DateTime/Difference.php b/src/Coduo/PHPHumanizer/DateTime/Difference.php index a703081..b99124d 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Difference.php +++ b/src/Coduo/PHPHumanizer/DateTime/Difference.php @@ -11,7 +11,7 @@ use Coduo\PHPHumanizer\DateTime\Unit\Week; use Coduo\PHPHumanizer\DateTime\Unit\Year; -class Difference +final class Difference { /** * @var \DateTime diff --git a/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php b/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php index af77a35..79ba44d 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php +++ b/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class CompoundResult +final class CompoundResult { /** * @var \Coduo\PHPHumanizer\DateTime\Unit diff --git a/src/Coduo/PHPHumanizer/DateTime/Formatter.php b/src/Coduo/PHPHumanizer/DateTime/Formatter.php index 8b0ec7b..48222f9 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Formatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/Formatter.php @@ -4,7 +4,7 @@ use Symfony\Component\Translation\TranslatorInterface; -class Formatter +final class Formatter { /** * @var \Symfony\Component\Translation\TranslatorInterface diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php b/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php index 9425d8e..0edfd7e 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php @@ -10,7 +10,7 @@ use Coduo\PHPHumanizer\DateTime\Unit\Year; use Coduo\PHPHumanizer\DateTime\Difference\CompoundResult; -class PreciseDifference +final class PreciseDifference { /** * @var \DateTime diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index af50f8a..46a1b80 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -4,7 +4,7 @@ use Symfony\Component\Translation\TranslatorInterface; -class PreciseFormatter +final class PreciseFormatter { /** * @var \Symfony\Component\Translation\TranslatorInterface diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/Day.php b/src/Coduo/PHPHumanizer/DateTime/Unit/Day.php index fe12aad..880a456 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/Day.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/Day.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class Day implements Unit +final class Day implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/Hour.php b/src/Coduo/PHPHumanizer/DateTime/Unit/Hour.php index dd33269..dcece2f 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/Hour.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/Hour.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class Hour implements Unit +final class Hour implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/JustNow.php b/src/Coduo/PHPHumanizer/DateTime/Unit/JustNow.php index 97b33df..1ed5ce0 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/JustNow.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/JustNow.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class JustNow implements Unit +final class JustNow implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/Minute.php b/src/Coduo/PHPHumanizer/DateTime/Unit/Minute.php index 096e0c1..2a6c895 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/Minute.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/Minute.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class Minute implements Unit +final class Minute implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/Month.php b/src/Coduo/PHPHumanizer/DateTime/Unit/Month.php index 8f94e68..4bbb6ec 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/Month.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/Month.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class Month implements Unit +final class Month implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/Second.php b/src/Coduo/PHPHumanizer/DateTime/Unit/Second.php index 61c95c7..ce8ec27 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/Second.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/Second.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class Second implements Unit +final class Second implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/Week.php b/src/Coduo/PHPHumanizer/DateTime/Unit/Week.php index a35f188..f20bb65 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/Week.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/Week.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class Week implements Unit +final class Week implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit/Year.php b/src/Coduo/PHPHumanizer/DateTime/Unit/Year.php index d2185a0..6c01607 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit/Year.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit/Year.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\DateTime\Unit; -class Year implements Unit +final class Year implements Unit { /** * @return string diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal.php b/src/Coduo/PHPHumanizer/Number/Ordinal.php index f9d8619..c507951 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal.php @@ -5,7 +5,7 @@ use Coduo\PHPHumanizer\Number\Ordinal\Builder; use Coduo\PHPHumanizer\Number\Ordinal\StrategyInterface; -class Ordinal +final class Ordinal { /** * @var int|float diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php b/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php index 7e12f10..e6a686e 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php @@ -5,7 +5,7 @@ /** * Tries to find a proper strategy for ordinal numbers. */ -class Builder +final class Builder { /** * @param string $locale diff --git a/src/Coduo/PHPHumanizer/Number/RomanNumeral.php b/src/Coduo/PHPHumanizer/Number/RomanNumeral.php index 8361d90..7d967f3 100644 --- a/src/Coduo/PHPHumanizer/Number/RomanNumeral.php +++ b/src/Coduo/PHPHumanizer/Number/RomanNumeral.php @@ -2,7 +2,7 @@ namespace Coduo\PHPHumanizer\Number; -class RomanNumeral +final class RomanNumeral { const MIN_VALUE = 1; const MAX_VALUE = 3999; diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php index 1268bfb..7cda141 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\Number\Ordinal\StrategyInterface; -class EnStrategy implements StrategyInterface +final class EnStrategy implements StrategyInterface { /** {@inheritdoc} */ public function ordinalSuffix($number) diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php index b9280f8..54b3f08 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php @@ -4,7 +4,7 @@ use Coduo\PHPHumanizer\Number\Ordinal\StrategyInterface; -class NlStrategy implements StrategyInterface +final class NlStrategy implements StrategyInterface { /** {@inheritdoc} */ public function ordinalSuffix($number) diff --git a/src/Coduo/PHPHumanizer/String/BinarySuffix.php b/src/Coduo/PHPHumanizer/String/BinarySuffix.php index f818cd7..ca13f8e 100644 --- a/src/Coduo/PHPHumanizer/String/BinarySuffix.php +++ b/src/Coduo/PHPHumanizer/String/BinarySuffix.php @@ -2,7 +2,7 @@ namespace Coduo\PHPHumanizer\String; -class BinarySuffix +final class BinarySuffix { const CONVERT_THRESHOLD = 1024; diff --git a/src/Coduo/PHPHumanizer/String/HtmlTruncate.php b/src/Coduo/PHPHumanizer/String/HtmlTruncate.php index 629347f..42f2d15 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 implements TruncateInterface +final class HtmlTruncate implements TruncateInterface { /** * @var string diff --git a/src/Coduo/PHPHumanizer/String/Humanize.php b/src/Coduo/PHPHumanizer/String/Humanize.php index 548acf5..e09896f 100644 --- a/src/Coduo/PHPHumanizer/String/Humanize.php +++ b/src/Coduo/PHPHumanizer/String/Humanize.php @@ -2,7 +2,7 @@ namespace Coduo\PHPHumanizer\String; -class Humanize +final class Humanize { /** * @var string diff --git a/src/Coduo/PHPHumanizer/String/MetricSuffix.php b/src/Coduo/PHPHumanizer/String/MetricSuffix.php index 513ddac..c61bf15 100644 --- a/src/Coduo/PHPHumanizer/String/MetricSuffix.php +++ b/src/Coduo/PHPHumanizer/String/MetricSuffix.php @@ -2,7 +2,7 @@ namespace Coduo\PHPHumanizer\String; -class MetricSuffix +final class MetricSuffix { const CONVERT_THRESHOLD = 1000; diff --git a/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php b/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php index db2a9f6..0e61794 100644 --- a/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php +++ b/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php @@ -7,7 +7,7 @@ use Thunder\Shortcode\Processor\Processor; use Thunder\Shortcode\Shortcode\ShortcodeInterface; -class ShortcodeProcessor +final class ShortcodeProcessor { /** * Removes all shortcodes from given text. diff --git a/src/Coduo/PHPHumanizer/String/TextTruncate.php b/src/Coduo/PHPHumanizer/String/TextTruncate.php index df11ba0..75b8ef7 100644 --- a/src/Coduo/PHPHumanizer/String/TextTruncate.php +++ b/src/Coduo/PHPHumanizer/String/TextTruncate.php @@ -2,7 +2,7 @@ namespace Coduo\PHPHumanizer\String; -class TextTruncate implements TruncateInterface +final class TextTruncate implements TruncateInterface { /** * @var string diff --git a/src/Coduo/PHPHumanizer/String/WordBreakpoint.php b/src/Coduo/PHPHumanizer/String/WordBreakpoint.php index 1ce25fc..eb06d9b 100644 --- a/src/Coduo/PHPHumanizer/String/WordBreakpoint.php +++ b/src/Coduo/PHPHumanizer/String/WordBreakpoint.php @@ -2,8 +2,13 @@ namespace Coduo\PHPHumanizer\String; -class WordBreakpoint implements Breakpoint +final class WordBreakpoint implements Breakpoint { + /** + * @param string $text + * @param int $charactersCount + * @return bool|int + */ public function calculatePosition($text, $charactersCount) { if ($charactersCount < 0) { diff --git a/src/Coduo/PHPHumanizer/Translator/Builder.php b/src/Coduo/PHPHumanizer/Translator/Builder.php index 7131ed1..ca8ddd8 100644 --- a/src/Coduo/PHPHumanizer/Translator/Builder.php +++ b/src/Coduo/PHPHumanizer/Translator/Builder.php @@ -5,8 +5,12 @@ use Symfony\Component\Translation\Loader\YamlFileLoader; use Symfony\Component\Translation\Translator; -class Builder +final class Builder { + /** + * @param $locale + * @return Translator + */ public static function build($locale) { $translator = new Translator($locale); From 484ff81cffc6de16fdbf3d9e59dad58e1d1477c8 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 13 Dec 2015 18:10:03 +0100 Subject: [PATCH 4/5] Updated dependencies to handle symfony 3.0 --- composer.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 2a40401..5673922 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,10 @@ ], "require": { "php": ">=5.3.0", - "symfony/intl": "~2.3", - "symfony/config": "~2.3", - "symfony/translation": "~2.3", - "symfony/yaml": "~2.3", + "symfony/intl": "^2.3|^3.0", + "symfony/config": "^2.3|^3.0", + "symfony/translation": "^2.3|^3.0", + "symfony/yaml": "^2.3|^3.0", "thunderer/shortcode": "~0.5" }, "require-dev": { From c0d04f26b7e894f347087216c013cf11ae26c317 Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 13 Dec 2015 18:35:59 +0100 Subject: [PATCH 5/5] Removed allowing failures on lowest dependencies --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f8207c..e54e070 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,8 +16,6 @@ matrix: - php: 5.6 - php: 7.0 - php: hhvm - allow_failures: - - env: DEPENDENCIES='low' before_install: - composer self-update