Skip to content

Commit

Permalink
Issue danielstjules#209 - PHP 8.1 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Sweetchuck committed Jan 3, 2022
1 parent df24ab6 commit 33e221a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
"homepage": "http://www.danielstjules.com"
}
],
"repositories": {
"phpunit/phpunit": {
"type": "github",
"url": "https://github.com/Sweetchuck/phpunit.git",
"branch": "4.x-php8"
}
},
"require": {
"php": ">=5.4.0",
"symfony/polyfill-mbstring": "~1.1"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
"phpunit/phpunit": "dev-4.x-php8#f7f5b1d9a8c733b2ba8e665b2e8a0f04e208ed9d"
},
"support": {
"issues": "https://github.com/danielstjules/Stringy/issues",
Expand Down
12 changes: 9 additions & 3 deletions src/Stringy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 33e221a

Please sign in to comment.