From b2365b4bfb4d3bfead7a75c85e3ea910abe747be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Andor?= Date: Mon, 3 Jan 2022 22:16:06 +0100 Subject: [PATCH] Issue #209 - PHP 8.1 compatibility --- composer.json | 15 ++++++++++++++- src/Stringy.php | 12 +++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 092989f4..a44a3241 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,25 @@ "homepage": "http://www.danielstjules.com" } ], + "repositories": { + "phpunit/phpunit": { + "type": "github", + "url": "https://github.com/Sweetchuck/phpunit.git", + "branch": "4.x-php8" + }, + "phpunit/php-file-iterator": { + "type": "github", + "url": "https://github.com/Sweetchuck/php-file-iterator.git", + "branch": "1.4-php8" + } + }, "require": { "php": ">=5.4.0", "symfony/polyfill-mbstring": "~1.1" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "dev-4.x-php8#f7f5b1d9a8c733b2ba8e665b2e8a0f04e208ed9d", + "phpunit/php-file-iterator": "dev-1.4-php8#0bf836b26a9789e7cd634c43dc468428c8fa77d6 as 1.4.5" }, "support": { "issues": "https://github.com/danielstjules/Stringy/issues", diff --git a/src/Stringy.php b/src/Stringy.php index ccb6f5aa..0efc685d 100644 --- a/src/Stringy.php +++ b/src/Stringy.php @@ -267,6 +267,7 @@ public function containsAny($needles, $caseSensitive = true) * * @return int The number of characters in the string, given the encoding */ + #[\ReturnTypeWillChange] public function count() { return $this->length(); @@ -450,6 +451,7 @@ public function getEncoding() * * @return \ArrayIterator An iterator for the characters in the string */ + #[\ReturnTypeWillChange] public function getIterator() { return new ArrayIterator($this->chars()); @@ -716,7 +718,7 @@ public function length() */ public function lines() { - $array = $this->split('[\r\n]{1,2}', $this->str); + $array = $this->split('[\r\n]{1,2}'); for ($i = 0; $i < count($array); $i++) { $array[$i] = static::create($array[$i], $this->encoding); } @@ -847,6 +849,7 @@ public function lowerCaseFirst() * @param mixed $offset The index to check * @return boolean Whether or not the index exists */ + #[\ReturnTypeWillChange] public function offsetExists($offset) { $length = $this->length(); @@ -870,6 +873,7 @@ public function offsetExists($offset) * @throws \OutOfBoundsException If the positive or negative offset does * not exist */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { $offset = (int) $offset; @@ -890,6 +894,7 @@ public function offsetGet($offset) * @param mixed $value Value to set * @throws \Exception When called */ + #[\ReturnTypeWillChange] public function offsetSet($offset, $value) { // Stringy is immutable, cannot directly set char @@ -903,6 +908,7 @@ public function offsetSet($offset, $value) * @param mixed $offset The index of the character * @throws \Exception When called */ + #[\ReturnTypeWillChange] public function offsetUnset($offset) { // Don't allow directly modifying the string @@ -1170,7 +1176,7 @@ public function slugify($replacement = '-', $language = 'en') $stringy->str = str_replace('@', $replacement, $stringy); $quotedReplacement = preg_quote($replacement); - $pattern = "/[^a-zA-Z\d\s-_$quotedReplacement]/u"; + $pattern = "/[^a-zA-Z\d\s\-_$quotedReplacement]/u"; $stringy->str = preg_replace($pattern, '', $stringy); return $stringy->toLowerCase()->delimit($replacement) @@ -1277,7 +1283,7 @@ public function split($pattern, $limit = null) // mb_split returns the remaining unsplit string in the last index when // supplying a limit - $limit = ($limit > 0) ? $limit += 1 : -1; + $limit = ($limit > 0) ? $limit + 1 : -1; static $functionExists; if ($functionExists === null) {