diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..15c1f68 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +# 2.0 + +* Added support for PHP7 +* Updated dependencies to support Symfony3 components +* Added support for Ordinal number strategies that require prefixes diff --git a/UPGRADE.md b/UPGRADE.md new file mode 100644 index 0000000..ab3a500 --- /dev/null +++ b/UPGRADE.md @@ -0,0 +1,9 @@ +# Upgrade 1.0 to 2.0 + +* All classes are now marked as final in order to close extra extension points +* Renamed ``Coduo\PHPHumanizer\Collection`` into ``Coduo\PHPHumanizer\CollectionHumanizer`` +* Renamed ``Coduo\PHPHumanizer\DateTime`` into ``Coduo\PHPHumanizer\DateTimeHumanizer`` +* Renamed ``Coduo\PHPHumanizer\Number`` into ``Coduo\PHPHumanizer\NumberHumanizer`` +* Renamed ``Coduo\PHPHumanizer\String`` into ``Coduo\PHPHumanizer\StringHumanizer`` +* Replaced ``ordinalSuffix($number)`` method in ``Coduo\PHPHumanizer\Number\Ordinal\StrategyInterface`` with ``isPrefix()`` and ``ordinalIndicator($number)`` +* Dependency ``thunderer/shortcode`` was removed, now shortcode lib needs to be added to project \ No newline at end of file diff --git a/composer.json b/composer.json index 5673922..78a33d6 100644 --- a/composer.json +++ b/composer.json @@ -18,10 +18,10 @@ "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" + "symfony/yaml": "^2.3|^3.0" }, "require-dev": { + "thunderer/shortcode": "~0.5", "phpspec/phpspec": "^2", "phpunit/phpunit": "^4.5|^5.0" }, diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php b/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php index 470e87a..0e0664c 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal/StrategyInterface.php @@ -4,10 +4,10 @@ interface StrategyInterface { - /** - * @return boolean - */ - public function isPrefix(); + /** + * @return boolean + */ + public function isPrefix(); /** * @param int|float $number diff --git a/src/Coduo/PHPHumanizer/NumberHumanizer.php b/src/Coduo/PHPHumanizer/NumberHumanizer.php index b2354a9..886a2d5 100644 --- a/src/Coduo/PHPHumanizer/NumberHumanizer.php +++ b/src/Coduo/PHPHumanizer/NumberHumanizer.php @@ -18,10 +18,8 @@ final class NumberHumanizer public static function ordinalize($number, $locale = 'en') { $ordinal = new Ordinal($number, $locale); - if ($ordinal->isPrefix()) { - return (string) $ordinal.$number; - } - else return (string) $number.$ordinal; + + return (string) ($ordinal->isPrefix()) ? $ordinal.$number : $number.$ordinal; } /** @@ -33,6 +31,7 @@ public static function ordinalize($number, $locale = 'en') public static function ordinal($number, $locale = 'en') { $ordinal = new Ordinal($number, $locale); + return (string) $ordinal; } diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php index 5b7ebb7..cec3754 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/EnStrategy.php @@ -6,17 +6,22 @@ final class EnStrategy implements StrategyInterface { - /** {@inheritdoc}*/ - public function isPrefix(){ - return False; + /** + * {@inheritdoc} + */ + public function isPrefix() + { + return false; } - /** {@inheritdoc} */ + /** + * {@inheritdoc} + */ public function ordinalIndicator($number) { $absNumber = abs((integer) $number); - if (in_array(($absNumber % 100), array(11, 12, 13))) { + if (in_array(($absNumber % 100), array(11, 12, 13), true)) { return 'th'; } diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/IdStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/IdStrategy.php index e4ba1e4..951971e 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/IdStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/IdStrategy.php @@ -6,12 +6,17 @@ final class IdStrategy implements StrategyInterface { - /** {@inheritdoc}*/ - public function isPrefix(){ - return True; + /** + * {@inheritdoc} + */ + public function isPrefix() + { + return true; } - - /** {@inheritdoc} */ + + /** + * {@inheritdoc} + */ public function ordinalIndicator($number) { return 'ke-'; diff --git a/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php b/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php index 4390130..c7f47ee 100644 --- a/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php +++ b/src/Coduo/PHPHumanizer/Resources/Ordinal/NlStrategy.php @@ -6,12 +6,17 @@ final class NlStrategy implements StrategyInterface { - /** {@inheritdoc}*/ - public function isPrefix(){ + /** + * {@inheritdoc} + */ + public function isPrefix() + { return False; } - /** {@inheritdoc} */ + /** + * {@inheritdoc} + */ public function ordinalIndicator($number) { return 'e'; diff --git a/src/Coduo/PHPHumanizer/StringHumanizer.php b/src/Coduo/PHPHumanizer/StringHumanizer.php index eb158f3..686fe59 100644 --- a/src/Coduo/PHPHumanizer/StringHumanizer.php +++ b/src/Coduo/PHPHumanizer/StringHumanizer.php @@ -58,6 +58,10 @@ public static function truncateHtml($text, $charactersCount, $allowedTags = '', */ public static function removeShortcodes($text) { + if (!class_exists('Thunder\Shortcode\Processor\Processor')) { + throw new \RuntimeException("Please add \"thunderer/shortcode\": ~0.5 to composer.json first"); + } + $processor = new ShortcodeProcessor(); return $processor->removeShortcodes($text); @@ -69,6 +73,10 @@ public static function removeShortcodes($text) */ public static function removeShortcodeTags($text) { + if (!class_exists('Thunder\Shortcode\Processor\Processor')) { + throw new \RuntimeException("Please add \"thunderer/shortcode\": ~0.5 to composer.json first"); + } + $processor = new ShortcodeProcessor(); return $processor->removeShortcodeTags($text);