diff --git a/.travis.yml b/.travis.yml index 5309d487..51256dcf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,15 @@ sudo: false dist: trusty php: - - 5.5 - - 5.6 - - 7.0 - 7.1 + - 7.2 + - 7.3 + +before_install: + - composer global require phpunit/phpunit ^7.0 before_script: - composer update --dev script: - - phpunit --configuration phpunit.travis.xml + - /home/travis/.config/composer/vendor/bin/phpunit --configuration phpunit.travis.xml diff --git a/Mbstring.php b/Mbstring.php index a3c87fa3..6e48ede2 100644 --- a/Mbstring.php +++ b/Mbstring.php @@ -1,4 +1,4 @@ -rules[$ruleType] as $regex => $replacement) { $matches = 0; - $matchedWord = preg_replace($regex, $replacement, $word, -1, $matches); + $matchedWord = preg_replace($regex, $replacement, (string) $word, -1, $matches); if ($matches > 0) { return $matchedWord; diff --git a/StringNormalise.php b/StringNormalise.php index 334ccedb..268db4c4 100644 --- a/StringNormalise.php +++ b/StringNormalise.php @@ -1,4 +1,4 @@ -Traversable * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function getIterator() { return new \ArrayIterator($this->chop()); @@ -214,6 +215,7 @@ public function getIterator() * The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { $offset = $offset >= 0 ? $offset : (int) abs($offset) - 1; @@ -228,6 +230,7 @@ public function offsetExists($offset) * * @return string Can return all value types. */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { return $this->getChar($offset); @@ -248,6 +251,7 @@ public function offsetGet($offset) * @return void * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $string) { $this->string = Mbstring::substrReplace($this->string, $string, $offset, 1, $this->encoding); @@ -265,6 +269,7 @@ public function offsetSet($offset, $string) * @return void * @since 5.0.0 */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { if ($this->length() < abs($offset)) { @@ -284,6 +289,7 @@ public function offsetUnset($offset) * The return value is cast to an integer. * @since 5.1.0 */ + #[\ReturnTypeWillChange] public function count() { return $this->length(); @@ -605,11 +611,8 @@ public function indexOfLast($search) */ public function explode($delimiter, $limit = null) { - // Fix HHVM default explode limit issue - // @see https://github.com/facebook/hhvm/issues/7696 - // @see https://3v4l.org/fllad if ($limit === null) { - $limit = defined('HHVM_VERSION') ? 0x7FFFFFFF : PHP_INT_MAX; + return explode($delimiter, $this->string); } return explode($delimiter, $this->string, $limit); @@ -630,4 +633,34 @@ function ($new) use ($callback) { } ); } + + /** + * pipe + * + * @param callable $callback + * + * @return static + * + * @since 3.5.14 + */ + public function pipe(callable $callback): self + { + return $callback($this); + } + + /** + * clearHtml + * + * @param string|null $allowTags + * + * @return StringObject + * + * @since 3.5.13 + */ + public function stripHtmlTags(?string $allowTags = null) + { + return $this->cloneInstance(function (self $new) use ($allowTags) { + $new->string = strip_tags($new->string, $allowTags); + }); + } } diff --git a/Test/InflectorTest.php b/Test/InflectorTest.php index 73e59445..7ed104e0 100644 --- a/Test/InflectorTest.php +++ b/Test/InflectorTest.php @@ -1,4 +1,4 @@ -expectException(\InvalidArgumentException::class); + TestHelper::invoke($this->StringInflector, 'addRule', new \stdClass(), 'singular'); } diff --git a/Test/MbstringTest.php b/Test/MbstringTest.php index 8924b879..d55bd258 100644 --- a/Test/MbstringTest.php +++ b/Test/MbstringTest.php @@ -1,4 +1,4 @@ -getString()); @@ -158,6 +158,7 @@ public function testOffsetGet($offset, $expected) * * @return array */ + #[\ReturnTypeWillChange] public function offsetGetProvider() { return [ @@ -196,6 +197,7 @@ public function testOffsetSet($string, $replace, $offset, $expected) * * @return array */ + #[\ReturnTypeWillChange] public function offsetSetProvider() { return [ @@ -230,6 +232,7 @@ public function testOffsetUnset($string, $offset, $expected) * * @return array */ + #[\ReturnTypeWillChange] public function offsetUnsetProvider() { return [ diff --git a/Test/Utf8StringTest.php b/Test/Utf8StringTest.php index 63fdd6ce..d5573ce7 100644 --- a/Test/Utf8StringTest.php +++ b/Test/Utf8StringTest.php @@ -1,4 +1,4 @@ -=5.5.9" + "php": ">=7.1.3" }, "require-dev": { "windwalker/test": "~3.0", - "windwalker/utilities": "~3.0" + "windwalker/utilities": "dev-master" }, "suggest": { "windwalker/utilities": "Install ~3.0 if you require SimpleTemplate template engine." diff --git a/functions.php b/functions.php index 288d3852..2c4ea37a 100644 --- a/functions.php +++ b/functions.php @@ -1,4 +1,4 @@ -= 192 && $ord0 <= 223) { return ($ord0 - 192) * 64 + ($ord1 - 128); } - if (!isset($chr{2})) { + if (!isset($chr[2])) { trigger_error('Short sequence - at least 3 bytes expected, only 2 seen'); return false; } - $ord2 = ord($chr{2}); + $ord2 = ord($chr[2]); if ($ord0 >= 224 && $ord0 <= 239) { return ($ord0 - 224) * 4096 + ($ord1 - 128) * 64 + ($ord2 - 128); } - if (!isset($chr{3})) { + if (!isset($chr[3])) { trigger_error('Short sequence - at least 4 bytes expected, only 3 seen'); return false; } - $ord3 = ord($chr{3}); + $ord3 = ord($chr[3]); if ($ord0 >= 240 && $ord0 <= 247) { return ($ord0 - 240) * 262144 + ($ord1 - 128) * 4096 @@ -64,12 +64,12 @@ function utf8_ord($chr) + ($ord3 - 128); } - if (!isset($chr{4})) { + if (!isset($chr[4])) { trigger_error('Short sequence - at least 5 bytes expected, only 4 seen'); return false; } - $ord4 = ord($chr{4}); + $ord4 = ord($chr[4]); if ($ord0 >= 248 && $ord0 <= 251) { return ($ord0 - 248) * 16777216 + ($ord1 - 128) * 262144 @@ -78,7 +78,7 @@ function utf8_ord($chr) + ($ord4 - 128); } - if (!isset($chr{5})) { + if (!isset($chr[5])) { trigger_error('Short sequence - at least 6 bytes expected, only 5 seen'); return false; @@ -89,7 +89,7 @@ function utf8_ord($chr) + ($ord2 - 128) * 262144 + ($ord3 - 128) * 4096 + ($ord4 - 128) * 64 - + (ord($chr{5}) - 128); + + (ord($chr[5]) - 128); } if ($ord0 >= 254 && $ord0 <= 255) { diff --git a/phputf8/str_ireplace.php b/phputf8/str_ireplace.php index e449b247..bcdb8d80 100644 --- a/phputf8/str_ireplace.php +++ b/phputf8/str_ireplace.php @@ -1,4 +1,4 @@ -