diff --git a/.gitignore b/.gitignore index a3f78a6..f0bf8a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ vendor/ bin/ composer.lock -composer.phar \ No newline at end of file +composer.phar +.php_cs.cache \ No newline at end of file diff --git a/.php_cs b/.php_cs new file mode 100644 index 0000000..5983888 --- /dev/null +++ b/.php_cs @@ -0,0 +1,18 @@ +setRules([ + '@PSR2' => true, + 'declare_strict_types' => true, + 'array_syntax' => ['syntax' => 'short'], + 'blank_line_after_opening_tag' => true, + 'single_blank_line_before_namespace' => true, + 'no_unused_imports' => true, + 'single_quote' => true, + 'native_function_invocation' => true + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__ . '/src') + ->in(__DIR__ . '/tests') + )->setRiskyAllowed(true) + ->setUsingCache(false); \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index e54e070..35d2afa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,26 +5,22 @@ sudo: false cache: directories: - $HOME/.composer/cache - + matrix: include: - - php: 5.3 - env: DEPENDENCIES='low' - - php: 5.3 - - php: 5.4 - - php: 5.5 - - php: 5.6 - php: 7.0 - - php: hhvm + - php: 7.1 + - php: 7.2 + - php: 7.3 before_install: - composer self-update install: - export COMPOSER_ROOT_VERSION=dev-master - - if [ "$DEPENDENCIES" != "low" ]; then composer update; fi; - - if [ "$DEPENDENCIES" == "low" ]; then composer update --prefer-lowest; fi; + - composer update script: - ./bin/phpspec run --format=pretty - - ./bin/phpunit + - ./bin/phpunit + - ./bin/php-cs-fixer fix -v --dry-run \ No newline at end of file diff --git a/README.md b/README.md index 04d2502..d530903 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#PHP Humanizer +# PHP Humanizer [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=master)](https://travis-ci.org/coduo/php-humanizer) [![Latest Stable Version](https://poser.pugx.org/coduo/php-humanizer/v/stable)](https://packagist.org/packages/coduo/php-humanizer) @@ -6,9 +6,19 @@ [![Latest Unstable Version](https://poser.pugx.org/coduo/php-humanizer/v/unstable)](https://packagist.org/packages/coduo/php-humanizer) [![License](https://poser.pugx.org/coduo/php-humanizer/license)](https://packagist.org/packages/coduo/php-humanizer) +### Tests +* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=master)](https://travis-ci.org/coduo/php-humanizer) - master (3.0) +* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=2.0)](https://travis-ci.org/coduo/php-humanizer) - 2.0 +* [![Build Status](https://travis-ci.org/coduo/php-humanizer.svg?branch=1.0)](https://travis-ci.org/coduo/php-humanizer) - 1.0 + +[Readme for master (3.0) version](https://github.com/coduo/php-humanizer/tree/master/README.md) +[Readme for 2.0 version](https://github.com/coduo/php-matcher/tree/2.0/README.md) +[Readme for 1.0 version](https://github.com/coduo/php-matcher/tree/1.0/README.md) + + Humanize values to make them readable for regular people ;) -#Installation +# Installation Run the following command: @@ -16,7 +26,7 @@ Run the following command: composer require coduo/php-humanizer ``` -#Usage +# Usage ## Text diff --git a/composer.json b/composer.json index 1615773..def4c0a 100644 --- a/composer.json +++ b/composer.json @@ -15,10 +15,11 @@ } ], "require": { - "php": ">=5.3.0", - "symfony/config": "^2.3|^3.0", - "symfony/translation": "^2.3|^3.0", - "symfony/yaml": "^2.3|^3.0" + "php": ">=7.0.0", + "symfony/config": "^2.3|^3.0|^4.0", + "symfony/translation": "^2.3|^3.0|^4.0", + "symfony/yaml": "^2.3|^3.0|^4.0", + "friendsofphp/php-cs-fixer": "^2.14" }, "require-dev": { "thunderer/shortcode": "~0.5", @@ -36,7 +37,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.1-dev" + "dev-master": "3.0-dev" } }, "suggest": { diff --git a/src/Coduo/PHPHumanizer/Collection/Formatter.php b/src/Coduo/PHPHumanizer/Collection/Formatter.php index 926a166..60f51c4 100644 --- a/src/Coduo/PHPHumanizer/Collection/Formatter.php +++ b/src/Coduo/PHPHumanizer/Collection/Formatter.php @@ -1,5 +1,7 @@ translator->transChoice('comma_separated_with_limit', $moreCount, array( - '%list%' => implode(', ', $display), + return $this->translator->transChoice('comma_separated_with_limit', $moreCount, [ + '%list%' => \implode(', ', $display), '%count%' => $moreCount, - ), $this->catalogue); + ], $this->catalogue); } /** @@ -77,14 +79,14 @@ private function formatCommaSeparatedWithLimit($collection, $limit, $count) */ private function formatCommaSeparated($collection, $count) { - $display = array_map(function ($element) { + $display = \array_map(function ($element) { return (string) $element; - }, array_slice($collection, 0, $count - 1)); + }, \array_slice($collection, 0, $count - 1)); - return $this->translator->trans('comma_separated', array( - '%list%' => implode(', ', $display), - '%last%' => (string) end($collection), - ), $this->catalogue); + return $this->translator->trans('comma_separated', [ + '%list%' => \implode(', ', $display), + '%last%' => (string) \end($collection), + ], $this->catalogue); } /** @@ -94,9 +96,9 @@ private function formatCommaSeparated($collection, $count) */ private function formatOnlyTwo($collection) { - return $this->translator->trans('only_two', array( + return $this->translator->trans('only_two', [ '%first%' => (string) $collection[0], '%second%' => (string) $collection[1], - ), $this->catalogue); + ], $this->catalogue); } } diff --git a/src/Coduo/PHPHumanizer/Collection/Oxford.php b/src/Coduo/PHPHumanizer/Collection/Oxford.php index 13c0fbc..c102712 100644 --- a/src/Coduo/PHPHumanizer/Collection/Oxford.php +++ b/src/Coduo/PHPHumanizer/Collection/Oxford.php @@ -1,5 +1,7 @@ toDate->getTimestamp() - $this->fromDate->getTimestamp()) * 1000; + $absoluteMilliSecondsDiff = \abs($this->toDate->getTimestamp() - $this->fromDate->getTimestamp()) * 1000; foreach ($units as $unit) { if ($absoluteMilliSecondsDiff >= $unit->getMilliseconds()) { $this->unit = $unit; @@ -80,7 +82,7 @@ private function calculate() $this->quantity = ($absoluteMilliSecondsDiff == 0) ? $absoluteMilliSecondsDiff - : (int) round($absoluteMilliSecondsDiff / $this->unit->getMilliseconds()); + : (int) \round($absoluteMilliSecondsDiff / $this->unit->getMilliseconds()); } public function isPast() diff --git a/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php b/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php index 79ba44d..4721c2e 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php +++ b/src/Coduo/PHPHumanizer/DateTime/Difference/CompoundResult.php @@ -1,5 +1,7 @@ getUnit()->getName(), $difference->isPast() ? 'past' : 'future'); + $translationKey = \sprintf('%s.%s', $difference->getUnit()->getName(), $difference->isPast() ? 'past' : 'future'); return $this->translator->transChoice( $translationKey, $difference->getQuantity(), - array('%count%' => $difference->getQuantity()), + ['%count%' => $difference->getQuantity()], 'difference', $locale ); diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php b/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php index 0edfd7e..221f1a6 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseDifference.php @@ -1,5 +1,7 @@ fromDate->diff($this->toDate); diff --git a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php index 46a1b80..52a2e34 100644 --- a/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php +++ b/src/Coduo/PHPHumanizer/DateTime/PreciseFormatter.php @@ -1,5 +1,7 @@ getCompoundResults() as $result) { $diff[] = $this->translator->transChoice( 'compound.'.$result->getUnit()->getName(), $result->getQuantity(), - array('%count%' => $result->getQuantity()), + ['%count%' => $result->getQuantity()], 'difference', $locale ); @@ -41,7 +43,7 @@ public function formatDifference(PreciseDifference $difference, $locale = 'en') return $this->translator->trans( 'compound.'.($difference->isPast() ? 'past' : 'future'), - array('%value%' => implode(', ', $diff)), + ['%value%' => \implode(', ', $diff)], 'difference', $locale ); diff --git a/src/Coduo/PHPHumanizer/DateTime/Unit.php b/src/Coduo/PHPHumanizer/DateTime/Unit.php index 75681f5..bac4b47 100644 --- a/src/Coduo/PHPHumanizer/DateTime/Unit.php +++ b/src/Coduo/PHPHumanizer/DateTime/Unit.php @@ -1,5 +1,7 @@ strategy ->ordinalIndicator($this->number); } -} \ No newline at end of file +} diff --git a/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php b/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php index e6a686e..86a5b82 100644 --- a/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php +++ b/src/Coduo/PHPHumanizer/Number/Ordinal/Builder.php @@ -1,5 +1,7 @@ 1000, 'CM' => 900, 'D' => 500, @@ -22,7 +24,7 @@ final class RomanNumeral 'V' => 5, 'IV' => 4, 'I' => 1, - ); + ]; /** * @param $number @@ -61,12 +63,12 @@ public function toRoman($number) */ public function fromRoman($string) { - if (mb_strlen($string) === 0 || 0 === preg_match(self::ROMAN_STRING_MATCHER, $string)) { + if (\mb_strlen((string) $string) === 0 || 0 === \preg_match(self::ROMAN_STRING_MATCHER, (string) $string)) { throw new \InvalidArgumentException(); } $total = 0; - $i = mb_strlen($string); + $i = \mb_strlen($string); while ($i > 0) { $digit = $this->map[$string{--$i}]; diff --git a/src/Coduo/PHPHumanizer/NumberHumanizer.php b/src/Coduo/PHPHumanizer/NumberHumanizer.php index 886a2d5..25835ea 100644 --- a/src/Coduo/PHPHumanizer/NumberHumanizer.php +++ b/src/Coduo/PHPHumanizer/NumberHumanizer.php @@ -1,5 +1,7 @@ '#.## PB', 1099511627776 => '#.## TB', 1073741824 => '#.## GB', 1048576 => '#.## MB', 1024 => '#.# kB', 0 => '# bytes', - ); + ]; /** * @param int $number @@ -37,11 +39,11 @@ final class BinarySuffix */ public function __construct($number, $locale = 'en', $precision = null) { - if (!is_numeric($number)) { + if (!\is_numeric($number)) { throw new \InvalidArgumentException('Binary suffix converter accept only numeric values.'); } - if (!is_null($precision)) { + if (!\is_null($precision)) { $this->setSpecificPrecisionFormat($precision); } @@ -52,7 +54,7 @@ public function __construct($number, $locale = 'en', $precision = null) * Workaround for 32-bit systems which ignore array ordering when * dropping values over 2^32-1 */ - krsort($this->binaryPrefixes); + \krsort($this->binaryPrefixes); } public function convert() @@ -94,12 +96,12 @@ protected function setSpecificPrecisionFormat($precision) $icuFormat = '#'; if ($precision > 0) { - $icuFormat .= str_pad('#.', (2 + $precision), '0'); + $icuFormat .= \str_pad('#.', (2 + $precision), '0'); } foreach ($this->binaryPrefixes as $size => $unitPattern) { if ($size >= 1024) { - $symbol = substr($unitPattern, strpos($unitPattern, ' ')); + $symbol = \substr($unitPattern, \strpos($unitPattern, ' ')); $this->binaryPrefixes[$size] = $icuFormat.$symbol; } } diff --git a/src/Coduo/PHPHumanizer/String/Breakpoint.php b/src/Coduo/PHPHumanizer/String/Breakpoint.php index 23d37f1..911381b 100644 --- a/src/Coduo/PHPHumanizer/String/Breakpoint.php +++ b/src/Coduo/PHPHumanizer/String/Breakpoint.php @@ -1,5 +1,7 @@ allowedTags); + $strippedText = \strip_tags($text, $this->allowedTags); return $this->truncateHtml($strippedText, $charactersCount); } @@ -56,37 +58,37 @@ private function truncateHtml($string, $charactersCount) { $limit = $charactersCount; $offset = 0; - $tags = array(); + $tags = []; // Handle special characters. - preg_match_all('/&[a-z]+;/i', strip_tags($string), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); + \preg_match_all('/&[a-z]+;/i', \strip_tags($string), $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); foreach ($matches as $match) { if ($match[0][1] >= $limit) { break; } - $limit += (mb_strlen($match[0][0]) - 1); + $limit += (\mb_strlen($match[0][0]) - 1); } // Handle all the html tags. - preg_match_all('/<[^>]+>([^<]*)/', $string, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); + \preg_match_all('/<[^>]+>([^<]*)/', $string, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER); foreach ($matches as $match) { if ($match[0][1] - $offset >= $limit) { break; } - $tag = mb_substr(strtok($match[0][0], " \t\n\r\0\x0B>"), 1); + $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); + } 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)) ? ''.implode('>', $tags).'>' : ''); + $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)) ? ''.\implode('>', $tags).'>' : ''); return $newString; } diff --git a/src/Coduo/PHPHumanizer/String/Humanize.php b/src/Coduo/PHPHumanizer/String/Humanize.php index e09896f..92c27cd 100644 --- a/src/Coduo/PHPHumanizer/String/Humanize.php +++ b/src/Coduo/PHPHumanizer/String/Humanize.php @@ -1,5 +1,7 @@ text = $text; $this->capitalize = $capitalize; @@ -38,9 +40,9 @@ public function __construct($text, $capitalize = true, $separator = '_', array $ */ 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(\strtolower(\preg_replace(['/([A-Z])/', "/[{$this->separator}\\s]+/"], ['_$1', ' '], $this->text))); + $humanized = \trim(\str_replace($this->forbiddenWords, '', $humanized)); - return $this->capitalize ? ucfirst($humanized) : $humanized; + return $this->capitalize ? \ucfirst($humanized) : $humanized; } } diff --git a/src/Coduo/PHPHumanizer/String/MetricSuffix.php b/src/Coduo/PHPHumanizer/String/MetricSuffix.php index 2e818d9..2d19637 100644 --- a/src/Coduo/PHPHumanizer/String/MetricSuffix.php +++ b/src/Coduo/PHPHumanizer/String/MetricSuffix.php @@ -1,5 +1,7 @@ '#.##P', 1000000000000 => '#.##T', 1000000000 => '#.##G', 1000000 => '#.##M', 1000 => '#.#k', 0 => '#.#', - ); + ]; /** * @param $number @@ -36,7 +38,7 @@ final class MetricSuffix */ public function __construct($number, $locale = 'en') { - if (!is_numeric($number)) { + if (!\is_numeric($number)) { throw new \InvalidArgumentException('Metric suffix converter accept only numeric values.'); } @@ -47,7 +49,7 @@ public function __construct($number, $locale = 'en') * Workaround for 32-bit systems which ignore array ordering when * dropping values over 2^32-1 */ - krsort($this->binaryPrefixes); + \krsort($this->binaryPrefixes); } public function convert() diff --git a/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php b/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php index 0e61794..22cbd69 100644 --- a/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php +++ b/src/Coduo/PHPHumanizer/String/ShortcodeProcessor.php @@ -1,5 +1,7 @@ breakpoint->calculatePosition($text, $charactersCount))); + $truncatedText = \rtrim(\mb_substr($text, 0, $this->breakpoint->calculatePosition($text, $charactersCount))); return ($truncatedText === $text) ? $truncatedText : $truncatedText.$this->append; } diff --git a/src/Coduo/PHPHumanizer/String/TruncateInterface.php b/src/Coduo/PHPHumanizer/String/TruncateInterface.php index 2f20dd3..849b06b 100644 --- a/src/Coduo/PHPHumanizer/String/TruncateInterface.php +++ b/src/Coduo/PHPHumanizer/String/TruncateInterface.php @@ -1,5 +1,7 @@ mb_strlen($text)) { - return mb_strlen($text); + if ($charactersCount > \mb_strlen($text)) { + return \mb_strlen($text); } - $breakpoint = mb_strpos($text, ' ', $charactersCount); + $breakpoint = \mb_strpos($text, ' ', $charactersCount); if (false === $breakpoint) { - return mb_strlen($text); + return \mb_strlen($text); } return $breakpoint; diff --git a/src/Coduo/PHPHumanizer/StringHumanizer.php b/src/Coduo/PHPHumanizer/StringHumanizer.php index 686fe59..bf07789 100644 --- a/src/Coduo/PHPHumanizer/StringHumanizer.php +++ b/src/Coduo/PHPHumanizer/StringHumanizer.php @@ -1,5 +1,7 @@ getBasename('.yml'); - list($fileDomain, $fileLocale) = explode('.', $resourceName); + list($fileDomain, $fileLocale) = \explode('.', $resourceName); $translator->addResource('yml', $file->getPathname(), $fileLocale, $fileDomain); } diff --git a/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php b/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php index d759af8..c36703a 100644 --- a/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/CollectionHumanizerTest.php @@ -1,5 +1,7 @@ assertEquals($expectedResult, CollectionHumanizer::oxford($collection, $limit, $locale)); } public function oxfordCollectionProvider() { - return array( + return [ // English - array(array("Michal"), null, 'en', 'Michal'), - array(array("Michal", "Norbert"), null, 'en', 'Michal and Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'en', 'Michal, Norbert, and 1 other'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'en', 'Michal, Norbert, and 2 others'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'en', 'Michal, Norbert, Lukasz, and Pawel'), + [['Michal'], null, 'en', 'Michal'], + [['Michal', 'Norbert'], null, 'en', 'Michal and Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'en', 'Michal, Norbert, and 1 other'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'en', 'Michal, Norbert, and 2 others'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'en', 'Michal, Norbert, Lukasz, and Pawel'], // Chinese Simplified - array(array("Michal"), null, 'zh_CN', 'Michal'), - array(array("Michal", "Norbert"), null, 'zh_CN', 'Michal 和 Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'zh_CN', 'Michal, Norbert 和另一个'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'zh_CN', 'Michal, Norbert 和另 2 个'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'zh_CN', 'Michal, Norbert, Lukasz, 和 Pawel'), + [['Michal'], null, 'zh_CN', 'Michal'], + [['Michal', 'Norbert'], null, 'zh_CN', 'Michal 和 Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'zh_CN', 'Michal, Norbert 和另一个'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'zh_CN', 'Michal, Norbert 和另 2 个'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'zh_CN', 'Michal, Norbert, Lukasz, 和 Pawel'], // Polish - array(array("Michal"), null, 'pl', 'Michal'), - array(array("Michal", "Norbert"), null, 'pl', 'Michal i Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'pl', 'Michal, Norbert i 1 inny'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'pl', 'Michal, Norbert i 2 innych'), + [['Michal'], null, 'pl', 'Michal'], + [['Michal', 'Norbert'], null, 'pl', 'Michal i Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'pl', 'Michal, Norbert i 1 inny'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'pl', 'Michal, Norbert i 2 innych'], // Dutch - array(array("Michal"), null, 'nl', 'Michal'), - array(array("Michal", "Norbert"), null, 'nl', 'Michal en Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'nl', 'Michal, Norbert, en 1 andere'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'nl', 'Michal, Norbert, en 2 andere'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'nl', 'Michal, Norbert, Lukasz, en Pawel'), + [['Michal'], null, 'nl', 'Michal'], + [['Michal', 'Norbert'], null, 'nl', 'Michal en Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'nl', 'Michal, Norbert, en 1 andere'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'nl', 'Michal, Norbert, en 2 andere'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'nl', 'Michal, Norbert, Lukasz, en Pawel'], // Russian - array(array("Michal"), null, 'ru', 'Michal'), - array(array("Michal", "Norbert"), null, 'ru', 'Michal и Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'ru', 'Michal, Norbert и ещё 1'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'ru', 'Michal, Norbert и ещё 2'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'ru', 'Michal, Norbert, Lukasz и Pawel'), + [['Michal'], null, 'ru', 'Michal'], + [['Michal', 'Norbert'], null, 'ru', 'Michal и Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'ru', 'Michal, Norbert и ещё 1'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'ru', 'Michal, Norbert и ещё 2'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'ru', 'Michal, Norbert, Lukasz и Pawel'], // Indonesian - array(array("Michal"), null, 'id', 'Michal'), - array(array("Michal", "Norbert"), null, 'id', 'Michal dan Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'id', 'Michal, Norbert, dan 1 lainnya'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'id', 'Michal, Norbert, dan 2 lainnya'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'id', 'Michal, Norbert, Lukasz, dan Pawel'), + [['Michal'], null, 'id', 'Michal'], + [['Michal', 'Norbert'], null, 'id', 'Michal dan Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'id', 'Michal, Norbert, dan 1 lainnya'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'id', 'Michal, Norbert, dan 2 lainnya'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'id', 'Michal, Norbert, Lukasz, dan Pawel'], // Ukrainian - array(array("Michal"), null, 'uk', 'Michal'), - array(array("Michal", "Norbert"), null, 'uk', 'Michal та Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'uk', 'Michal, Norbert і ще 1'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'uk', 'Michal, Norbert і ще 2'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'uk', 'Michal, Norbert, Lukasz та Pawel'), + [['Michal'], null, 'uk', 'Michal'], + [['Michal', 'Norbert'], null, 'uk', 'Michal та Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'uk', 'Michal, Norbert і ще 1'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'uk', 'Michal, Norbert і ще 2'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'uk', 'Michal, Norbert, Lukasz та Pawel'], // Thai - array(array("Michal"), null, 'th', 'Michal'), - array(array("Michal", "Norbert"), null, 'th', 'Michal และ Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'th', 'Michal, Norbert และอีก 1'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'th', 'Michal, Norbert และอีก 2'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'th', 'Michal, Norbert, Lukasz และ Pawel'), + [['Michal'], null, 'th', 'Michal'], + [['Michal', 'Norbert'], null, 'th', 'Michal และ Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'th', 'Michal, Norbert และอีก 1'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'th', 'Michal, Norbert และอีก 2'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'th', 'Michal, Norbert, Lukasz และ Pawel'], // Japanese - array(array("Michal"), null, 'ja', 'Michal'), - array(array("Michal", "Norbert"), null, 'ja', 'Michal と Norbert'), - array(array("Michal", "Norbert", "Lukasz"), 2, 'ja', 'Michal, Norbert ともうひとり'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), 2, 'ja', 'Michal, Norbert ともう 2 人'), - array(array("Michal", "Norbert", "Lukasz", "Pawel"), null, 'ja', 'Michal, Norbert, Lukasz と Pawel'), - ); + [['Michal'], null, 'ja', 'Michal'], + [['Michal', 'Norbert'], null, 'ja', 'Michal と Norbert'], + [['Michal', 'Norbert', 'Lukasz'], 2, 'ja', 'Michal, Norbert ともうひとり'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], 2, 'ja', 'Michal, Norbert ともう 2 人'], + [['Michal', 'Norbert', 'Lukasz', 'Pawel'], null, 'ja', 'Michal, Norbert, Lukasz と Pawel'], + ]; } } diff --git a/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php b/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php index 9ae9e94..628e3f6 100644 --- a/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php +++ b/tests/Coduo/PHPHumanizer/Tests/DateTimeHumanizerTest.php @@ -1,5 +1,7 @@ assertEquals($expected, StringHumanizer::truncate($text, $charactersCount, $append)); } @@ -43,7 +45,7 @@ function test_truncate_string_to_word_closest_to_a_certain_number_of_characters( * @param $expected * @param $append */ - function test_truncate_string_to_word_closest_to_a_certain_number_of_characters_with_html_tags($text, $charactersCount, $allowedTags, $expected, $append = '') + public function test_truncate_string_to_word_closest_to_a_certain_number_of_characters_with_html_tags($text, $charactersCount, $allowedTags, $expected, $append = '') { $this->assertEquals($expected, StringHumanizer::truncateHtml($text, $charactersCount, $allowedTags, $append)); } @@ -54,7 +56,7 @@ function test_truncate_string_to_word_closest_to_a_certain_number_of_characters_ * @param $text * @param $expected */ - function test_remove_all_shortcodes_from_text($text, $expected) + public function test_remove_all_shortcodes_from_text($text, $expected) { $this->assertEquals($expected, StringHumanizer::removeShortcodes($text)); } @@ -65,25 +67,25 @@ function test_remove_all_shortcodes_from_text($text, $expected) * @param $text * @param $expected */ - function test_remove_only_shortcode_tags_from_text($text, $expected) + public function test_remove_only_shortcode_tags_from_text($text, $expected) { $this->assertEquals($expected, StringHumanizer::removeShortcodeTags($text)); } public function removeAllShortcodesProvider() { - return array( - array('some [text] containing [shortcodes /] and [stuff]with[/stuff] content', 'some containing and content'), - array('some [text] containing [shortcodes /] and [stuff]with[/stuff] content [/text]', 'some '), - ); + return [ + ['some [text] containing [shortcodes /] and [stuff]with[/stuff] content', 'some containing and content'], + ['some [text] containing [shortcodes /] and [stuff]with[/stuff] content [/text]', 'some '], + ]; } public function removeShortcodeTagsProvider() { - return array( - array('some [text] containing [shortcodes /] and [stuff]with[/stuff] content', 'some containing and with content'), - array('some [text] containing [shortcodes /] and [stuff]with[/stuff] content [/text]', 'some containing and with content '), - ); + return [ + ['some [text] containing [shortcodes /] and [stuff]with[/stuff] content', 'some containing and with content'], + ['some [text] containing [shortcodes /] and [stuff]with[/stuff] content [/text]', 'some containing and with content '], + ]; } /** @@ -91,15 +93,15 @@ public function removeShortcodeTagsProvider() */ public function humanizeStringProvider() { - return array( - array('news_count', 'News count', true, '_', array('id')), - array('user', 'user', false, '_', array('id')), - array('news_id', 'News', true, '_', array('id')), - array('customer_id', 'Customer id', true, '_', array()), - array('news_count', 'News count', true, '_', array('id')), - array('news-count', 'News count', true, '-', array('id')), - array('news-count', 'news count', false, '-', array('id')) - ); + return [ + ['news_count', 'News count', true, '_', ['id']], + ['user', 'user', false, '_', ['id']], + ['news_id', 'News', true, '_', ['id']], + ['customer_id', 'Customer id', true, '_', []], + ['news_count', 'News count', true, '_', ['id']], + ['news-count', 'News count', true, '-', ['id']], + ['news-count', 'news count', false, '-', ['id']] + ]; } /** @@ -111,24 +113,24 @@ public function truncateStringProvider() $longText = 'Lorem ipsum dolorem si amet, lorem ipsum. Dolorem sic et nunc.'; $shortText = 'Short text'; - return array( - array($longText, 'Lorem', 2), - array($longText, 'Lorem ipsum...', 10, '...'), - array($longText, 'Lorem ipsum dolorem si amet, lorem', 30), - array($longText, 'Lorem', 0), - array($longText, 'Lorem...', 0, '...'), - array($longText, 'Lorem ipsum dolorem si amet, lorem ipsum. Dolorem sic et nunc.', -2), - array($shortText, "Short...", 1, '...'), - array($shortText, "Short...", 2, '...'), - array($shortText, "Short...", 3, '...'), - array($shortText, "Short...", 4, '...'), - array($shortText, "Short...", 5, '...'), - array($shortText, "Short text", 6, '...'), - array($shortText, "Short text", 7, '...'), - array($shortText, "Short text", 8, '...'), - array($shortText, "Short text", 9, '...'), - array($shortText, "Short text", 10, '...') - ); + return [ + [$longText, 'Lorem', 2], + [$longText, 'Lorem ipsum...', 10, '...'], + [$longText, 'Lorem ipsum dolorem si amet, lorem', 30], + [$longText, 'Lorem', 0], + [$longText, 'Lorem...', 0, '...'], + [$longText, 'Lorem ipsum dolorem si amet, lorem ipsum. Dolorem sic et nunc.', -2], + [$shortText, 'Short...', 1, '...'], + [$shortText, 'Short...', 2, '...'], + [$shortText, 'Short...', 3, '...'], + [$shortText, 'Short...', 4, '...'], + [$shortText, 'Short...', 5, '...'], + [$shortText, 'Short text', 6, '...'], + [$shortText, 'Short text', 7, '...'], + [$shortText, 'Short text', 8, '...'], + [$shortText, 'Short text', 9, '...'], + [$shortText, 'Short text', 10, '...'] + ]; } /** @@ -139,20 +141,20 @@ public function truncateHtmlStringProvider() { $text = '
HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create web pages.[1] Web browsers can read HTML files and render them into visible or audible web pages. HTML describes the structure of a website semantically along with cues for presentation, making it a markup language, rather than a programming language.
'; - return array( - array($text, 3, '', "HyperText"), - array($text, 12, '', "HyperText Markup"), - array($text, 30, '', "HyperText Markup Language, commonly"), - array($text, 50, '', "HyperText Markup Language, commonly referred to as"), - array($text, 75, '', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup'), - array($text, 100,'', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create'), - array($text, 3 , '', "HyperText"), - array($text, 12 , '', "HyperText Markup"), - array($text, 50 , '', "HyperText Markup Language, commonly referred to as"), - array($text, 75 , '', "HyperText Markup Language, commonly referred to as HTML, is the standard markup"), - array($text, 100, '', "HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create"), - array($text, 50, '', "HyperText Markup Language, commonly referred to as...", '...'), - array($text, 75, '', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup...', '...') - ); + return [ + [$text, 3, '', 'HyperText'], + [$text, 12, '', 'HyperText Markup'], + [$text, 30, '', 'HyperText Markup Language, commonly'], + [$text, 50, '', 'HyperText Markup Language, commonly referred to as'], + [$text, 75, '', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup'], + [$text, 100,'', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create'], + [$text, 3 , '', 'HyperText'], + [$text, 12 , '', 'HyperText Markup'], + [$text, 50 , '', 'HyperText Markup Language, commonly referred to as'], + [$text, 75 , '', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup'], + [$text, 100, '', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup language used to create'], + [$text, 50, '', 'HyperText Markup Language, commonly referred to as...', '...'], + [$text, 75, '', 'HyperText Markup Language, commonly referred to as HTML, is the standard markup...', '...'] + ]; } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 796fb24..e800b9d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,5 @@