From 921b3cc9984d6b1c0ba4664f1ac3926b59e80424 Mon Sep 17 00:00:00 2001
From: Sergey Romanenko
Date: Sun, 3 Jul 2022 18:48:06 +0300
Subject: [PATCH] Strings 5.0.0
---
.github/workflows/ci.yml | 43 ++++++++++------------------------------
README.md | 4 +---
composer.json | 19 ++++++++++--------
src/Strings.php | 14 +++++++------
src/helpers.php | 4 +++-
tests/StringsTest.php | 1 +
6 files changed, 35 insertions(+), 50 deletions(-)
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 8194a0f..825992e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -1,22 +1,13 @@
name: CI
on: ['push', 'pull_request']
jobs:
- phpstan:
- name: PHP Static Analysis
- runs-on: ubuntu-latest
- steps:
- - uses: actions/checkout@v2
- - name: PHPStan
- uses: docker://oskarstark/phpstan-ga
- with:
- args: analyse src/ -c phpstan.neon
- tests:
- name: Unit Tests for PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
+ ci:
+ name: PHP ${{ matrix.php }} - ${{ matrix.os }} - ${{ matrix.dependency-version }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
- os: [ubuntu-latest, macos-latest, windows-latest]
- php: ['7.4', '8.0', '8.1']
+ os: [ubuntu-latest, macos-latest]
+ php: ['8.1']
dependency-version: [prefer-stable]
steps:
@@ -27,7 +18,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- extensions: fileinfo, spl, json, dom, mbstring, pcntl
+ extensions: json, mbstring, pcntl
ini-values: disable_functions, error_reporting=E_ALL
tools: composer:v2
coverage: xdebug
@@ -37,28 +28,17 @@ jobs:
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- - name: Install PHP 7 dependencies
+ - name: Install PHP 8.1 dependencies
run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress
- if: "matrix.php < 8"
-
- - name: Install PHP 8 dependencies
- if: "matrix.php >= 8"
- run: composer update --${{ matrix.dependency-version }} --no-interaction --no-progress
-
- - name: Run Tests for PHP 7.4
- if: "matrix.php == 7.4"
- run: ./vendor/bin/pest --coverage
-
- - name: Run Tests for PHP 8.0
- if: "matrix.php == 8.0"
- run: ./vendor/bin/pest --coverage
-
+
+ - name: PHP Static Analysis for PHP 8.1
+ run: ./vendor/bin/phpstan
+
- name: Run Tests for PHP 8.1
- if: "matrix.php == 8.1"
run: ./vendor/bin/pest --coverage
support:
- needs: [phpstan, tests]
+ needs: [ci]
name: Discord Notification
runs-on: ubuntu-latest
steps:
@@ -68,4 +48,3 @@ jobs:
with:
webhook: ${{ secrets.WEBHOOK_TOKEN }}
message: "**❤️ SUPPORT ONGOING DEVELOPMENT**\n➡️ https://github.com/Awilum#support-me"
-
diff --git a/README.md b/README.md
index 5dad6f4..967c1d6 100644
--- a/README.md
+++ b/README.md
@@ -4,9 +4,7 @@ Strings Package provide a fluent, object-oriented interface for working with mul
-
-
-
+
diff --git a/composer.json b/composer.json
index cc005a5..868ade7 100644
--- a/composer.json
+++ b/composer.json
@@ -17,7 +17,7 @@
}
],
"require": {
- "php": "^7.4 || ^8.0",
+ "php": "^8.1",
"ext-json": "*",
"ext-mbstring": "*",
"glowy/macroable": "^3.0"
@@ -30,18 +30,21 @@
"src/helpers.php"
]
},
- "require-dev": {
- "doctrine/coding-standard": "9.0.0",
- "pestphp/pest": "^1.21.3",
- "phpstan/phpstan": "^1.4.5",
- "symfony/var-dumper": "^5.4.9"
- },
"config": {
+ "apcu-autoloader": true,
+ "optimize-autoloader": true,
+ "platform-check": false,
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
- "prefer-stable": true
+ "require-dev": {
+ "ext-iconv": "*",
+ "doctrine/coding-standard": "9.0.0",
+ "pestphp/pest": "^1.21.1",
+ "phpstan/phpstan": "^1.8.0",
+ "symfony/var-dumper": "^6.1.0"
+ }
}
diff --git a/src/Strings.php b/src/Strings.php
index 1d7f761..93c6d6a 100644
--- a/src/Strings.php
+++ b/src/Strings.php
@@ -13,6 +13,7 @@
namespace Glowy\Strings;
+use Stringable;
use ArrayAccess;
use ArrayIterator;
use Glowy\Macroable\Macroable;
@@ -23,6 +24,7 @@
use IteratorAggregate;
use OutOfBoundsException;
+use function Glowy\Strings\strings;
use function abs;
use function array_count_values;
use function array_merge;
@@ -117,7 +119,7 @@
*
* @author Sergey Romanenko
*/
-class Strings implements ArrayAccess, Countable, IteratorAggregate
+class Strings implements ArrayAccess, Countable, IteratorAggregate, Stringable
{
use Macroable;
@@ -823,7 +825,7 @@ public function indexOfLast(string $needle, int $offset = 0, bool $caseSensitive
*
* @return self Returns instance of The Strings class.
*/
- public function trim(?string $character_mask = null): self
+ public function trim(string|null $character_mask = null): self
{
$this->string = trim(...array_merge([$this->string], func_get_args()));
@@ -837,7 +839,7 @@ public function trim(?string $character_mask = null): self
*
* @return self Returns instance of The Strings class.
*/
- public function trimLeft(?string $character_mask = null): self
+ public function trimLeft(string|null $character_mask = null): self
{
$this->string = ltrim(...array_merge([$this->string], func_get_args()));
@@ -847,11 +849,11 @@ public function trimLeft(?string $character_mask = null): self
/**
* Strip whitespace (or other characters) from the end of a string.
*
- * @param string $character_mask Stripped characters can also be specified using the character_mask parameter.
+ * @param string|null $character_mask Stripped characters can also be specified using the character_mask parameter.
*
* @return self Returns instance of The Strings class.
*/
- public function trimRight(?string $character_mask = null): self
+ public function trimRight(string|null $character_mask = null): self
{
$this->string = rtrim(...array_merge([$this->string], func_get_args()));
@@ -2716,7 +2718,7 @@ public function toBoolean(): bool
*
* @return array Return Strings object as array based on a delimiter.
*/
- public function toArray(?string $delimiter = null): array
+ public function toArray(string|null $delimiter = null): array
{
$encoding = $this->encoding;
$string = static::create($this->string, $encoding)->trim()->toString();
diff --git a/src/helpers.php b/src/helpers.php
index f66be69..178c9a8 100644
--- a/src/helpers.php
+++ b/src/helpers.php
@@ -11,6 +11,8 @@
declare(strict_types=1);
+namespace Glowy\Strings;
+
use Glowy\Strings\Strings;
if (! function_exists('strings')) {
@@ -25,7 +27,7 @@
* @param mixed $string Value to modify, after being cast to string. Default: ''
* @param mixed $encoding The character encoding. Default: UTF-8
*/
- function strings($string = '', $encoding = 'UTF-8'): Strings
+ function strings($string = '', $encoding = 'UTF-8'): \Glowy\Strings\Strings
{
return new Strings($string, $encoding);
}
diff --git a/tests/StringsTest.php b/tests/StringsTest.php
index 866ded7..db07da1 100644
--- a/tests/StringsTest.php
+++ b/tests/StringsTest.php
@@ -12,6 +12,7 @@
declare(strict_types=1);
use Glowy\Strings\Strings;
+use function Glowy\Strings\strings;
test('test __construct() method', function (): void {
$this->assertInstanceOf(Strings::class, new Strings());