aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-30 16:13:33 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2017-08-30 16:13:33 +0200
commit417c86c5589d51223b95d19d709be6e623761fa2 (patch)
tree10897312dae24e62d061c763dc2d34f7bdf99664
parentb22ee139c2686174f8f1db6e74008fc693c0c92d (diff)
downloadUstring-417c86c5589d51223b95d19d709be6e623761fa2.zip
Ustring-417c86c5589d51223b95d19d709be6e623761fa2.tar.gz
Ustring-417c86c5589d51223b95d19d709be6e623761fa2.tar.bz2
chore(php) Move to PHP 7.
-rw-r--r--Bin/Fromcode.php19
-rw-r--r--Bin/Tocode.php21
-rw-r--r--Source/Exception.php9
-rw-r--r--Source/Search.php20
-rw-r--r--Source/Ustring.php346
-rw-r--r--Test/Unit/Issue.php9
-rw-r--r--Test/Unit/Search.php9
-rw-r--r--Test/Unit/Ustring.php131
8 files changed, 174 insertions, 390 deletions
diff --git a/Bin/Fromcode.php b/Bin/Fromcode.php
index 401c60f..32105e2 100644
--- a/Bin/Fromcode.php
+++ b/Bin/Fromcode.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,12 +42,7 @@ use Hoa\Console;
use Hoa\Ustring;
/**
- * Class Hoa\Ustring\Bin\Fromcode.
- *
* Get a character from its code. Please, see Hoa\Ustring\Ustring::fromCode.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Fromcode extends Console\Dispatcher\Kit
{
@@ -64,10 +61,8 @@ class Fromcode extends Console\Dispatcher\Kit
/**
* The entry method.
- *
- * @return int
*/
- public function main()
+ public function main(): ?int
{
$base = 16;
@@ -96,15 +91,13 @@ class Fromcode extends Console\Dispatcher\Kit
echo $char;
- return;
+ return 0;
}
/**
* The command usage.
- *
- * @return int
*/
- public function usage()
+ public function usage(): void
{
echo
'Usage : ustring:fromcode <char>', "\n",
@@ -113,8 +106,6 @@ class Fromcode extends Console\Dispatcher\Kit
'b' => 'Specify the base of the code (16 by default).',
'help' => 'This help.'
]), "\n";
-
- return;
}
}
diff --git a/Bin/Tocode.php b/Bin/Tocode.php
index 5cb8b05..88d5c5e 100644
--- a/Bin/Tocode.php
+++ b/Bin/Tocode.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,19 +42,12 @@ use Hoa\Console;
use Hoa\Ustring;
/**
- * Class Hoa\Ustring\Bin\Tocode.
- *
* Transform a character into its code. Please, see Hoa\Ustring\Ustring::toCode.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Tocode extends Console\Dispatcher\Kit
{
/**
* Options description.
- *
- * @var array
*/
protected $options = [
['base', Console\GetOption::REQUIRED_ARGUMENT, 'b'],
@@ -64,10 +59,8 @@ class Tocode extends Console\Dispatcher\Kit
/**
* The entry method.
- *
- * @return int
*/
- public function main()
+ public function main(): ?int
{
$base = 16;
@@ -96,15 +89,13 @@ class Tocode extends Console\Dispatcher\Kit
echo $code, "\n";
- return;
+ return 0;
}
/**
* The command usage.
- *
- * @return int
*/
- public function usage()
+ public function usage(): void
{
echo
'Usage : ustring:tocode <char>', "\n",
@@ -113,8 +104,6 @@ class Tocode extends Console\Dispatcher\Kit
'b' => 'Get the code in a specific base (16 by default).',
'help' => 'This help.'
]), "\n";
-
- return;
}
}
diff --git a/Source/Exception.php b/Source/Exception.php
index 91fd76a..82ac123 100644
--- a/Source/Exception.php
+++ b/Source/Exception.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -39,12 +41,7 @@ namespace Hoa\Ustring;
use Hoa\Exception as HoaException;
/**
- * Class \Hoa\Ustring\Exception.
- *
- * Extending the \Hoa\Exception\Exception class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
+ * Extends the `Hoa\Exception\Exception` class.
*/
class Exception extends HoaException
{
diff --git a/Source/Search.php b/Source/Search.php
index d5c30c0..c0e93f7 100644
--- a/Source/Search.php
+++ b/Source/Search.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -37,25 +39,15 @@
namespace Hoa\Ustring;
/**
- * Class \Hoa\Ustring\Search.
- *
* Some algorithms about search in strings.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Search
{
/**
* Search by approximated patterns, with k differences based upon the
* principle diagonal monotony.
- *
- * @param string $y Haystack.
- * @param string $x Needle.
- * @param int $k Number of differences.
- * @return array
*/
- public static function approximated($y, $x, $k)
+ public static function approximated(string $y, string $x, int $k): array
{
$x = (string) $x;
$y = (string) $y;
@@ -96,12 +88,8 @@ class Search
/**
* Length of the longest common prefixes.
- *
- * @param string $x Word.
- * @param string $y Word.
- * @return int
*/
- public static function lcp($x, $y)
+ public static function lcp(string $x, string $y): int
{
$max = min(strlen($x), strlen($y));
$i = 0;
diff --git a/Source/Ustring.php b/Source/Ustring.php
index 730542b..dcf0f00 100644
--- a/Source/Ustring.php
+++ b/Source/Ustring.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -36,161 +38,118 @@
namespace Hoa\Ustring;
+use ArrayIterator;
+use Collator;
use Hoa\Consistency;
+use Transliterator;
/**
- * Class \Hoa\Ustring.
- *
* This class represents a UTF-8 string.
* Please, see:
- * • http://www.ietf.org/rfc/rfc3454.txt;
- * • http://unicode.org/reports/tr9/;
- * • http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
+ * * http://www.ietf.org/rfc/rfc3454.txt,
+ * * http://unicode.org/reports/tr9/,
+ * * http://www.unicode.org/Public/6.0.0/ucd/UnicodeData.txt.
*/
class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
{
/**
* Left-To-Right.
- *
- * @const int
*/
- const LTR = 0;
+ public const LTR = 0;
/**
* Right-To-Left.
- *
- * @const int
*/
- const RTL = 1;
+ public const RTL = 1;
/**
* ZERO WIDTH NON-BREAKING SPACE (ZWNPBSP, aka byte-order mark, BOM).
- *
- * @const int
*/
- const BOM = 0xfeff;
+ public const BOM = 0xfeff;
/**
* LEFT-TO-RIGHT MARK.
- *
- * @const int
*/
- const LRM = 0x200e;
+ public const LRM = 0x200e;
/**
* RIGHT-TO-LEFT MARK.
- *
- * @const int
*/
- const RLM = 0x200f;
+ public const RLM = 0x200f;
/**
* LEFT-TO-RIGHT EMBEDDING.
- *
- * @const int
*/
- const LRE = 0x202a;
+ public const LRE = 0x202a;
/**
* RIGHT-TO-LEFT EMBEDDING.
- *
- * @const int
*/
- const RLE = 0x202b;
+ public const RLE = 0x202b;
/**
* POP DIRECTIONAL FORMATTING.
- *
- * @const int
*/
- const PDF = 0x202c;
+ public const PDF = 0x202c;
/**
* LEFT-TO-RIGHT OVERRIDE.
- *
- * @const int
*/
- const LRO = 0x202d;
+ public const LRO = 0x202d;
/**
* RIGHT-TO-LEFT OVERRIDE.
- *
- * @const int
*/
- const RLO = 0x202e;
+ public const RLO = 0x202e;
/**
* Represent the beginning of the string.
- *
- * @const int
*/
- const BEGINNING = 1;
+ public const BEGINNING = 1;
/**
* Represent the end of the string.
- *
- * @const int
*/
- const END = 2;
+ public const END = 2;
/**
* Split: non-empty pieces is returned.
- *
- * @const int
*/
- const WITHOUT_EMPTY = PREG_SPLIT_NO_EMPTY;
+ public const WITHOUT_EMPTY = PREG_SPLIT_NO_EMPTY;
/**
* Split: parenthesized expression in the delimiter pattern will be captured
* and returned.
- *
- * @const int
*/
- const WITH_DELIMITERS = PREG_SPLIT_DELIM_CAPTURE;
+ public const WITH_DELIMITERS = PREG_SPLIT_DELIM_CAPTURE;
/**
* Split: offsets of captures will be returned.
- *
- * @const int
*/
- const WITH_OFFSET = 260; // PREG_OFFSET_CAPTURE
- // | PREG_SPLIT_OFFSET_CAPTURE
+ public const WITH_OFFSET = PREG_OFFSET_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
/**
* Group results by patterns.
- *
- * @const int
*/
- const GROUP_BY_PATTERN = PREG_PATTERN_ORDER;
+ public const GROUP_BY_PATTERN = PREG_PATTERN_ORDER;
/**
* Group results by tuple (set of patterns).
- *
- * @const int
*/
- const GROUP_BY_TUPLE = PREG_SET_ORDER;
+ public const GROUP_BY_TUPLE = PREG_SET_ORDER;
/**
* Current string.
- *
- * @var string
*/
protected $_string = null;
/**
* Direction. Please see self::LTR and self::RTL constants.
- *
- * @var int
*/
protected $_direction = null;
/**
* Collator.
- *
- * @var \Collator
*/
protected static $_collator = null;
@@ -198,10 +157,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Construct a UTF-8 string.
- *
- * @param string $string String.
*/
- public function __construct($string = null)
+ public function __construct(string $string = null)
{
if (null !== $string) {
$this->append($string);
@@ -212,31 +169,24 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Check if ext/mbstring is available.
- *
- * @return bool
*/
- public static function checkMbString()
+ public static function checkMbString(): bool
{
return function_exists('mb_substr');
}
/**
* Check if ext/iconv is available.
- *
- * @return bool
*/
- public static function checkIconv()
+ public static function checkIconv(): bool
{
return function_exists('iconv');
}
/**
* Append a substring to the current string, i.e. add to the end.
- *
- * @param string $substring Substring to append.
- * @return \Hoa\Ustring
*/
- public function append($substring)
+ public function append(string $substring): self
{
$this->_string .= $substring;
@@ -245,11 +195,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Prepend a substring to the current string, i.e. add to the start.
- *
- * @param string $substring Substring to append.
- * @return \Hoa\Ustring
*/
- public function prepend($substring)
+ public function prepend(string $substring): self
{
$this->_string = $substring . $this->_string;
@@ -258,14 +205,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Pad the current string to a certain length with another piece, aka piece.
- *
- * @param int $length Length.
- * @param string $piece Piece.
- * @param int $side Whether we append at the end or the beginning
- * of the current string.
- * @return \Hoa\Ustring
*/
- public function pad($length, $piece, $side = self::END)
+ public function pad(int $length, string $piece, int $side = self::END): self
{
$difference = $length - $this->count();
@@ -291,11 +232,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
* Make a comparison with a string.
* Return < 0 if current string is less than $string, > 0 if greater and 0
* if equal.
- *
- * @param mixed $string String.
- * @return int
*/
- public function compare($string)
+ public function compare($string): int
{
if (null === $collator = static::getCollator()) {
return strcmp($this->_string, (string) $string);
@@ -306,17 +244,15 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Get collator.
- *
- * @return \Collator
*/
- public static function getCollator()
+ public static function getCollator(): ?Collator
{
if (false === class_exists('Collator')) {
return null;
}
if (null === static::$_collator) {
- static::$_collator = new \Collator(setlocale(LC_COLLATE, null));
+ static::$_collator = new Collator(setlocale(LC_COLLATE, null));
}
return static::$_collator;
@@ -324,11 +260,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Ensure that the pattern is safe for Unicode: add the “u” option.
- *
- * @param string $pattern Pattern.
- * @return string
*/
- public static function safePattern($pattern)
+ public static function safePattern(string $pattern): string
{
$delimiter = mb_substr($pattern, 0, 1);
$options = mb_substr(
@@ -345,24 +278,14 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Perform a regular expression (PCRE) match.
- *
- * @param string $pattern Pattern.
- * @param array $matches Matches.
- * @param int $flags Please, see constants self::WITH_OFFSET,
- * self::GROUP_BY_PATTERN and
- * self::GROUP_BY_TUPLE.
- * @param int $offset Alternate place from which to start the
- * search.
- * @param bool $global Whether the match is global or not.
- * @return int
*/
public function match(
- $pattern,
- &$matches = null,
- $flags = 0,
- $offset = 0,
- $global = false
- ) {
+ string $pattern,
+ array &$matches = null,
+ int $flags = 0,
+ int $offset = 0,
+ bool $global = false
+ ): int {
$pattern = static::safePattern($pattern);
if (0 === $flags) {
@@ -391,14 +314,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Perform a regular expression (PCRE) search and replace.
- *
- * @param mixed $pattern Pattern(s).
- * @param mixed $replacement Replacement(s) (please, see
- * preg_replace() documentation).
- * @param int $limit Maximum of replacements. -1 for unbound.
- * @return \Hoa\Ustring
*/
- public function replace($pattern, $replacement, $limit = -1)
+ public function replace($pattern, $replacement, int $limit = -1): self
{
$pattern = static::safePattern($pattern);
@@ -423,18 +340,12 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Split the current string according to a given pattern (PCRE).
- *
- * @param string $pattern Pattern (as a regular expression).
- * @param int $limit Maximum of split. -1 for unbound.
- * @param int $flags Please, see constants self::WITHOUT_EMPTY,
- * self::WITH_DELIMITERS, self::WITH_OFFSET.
- * @return array
*/
public function split(
- $pattern,
- $limit = -1,
- $flags = self::WITHOUT_EMPTY
- ) {
+ string $pattern,
+ int $limit = -1,
+ int $flags = self::WITHOUT_EMPTY
+ ): array {
return preg_split(
static::safePattern($pattern),
$this->_string,
@@ -445,20 +356,16 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Iterator over chars.
- *
- * @return \ArrayIterator
*/
- public function getIterator()
+ public function getIterator(): ArrayIterator
{
- return new \ArrayIterator(preg_split('#(?<!^)(?!$)#u', $this->_string));
+ return new ArrayIterator(preg_split('#(?<!^)(?!$)#u', $this->_string));
}
/**
* Perform a lowercase folding on the current string.
- *
- * @return \Hoa\Ustring
*/
- public function toLowerCase()
+ public function toLowerCase(): self
{
$this->_string = mb_strtolower($this->_string);
@@ -470,7 +377,7 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
*
* @return \Hoa\Ustring
*/
- public function toUpperCase()
+ public function toUpperCase(): \Hoa\Ustring
{
$this->_string = mb_strtoupper($this->_string);
@@ -481,12 +388,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
* Transform a UTF-8 string into an ASCII one.
* First, try with a transliterator. If not available, will fallback to a
* normalizer. If not available, will try something homemade.
- *
- * @param bool $try Try something if \Normalizer is not present.
- * @return \Hoa\Ustring
- * @throws \Hoa\Ustring\Exception
*/
- public function toAscii($try = false)
+ public function toAscii(bool $try = false): self
{
if (0 === preg_match('#[\x80-\xff]#', $this->_string)) {
return $this;
@@ -536,14 +439,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Transliterate the string into another.
* See self::getTransliterator for more information.
- *
- * @param string $identifier Identifier.
- * @param int $start Start.
- * @param int $end End.
- * @return \Hoa\Ustring
- * @throws \Hoa\Ustring\Exception
*/
- public function transliterate($identifier, $start = 0, $end = null)
+ public function transliterate(string $identifier, int $start = 0, int $end = null): self
{
if (null === $transliterator = static::getTransliterator($identifier)) {
throw new Exception(
@@ -561,28 +458,20 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Get transliterator.
* See http://userguide.icu-project.org/transforms/general for $identifier.
- *
- * @param string $identifier Identifier.
- * @return \Transliterator
*/
- public static function getTransliterator($identifier)
+ public static function getTransliterator(string $identifier): ?Transliterator
{
if (false === class_exists('Transliterator')) {
return null;
}
- return \Transliterator::create($identifier);
+ return Transliterator::create($identifier);
}
/**
* Strip characters (default \s) of the current string.
- *
- * @param string $regex Characters to remove.
- * @param int $side Whether we trim the beginning, the end or both
- * sides, of the current string.
- * @return \Hoa\Ustring
*/
- public function trim($regex = '\s', $side = 3 /* static::BEGINNING | static::END */)
+ public function trim(string $regex = '\s', int $side = self::BEGINNING | self::END): self
{
$regex = '(?:' . $regex . ')+';
$handle = null;
@@ -607,11 +496,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Compute offset (negative, unbound etc.).
- *
- * @param int $offset Offset.
- * @return int
*/
- protected function computeOffset($offset)
+ protected function computeOffset(int $offset): int
{
$length = mb_strlen($this->_string);
@@ -630,23 +516,16 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Get a specific chars of the current string.
- *
- * @param int $offset Offset (can be negative and unbound).
- * @return string
*/
- public function offsetGet($offset)
+ public function offsetGet($offset): string
{
return mb_substr($this->_string, $this->computeOffset($offset), 1);
}
/**
* Set a specific character of the current string.
- *
- * @param int $offset Offset (can be negative and unbound).
- * @param string $value Value.
- * @return \Hoa\Ustring
*/
- public function offsetSet($offset, $value)
+ public function offsetSet($offset, $value): self
{
$head = null;
$offset = $this->computeOffset($offset);
@@ -664,33 +543,24 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Delete a specific character of the current string.
- *
- * @param int $offset Offset (can be negative and unbound).
- * @return string
*/
- public function offsetUnset($offset)
+ public function offsetUnset($offset): void
{
- return $this->offsetSet($offset, null);
+ $this->offsetSet($offset, null);
}
/**
* Check if a specific offset exists.
- *
- * @return bool
*/
- public function offsetExists($offset)
+ public function offsetExists($offset): bool
{
return true;
}
/**
* Reduce the strings.
- *
- * @param int $start Position of first character.
- * @param int $length Maximum number of characters.
- * @return \Hoa\Ustring
*/
- public function reduce($start, $length = null)
+ public function reduce(int $start, int $length = null): self
{
$this->_string = mb_substr($this->_string, $start, $length);
@@ -699,21 +569,16 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Count number of characters of the current string.
- *
- * @return int
*/
- public function count()
+ public function count(): int
{
return mb_strlen($this->_string);
}
/**
* Get byte (not character) at a specific offset.
- *
- * @param int $offset Offset (can be negative and unbound).
- * @return string
*/
- public function getByteAt($offset)
+ public function getByteAt(int $offset): string
{
$length = strlen($this->_string);
@@ -732,10 +597,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Count number of bytes (not characters) of the current string.
- *
- * @return int
*/
- public function getBytesLength()
+ public function getBytesLength(): int
{
return strlen($this->_string);
}
@@ -744,10 +607,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
* Get the width of the current string.
* Useful when printing the string in monotype (some character need more
* than one column to be printed).
- *
- * @return int
*/
- public function getWidth()
+ public function getWidth(): int
{
return mb_strwidth($this->_string);
}
@@ -756,10 +617,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
* Get direction of the current string.
* Please, see the self::LTR and self::RTL constants.
* It does not yet support embedding directions.
- *
- * @return int
*/
- public function getDirection()
+ public function getDirection(): int
{
if (null === $this->_direction) {
if (null === $this->_string) {
@@ -777,11 +636,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Get character of a specific character.
* Please, see the self::LTR and self::RTL constants.
- *
- * @param string $char Character.
- * @return int
*/
- public static function getCharDirection($char)
+ public static function getCharDirection(string $char): int
{
$c = static::toCode($char);
@@ -878,11 +734,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
* wide-character code), or return the number of column positions to be
* occupied by the wide-character code wc, or return -1 (if wc does not
* correspond to a printable wide-character code).
- *
- * @param string $char Character.
- * @return int
*/
- public static function getCharWidth($char)
+ public static function getCharWidth(string $char): int
{
$char = (string) $char;
$c = static::toCode($char);
@@ -898,7 +751,7 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
// Non-spacing characters.
if (0xad !== $c &&
- 0 !== preg_match('#^[\p{Mn}\p{Me}\p{Cf}\x{1160}-\x{11ff}\x{200b}]#u', $char)) {
+ 0 !== preg_match('#^[\p{Mn}\p{Me}\p{Cf}\x{1160}-\x{11ff}\x{200b}]#u', $char)) {
return 0;
}
@@ -908,35 +761,29 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
(0x115f >= $c || // Hangul Jamo init. consonants
0x2329 === $c || 0x232a === $c ||
(0x2e80 <= $c && 0xa4cf >= $c &&
- 0x303f !== $c) || // CJK…Yi
- (0xac00 <= $c && 0xd7a3 >= $c) || // Hangul Syllables
- (0xf900 <= $c && 0xfaff >= $c) || // CJK Compatibility Ideographs
- (0xfe10 <= $c && 0xfe19 >= $c) || // Vertical forms
- (0xfe30 <= $c && 0xfe6f >= $c) || // CJK Compatibility Forms
- (0xff00 <= $c && 0xff60 >= $c) || // Fullwidth Forms
- (0xffe0 <= $c && 0xffe6 >= $c) ||
+ 0x303f !== $c) || // CJK…Yi
+ (0xac00 <= $c && 0xd7a3 >= $c) || // Hangul Syllables
+ (0xf900 <= $c && 0xfaff >= $c) || // CJK Compatibility Ideographs
+ (0xfe10 <= $c && 0xfe19 >= $c) || // Vertical forms
+ (0xfe30 <= $c && 0xfe6f >= $c) || // CJK Compatibility Forms
+ (0xff00 <= $c && 0xff60 >= $c) || // Fullwidth Forms
+ (0xffe0 <= $c && 0xffe6 >= $c) ||
(0x20000 <= $c && 0x2fffd >= $c) ||
(0x30000 <= $c && 0x3fffd >= $c)));
}
/**
* Check whether the character is printable or not.
- *
- * @param string $char Character.
- * @return bool
*/
- public static function isCharPrintable($char)
+ public static function isCharPrintable(string $char): bool
{
return 1 <= static::getCharWidth($char);
}
/**
* Get a UTF-8 character from its decimal code representation.
- *
- * @param int $code Code.
- * @return string
*/
- public static function fromCode($code)
+ public static function fromCode(int $code): string
{
return mb_convert_encoding(
'&#x' . dechex($code) . ';',
@@ -947,11 +794,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Get a decimal code representation of a specific character.
- *
- * @param string $char Character.
- * @return int
*/
- public static function toCode($char)
+ public static function toCode(string $char): int
{
$char = (string) $char;
$code = ord($char[0]);
@@ -981,14 +825,11 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Get a binary representation of a specific character.
- *
- * @param string $char Character.
- * @return string
*/
- public static function toBinaryCode($char)
+ public static function toBinaryCode(string $char): string
{
$char = (string) $char;
- $out = null;
+ $out = '';
for ($i = 0, $max = strlen($char); $i < $max; ++$i) {
$out .= vsprintf('%08b', ord($char[$i]));
@@ -999,14 +840,8 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Transcode.
- *
- * @param string $string String.
- * @param string $from Original encoding.
- * @param string $to Final encoding.
- * @return string
- * @throws \Hoa\Ustring\Exception
*/
- public static function transcode($string, $from, $to = 'UTF-8')
+ public static function transcode(string $string, string $from, string $to = 'UTF-8'): string
{
if (false === static::checkIconv()) {
throw new Exception(
@@ -1021,31 +856,24 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Check if a string is encoded in UTF-8.
- *
- * @param string $string String.
- * @return bool
*/
- public static function isUtf8($string)
+ public static function isUtf8(string $string): bool
{
return (bool) preg_match('##u', $string);
}
/**
* Copy current object string
- *
- * @return \Hoa\Ustring
*/
- public function copy()
+ public function copy(): self
{
return clone $this;
}
/**
* Transform the object as a string.
- *
- * @return string
*/
- public function __toString()
+ public function __toString(): string
{
return $this->_string;
}
@@ -1054,7 +882,7 @@ class Ustring implements \ArrayAccess, \Countable, \IteratorAggregate
/**
* Flex entity.
*/
-Consistency::flexEntity('Hoa\Ustring\Ustring');
+Consistency::flexEntity(Ustring::class);
if (false === Ustring::checkMbString()) {
throw new Exception(
diff --git a/Test/Unit/Issue.php b/Test/Unit/Issue.php
index fdd6939..855ef3a 100644
--- a/Test/Unit/Issue.php
+++ b/Test/Unit/Issue.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,16 +42,11 @@ use Hoa\Test;
use Hoa\Ustring as LUT;
/**
- * Class \Hoa\Ustring\Test\Unit\Issue.
- *
* Test suite of detected issues.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Issue extends Test\Unit\Suite implements Test\Decorrelated
{
- public function case_github_26()
+ public function case_github_26(): void
{
$this
->when($result = LUT::toCode(chr(160)))
diff --git a/Test/Unit/Search.php b/Test/Unit/Search.php
index 362161a..9f92b00 100644
--- a/Test/Unit/Search.php
+++ b/Test/Unit/Search.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,16 +42,11 @@ use Hoa\Test;
use Hoa\Ustring as LUT;
/**
- * Class \Hoa\Ustring\Test\Unit\Search.
- *
* Test suite of the search algorithms.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Search extends Test\Unit\Suite
{
- public function case_approximated()
+ public function case_approximated(): void
{
$this
->given(
diff --git a/Test/Unit/Ustring.php b/Test/Unit/Ustring.php
index 92a3154..a49ce6e 100644
--- a/Test/Unit/Ustring.php
+++ b/Test/Unit/Ustring.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
/**
* Hoa
*
@@ -40,16 +42,11 @@ use Hoa\Test;
use Hoa\Ustring as LUT;
/**
- * Class \Hoa\Ustring\Test\Unit\Ustring.
- *
* Test suite of the string class.
- *
- * @copyright Copyright © 2007-2017 Hoa community
- * @license New BSD License
*/
class Ustring extends Test\Unit\Suite
{
- public function case_check_mbstring()
+ public function case_check_mbstring(): void
{
$this
->given($this->function->function_exists = true)
@@ -58,7 +55,7 @@ class Ustring extends Test\Unit\Suite
->isTrue();
}
- public function case_append_ltr()
+ public function case_append_ltr(): void
{
$this
->given($string = new LUT('je'))
@@ -70,7 +67,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('je t\'aime');
}
- public function case_append_rtl()
+ public function case_append_rtl(): void
{
$this
->given($string = new LUT('أ'))
@@ -82,7 +79,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('أحبك');
}
- public function case_prepend_ltr()
+ public function case_prepend_ltr(): void
{
$this
->given($string = new LUT(' t\'aime'))
@@ -94,7 +91,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('je t\'aime');
}
- public function case_prepend_rtl()
+ public function case_prepend_rtl(): void
{
$this
->given($string = new LUT('ك'))
@@ -106,7 +103,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('أحبك');
}
- public function case_pad_beginning_ltr()
+ public function case_pad_beginning_ltr(): void
{
$this
->given($string = new LUT('je t\'aime'))
@@ -118,7 +115,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('👍 💩 😄 ❤️ 👍 je t\'aime');
}
- public function case_pad_beginning_rtl()
+ public function case_pad_beginning_rtl(): void
{
$this
->given($string = new LUT('أحبك'))
@@ -130,7 +127,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('👍 💩 😄 ❤️ 👍 💩 😄 ❤أحبك');
}
- public function case_pad_end_ltr()
+ public function case_pad_end_ltr(): void
{
$this
->given($string = new LUT('je t\'aime'))
@@ -142,7 +139,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('je t\'aime👍 💩 😄 ❤️ 👍 ');
}
- public function case_pad_end_rtl()
+ public function case_pad_end_rtl(): void
{
$this
->given($string = new LUT('أحبك'))
@@ -154,7 +151,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('أحبك👍 💩 😄 ❤️ 👍 💩 😄 ❤');
}
- public function case_compare_no_collator()
+ public function case_compare_no_collator(): void
{
$this
->given(
@@ -166,7 +163,7 @@ class Ustring extends Test\Unit\Suite
->case_compare();
}
- public function case_compare()
+ public function case_compare(): void
{
$this
->given($string = new LUT('b'))
@@ -186,7 +183,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo(-1);
}
- public function case_collator()
+ public function case_collator(): void
{
$this
->given(
@@ -199,7 +196,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('fr');
}
- public function case_safe_unsafe_pattern()
+ public function case_safe_unsafe_pattern(): void
{
$this
->given($pattern = '/foo/i')
@@ -209,7 +206,7 @@ class Ustring extends Test\Unit\Suite
->isEqualto('/foo/iu');
}
- public function case_safe_safe_pattern()
+ public function case_safe_safe_pattern(): void
{
$this
->given($pattern = '/foo/ui')
@@ -219,7 +216,7 @@ class Ustring extends Test\Unit\Suite
->isEqualto('/foo/ui');
}
- public function case_match_default()
+ public function case_match_default(): void
{
$this
->given(
@@ -236,7 +233,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_match_offset()
+ public function case_match_offset(): void
{
$this
->given(
@@ -265,7 +262,7 @@ class Ustring extends Test\Unit\Suite
->isEmpty();
}
- public function case_match_with_offset()
+ public function case_match_with_offset(): void
{
$this
->given(
@@ -285,7 +282,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_match_all_default()
+ public function case_match_all_default(): void
{
$this
->given(
@@ -305,7 +302,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_match_all_with_offset()
+ public function case_match_all_with_offset(): void
{
$this
->given(
@@ -331,7 +328,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_match_all_grouped_by_pattern()
+ public function case_match_all_grouped_by_pattern(): void
{
$this
->given(
@@ -355,7 +352,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_match_all_grouped_by_tuple()
+ public function case_match_all_grouped_by_tuple(): void
{
$this
->given(
@@ -379,7 +376,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_replace()
+ public function case_replace(): void
{
$this
->given($string = new LUT('❤️ 💩 💩'))
@@ -391,7 +388,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('❤️ 😄 😄');
}
- public function case_replace_limited()
+ public function case_replace_limited(): void
{
$this
->given($string = new LUT('❤️ 💩 💩'))
@@ -403,7 +400,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('❤️ 😄 💩');
}
- public function case_split_default()
+ public function case_split_default(): void
{
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
@@ -417,7 +414,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_split_default_limited()
+ public function case_split_default_limited(): void
{
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
@@ -429,7 +426,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_split_with_delimiters()
+ public function case_split_with_delimiters(): void
{
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
@@ -443,7 +440,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_split_with_offset()
+ public function case_split_with_offset(): void
{
$this
->given($string = new LUT('❤️💩❤️💩❤️'))
@@ -466,7 +463,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_iterator_ltr()
+ public function case_iterator_ltr(): void
{
$this
->given($string = new LUT('je t\'aime'))
@@ -486,7 +483,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_iterator_rtl()
+ public function case_iterator_rtl(): void
{
$this
->given($string = new LUT('أحبك'))
@@ -501,7 +498,7 @@ class Ustring extends Test\Unit\Suite
]);
}
- public function case_to_lower()
+ public function case_to_lower(): void
{
$this
->given($string = new LUT('Σ \'ΑΓΑΠΏ'))
@@ -521,7 +518,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('je t\'aime');
}
- public function case_to_upper()
+ public function case_to_upper(): void
{
$this
->given($string = new LUT('σ \'αγαπώ'))
@@ -541,7 +538,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('JE T\'AIME');
}
- public function case_trim_default()
+ public function case_trim_default(): void
{
$this
->given($string = new LUT('💩💩❤️💩💩'))
@@ -553,7 +550,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('❤️');
}
- public function case_trim_beginning()
+ public function case_trim_beginning(): void
{
$this
->given($string = new LUT('💩💩❤️💩💩'))
@@ -565,7 +562,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('❤️💩💩');
}
- public function case_trim_end()
+ public function case_trim_end(): void
{
$this
->given($string = new LUT('💩💩❤️💩💩'))
@@ -577,7 +574,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('💩💩❤️');
}
- public function case_offset_get_ltr()
+ public function case_offset_get_ltr(): void
{
$this
->given($string = new LUT('je t\'aime'))
@@ -592,7 +589,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('e');
}
- public function case_offset_get_rtl()
+ public function case_offset_get_rtl(): void
{
$this
->given($string = new LUT('أحبك'))
@@ -607,7 +604,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('ك');
}
- public function case_offset_set()
+ public function case_offset_set(): void
{
$this
->given($string = new LUT('أحبﻙ'))
@@ -617,11 +614,11 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('أحبك');
}
- public function case_offset_unset()
+ public function case_offset_unset(): void
{
$this
->given($string = new LUT('أحبك😄'))
- ->when(function () use ($string) {
+ ->when(function () use ($string): void {
unset($string[-1]);
})
->then
@@ -629,7 +626,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('أحبك');
}
- public function case_reduce()
+ public function case_reduce(): void
{
$this
->given($string = new LUT('أحبك'))
@@ -641,7 +638,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('أ');
}
- public function case_count()
+ public function case_count(): void
{
$this
->given($string = new LUT('je t\'aime'))
@@ -663,7 +660,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo(1);
}
- public function case_byte_at()
+ public function case_byte_at(): void
{
$this
->given($string = new LUT('💩'))
@@ -693,7 +690,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo(0xa9);
}
- public function case_bytes_length()
+ public function case_bytes_length(): void
{
$this
->given($string = new LUT('💩'))
@@ -703,7 +700,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo(4);
}
- public function case_get_width()
+ public function case_get_width(): void
{
$this
->given($string = new LUT('💩'))
@@ -719,7 +716,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo(2);
}
- public function case_get_char_direction()
+ public function case_get_char_direction(): void
{
$this
->when($result = LUT::getCharDirection('A'))
@@ -733,7 +730,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo(LUT::RTL);
}
- public function case_get_char_width()
+ public function case_get_char_width(): void
{
$this
->given(
@@ -771,7 +768,7 @@ class Ustring extends Test\Unit\Suite
[0xf900, 2]
]
)
- ->when(function () use ($data) {
+ ->when(function () use ($data): void {
foreach ($data as $datum) {
list($code, $width) = $datum;
@@ -784,7 +781,7 @@ class Ustring extends Test\Unit\Suite
});
}
- public function case_is_char_printable()
+ public function case_is_char_printable(): void
{
$this
->when($result = LUT::isCharPrintable(LUT::fromCode(0x7f)))
@@ -803,7 +800,7 @@ class Ustring extends Test\Unit\Suite
->isTrue();
}
- public function case_from_code()
+ public function case_from_code(): void
{
$this
// U+0000 to U+007F
@@ -831,7 +828,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('💩');
}
- public function case_to_code()
+ public function case_to_code(): void
{
$this
// U+0000 to U+007F
@@ -859,7 +856,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo(0x1f4a9);
}
- public function case_to_binary_code()
+ public function case_to_binary_code(): void
{
$this
// U+0000 to U+007F
@@ -887,7 +884,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('11110000100111111001001010101001');
}
- public function case_transcode_no_iconv()
+ public function case_transcode_no_iconv(): void
{
$this
->given(
@@ -895,13 +892,13 @@ class Ustring extends Test\Unit\Suite
return 'iconv' !== $name;
}
)
- ->exception(function () {
+ ->exception(function (): void {
LUT::transcode('foo', 'UTF-8');
})
->isInstanceOf(LUT\Exception::class);
}
- public function case_transcode_and_isUtf8()
+ public function case_transcode_and_isUtf8(): void
{
$this
->given($uΣ = 'Σ')
@@ -921,7 +918,7 @@ class Ustring extends Test\Unit\Suite
->isTrue();
}
- public function case_to_ascii_no_transliterator_no_normalizer()
+ public function case_to_ascii_no_transliterator_no_normalizer(): void
{
$this
->given(
@@ -930,13 +927,13 @@ class Ustring extends Test\Unit\Suite
},
$string = new LUT('Un été brûlant sur la côte')
)
- ->exception(function () use ($string) {
+ ->exception(function () use ($string): void {
$string->toAscii();
})
->isInstanceOf(LUT\Exception::class);
}
- public function case_to_ascii_no_transliterator_no_normalizer_try()
+ public function case_to_ascii_no_transliterator_no_normalizer_try(): void
{
$this
->given(
@@ -953,7 +950,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('Un ete brulant sur la cote');
}
- public function case_to_ascii_no_transliterator()
+ public function case_to_ascii_no_transliterator(): void
{
$this
->given(
@@ -970,7 +967,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo('Un ete brulant sur la cote');
}
- public function case_to_ascii()
+ public function case_to_ascii(): void
{
$this
->given(
@@ -1009,7 +1006,7 @@ class Ustring extends Test\Unit\Suite
=> '(for all) i (element of) N'
]
)
- ->when(function () use ($strings) {
+ ->when(function () use ($strings): void {
foreach ($strings as $original => $asciied) {
$this
->given($string = new LUT($original))
@@ -1023,7 +1020,7 @@ class Ustring extends Test\Unit\Suite
});
}
- public function case_copy()
+ public function case_copy(): void
{
$this
->given($string = new LUT('foo'))
@@ -1033,7 +1030,7 @@ class Ustring extends Test\Unit\Suite
->isEqualTo($string);
}
- public function case_toString()
+ public function case_toString(): void
{
$this
->given($datum = $this->sample($this->realdom->regex('/\w{7,42}/')))