From f9784e5e2191d7371ae900a70f6eb58a06ce5177 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 17 Apr 2026 07:27:53 +0200 Subject: [PATCH 1/4] Replace PHP CS Fixer with Laravel Pint --- .../workflows/fix-php-code-style-issues.yml | 26 ++++++++++++ .github/workflows/php-cs-fixer.yml | 23 ----------- .php_cs.dist | 40 ------------------- composer.json | 2 + 4 files changed, 28 insertions(+), 63 deletions(-) create mode 100644 .github/workflows/fix-php-code-style-issues.yml delete mode 100644 .github/workflows/php-cs-fixer.yml delete mode 100644 .php_cs.dist diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml new file mode 100644 index 0000000..55ec5b7 --- /dev/null +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -0,0 +1,26 @@ +name: Fix PHP code style issues + +on: [push] + +permissions: + contents: write + +jobs: + style: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Fix PHP code style issues + uses: aglipanci/laravel-pint-action@2.5 + with: + preset: laravel + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Fix styling diff --git a/.github/workflows/php-cs-fixer.yml b/.github/workflows/php-cs-fixer.yml deleted file mode 100644 index 4cf285f..0000000 --- a/.github/workflows/php-cs-fixer.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Check & fix styling - -on: [push] - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - name: Run PHP CS Fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php_cs.dist --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Fix styling diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index ac127a7..0000000 --- a/.php_cs.dist +++ /dev/null @@ -1,40 +0,0 @@ -in([ - __DIR__ . '/src', - __DIR__ . '/tests', - ]) - ->name('*.php') - ->notName('*.blade.php') - ->ignoreDotFiles(true) - ->ignoreVCS(true); - -return PhpCsFixer\Config::create() - ->setRules([ - '@PSR2' => true, - 'array_syntax' => ['syntax' => 'short'], - 'ordered_imports' => ['sortAlgorithm' => 'alpha'], - 'no_unused_imports' => true, - 'not_operator_with_successor_space' => true, - 'trailing_comma_in_multiline_array' => true, - 'phpdoc_scalar' => true, - 'unary_operator_spaces' => true, - 'binary_operator_spaces' => true, - 'blank_line_before_statement' => [ - 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'], - ], - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_var_without_name' => true, - 'class_attributes_separation' => [ - 'elements' => [ - 'method', - ], - ], - 'method_argument_space' => [ - 'on_multiline' => 'ensure_fully_multiline', - 'keep_multiple_spaces_after_comma' => true, - ], - 'single_trait_insert_per_statement' => true, - ]) - ->setFinder($finder); diff --git a/composer.json b/composer.json index 4364a3e..95184eb 100644 --- a/composer.json +++ b/composer.json @@ -22,6 +22,7 @@ "anahkiasen/underscore-php": "^2.0" }, "require-dev": { + "laravel/pint": "^1.0", "phpunit/phpunit" : "^9.5" }, "autoload": { @@ -36,6 +37,7 @@ } }, "scripts": { + "format": "vendor/bin/pint", "test": "vendor/bin/phpunit", "test-coverage": "vendor/bin/phpunit --coverage-html coverage" }, From b1e538d19570ee6573c76a33f4b4dae0987e7048 Mon Sep 17 00:00:00 2001 From: freekmurze <483853+freekmurze@users.noreply.github.com> Date: Fri, 17 Apr 2026 05:28:13 +0000 Subject: [PATCH 2/4] Fix styling --- src/Exceptions/ErrorCreatingString.php | 4 +- src/Exceptions/UnknownFunction.php | 4 +- src/Exceptions/UnsetOffset.php | 4 +- src/Integrations/Underscore.php | 8 +--- src/Str.php | 54 +++++++++++--------------- tests/Functions/BetweenTest.php | 7 ++-- tests/Functions/ConcatTest.php | 3 +- tests/Functions/PossessiveTest.php | 3 +- tests/Functions/PrefixTest.php | 3 +- tests/Functions/ReplaceFirstTest.php | 3 +- tests/Functions/ReplaceLastTest.php | 3 +- tests/Functions/SegmentTest.php | 9 +++-- tests/Functions/SuffixTest.php | 3 +- tests/Functions/TeaseTest.php | 5 ++- tests/Functions/ToLowerTest.php | 3 +- tests/Functions/ToUpperTest.php | 3 +- tests/Functions/TrimTest.php | 3 +- tests/StringTest.php | 5 ++- 18 files changed, 60 insertions(+), 67 deletions(-) diff --git a/src/Exceptions/ErrorCreatingString.php b/src/Exceptions/ErrorCreatingString.php index c85a3dd..6939949 100644 --- a/src/Exceptions/ErrorCreatingString.php +++ b/src/Exceptions/ErrorCreatingString.php @@ -4,6 +4,4 @@ use Exception; -class ErrorCreatingString extends Exception -{ -} +class ErrorCreatingString extends Exception {} diff --git a/src/Exceptions/UnknownFunction.php b/src/Exceptions/UnknownFunction.php index 1344b0d..eadb360 100644 --- a/src/Exceptions/UnknownFunction.php +++ b/src/Exceptions/UnknownFunction.php @@ -4,6 +4,4 @@ use Exception; -class UnknownFunction extends Exception -{ -} +class UnknownFunction extends Exception {} diff --git a/src/Exceptions/UnsetOffset.php b/src/Exceptions/UnsetOffset.php index 800bd9c..50e63cf 100644 --- a/src/Exceptions/UnsetOffset.php +++ b/src/Exceptions/UnsetOffset.php @@ -4,6 +4,4 @@ use Exception; -class UnsetOffset extends Exception -{ -} +class UnsetOffset extends Exception {} diff --git a/src/Integrations/Underscore.php b/src/Integrations/Underscore.php index 1ee8ea1..962716a 100644 --- a/src/Integrations/Underscore.php +++ b/src/Integrations/Underscore.php @@ -8,7 +8,7 @@ class Underscore { protected array $underscoreMethods = [ - //name, firstArgumentIsString, returnsAString + // name, firstArgumentIsString, returnsAString 'accord' => [false, true], 'random' => [false, true], 'quickRandom' => [false, true], @@ -43,11 +43,7 @@ class Underscore ]; /** - * @param \Spatie\String\Str $string - * @param string $method - * @param array $args - * - * @return mixed|\Spatie\String\Str + * @return mixed|Str */ public function call(Str $string, string $method, array $args) { diff --git a/src/Str.php b/src/Str.php index 7a56798..06bf029 100644 --- a/src/Str.php +++ b/src/Str.php @@ -7,11 +7,12 @@ use Spatie\String\Exceptions\UnknownFunction; use Spatie\String\Exceptions\UnsetOffset; use Spatie\String\Integrations\Underscore; +use Underscore\Methods\StringsMethods; /** * Magic methods provided by underscore are documented here. * - * @see \Underscore\Methods\StringsMethods + * @see StringsMethods * * @method \Spatie\String\Str accord($count, $many, $one, $zero = null) * @method \Spatie\String\Str random($length = 16) @@ -72,10 +73,8 @@ public function __toString(): string /** * Get the string between the given start and end. * - * @param $start - * @param $end * - * @return \Spatie\String\Str + * @return Str */ public function between(string $start, string $end): static { @@ -84,11 +83,11 @@ public function between(string $start, string $end): static } if ($start != '' && ! str_contains($this->string, $start)) { - return new static(); + return new static; } if ($end != '' && ! str_contains($this->string, $end)) { - return new static(); + return new static; } if ($start == '') { @@ -123,17 +122,15 @@ public function toLower(): static * of the string is always a full word concatinated with the * specified moreTextIndicator. * - * @param int $length - * @param string $moreTextIndicator * - * @return \Spatie\String\Str + * @return Str */ public function tease(int $length = 200, string $moreTextIndicator = '...'): static { $sanitizedString = $this->sanitizeForTease($this->string); if (strlen($sanitizedString) === 0) { - return new static(); + return new static; } if (strlen($sanitizedString) <= $length) { @@ -150,10 +147,10 @@ private function sanitizeForTease(string $string): string { $string = trim($string); - //remove html + // remove html $string = strip_tags($string); - //replace multiple spaces + // replace multiple spaces $string = preg_replace("/\s+/", ' ', $string); return $string; @@ -161,7 +158,7 @@ private function sanitizeForTease(string $string): string public function replaceFirst(mixed $search, string $replace): static { - if ((string)$search === '') { + if ((string) $search === '') { return $this; } @@ -178,7 +175,7 @@ public function replaceFirst(mixed $search, string $replace): static public function replaceLast(mixed $search, string $replace): static { - if ((string)$search === '') { + if ((string) $search === '') { return $this; } @@ -196,9 +193,8 @@ public function replaceLast(mixed $search, string $replace): static /** * Prefix a string. * - * @param $string * - * @return \Spatie\String\Str + * @return Str */ public function prefix($string): static { @@ -208,9 +204,8 @@ public function prefix($string): static /** * Suffix a string. * - * @param $string * - * @return \Spatie\String\Str + * @return Str */ public function suffix(mixed $string): static { @@ -225,12 +220,12 @@ public function concat(mixed $string): static /** * Get the possessive version of a string. * - * @return \Spatie\String\Str + * @return Str */ public function possessive(): static { if ($this->string === '') { - return new static(); + return new static; } $noApostropheEdgeCases = ['it']; @@ -247,10 +242,8 @@ public function possessive(): static * Returns an empty string when the offset doesn't exist. * Use a negative index to start counting from the last element. * - * @param string $delimiter - * @param int $index * - * @return \Spatie\String\Str + * @return Str */ public function segment(string $delimiter, int $index): static { @@ -279,9 +272,8 @@ public function lastSegment(string $delimiter): static /** * Pop (remove) the last segment of a string based on a delimiter. * - * @param string $delimiter * - * @return \Spatie\String\Str + * @return Str */ public function pop(string $delimiter): static { @@ -293,7 +285,7 @@ public function trim(string $characterMask = " \t\n\r\0\x0B"): static return new static(trim($this->string, $characterMask)); } - public function contains(array | string $needle, bool $caseSensitive = false, bool $absolute = false): bool + public function contains(array|string $needle, bool $caseSensitive = false, bool $absolute = false): bool { return $this->find($needle, $caseSensitive, $absolute); } @@ -301,16 +293,14 @@ public function contains(array | string $needle, bool $caseSensitive = false, bo /** * Unknown methods calls will be handled by various integrations. * - * @param $method - * @param $args * - * @return mixed|\Spatie\String\Str - *@throws UnknownFunction + * @return mixed|Str * + * @throws UnknownFunction */ public function __call($method, $args) { - $underscore = new Underscore(); + $underscore = new Underscore; if ($underscore->isSupportedMethod($method)) { return $underscore->call($this, $method, $args); @@ -338,6 +328,6 @@ public function offsetSet($offset, $value) public function offsetUnset($offset) { - throw new UnsetOffset(); + throw new UnsetOffset; } } diff --git a/tests/Functions/BetweenTest.php b/tests/Functions/BetweenTest.php index d594d76..2c5d5f6 100644 --- a/tests/Functions/BetweenTest.php +++ b/tests/Functions/BetweenTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class BetweenTest extends TestCase { @@ -37,13 +38,13 @@ public function it_returns_an_the_middle_even_if_start_and_end_are_the_same_stri } /** @test */ - public function it_returns_everything_after_the_start_if_end_is_an_emptyString() + public function it_returns_everything_after_the_start_if_end_is_an_empty_string() { $this->assertEquals('MiddleEnd', (string) string('StartMiddleEnd')->between('Start', '')); } /** @test */ - public function it_returns_everything_until_the_end_if_start_is_an_emptyString() + public function it_returns_everything_until_the_end_if_start_is_an_empty_string() { $this->assertEquals('StartMiddle', (string) string('StartMiddleEnd')->between('', 'End')); } @@ -57,6 +58,6 @@ public function it_returns_everything_if_both_start_and_end_are_empty() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('test')->between('', '')); + $this->assertInstanceOf(Str::class, string('test')->between('', '')); } } diff --git a/tests/Functions/ConcatTest.php b/tests/Functions/ConcatTest.php index 55d6935..1df820b 100644 --- a/tests/Functions/ConcatTest.php +++ b/tests/Functions/ConcatTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class ConcatTest extends TestCase { @@ -15,6 +16,6 @@ public function it_can_concatenate_a_string() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('hello')->concat(' world')); + $this->assertInstanceOf(Str::class, string('hello')->concat(' world')); } } diff --git a/tests/Functions/PossessiveTest.php b/tests/Functions/PossessiveTest.php index 5151099..8f64d03 100644 --- a/tests/Functions/PossessiveTest.php +++ b/tests/Functions/PossessiveTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class PossessiveTest extends TestCase { @@ -22,7 +23,7 @@ public function it_can_handle_an_empty_string() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('Bob')->possessive()); + $this->assertInstanceOf(Str::class, string('Bob')->possessive()); } /** @test */ diff --git a/tests/Functions/PrefixTest.php b/tests/Functions/PrefixTest.php index b25eb33..32ac779 100644 --- a/tests/Functions/PrefixTest.php +++ b/tests/Functions/PrefixTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class PrefixTest extends TestCase { @@ -15,6 +16,6 @@ public function it_can_prefix_a_string() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('world')->prefix('hello ')); + $this->assertInstanceOf(Str::class, string('world')->prefix('hello ')); } } diff --git a/tests/Functions/ReplaceFirstTest.php b/tests/Functions/ReplaceFirstTest.php index 1d3ecf6..21a848f 100644 --- a/tests/Functions/ReplaceFirstTest.php +++ b/tests/Functions/ReplaceFirstTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class ReplaceFirstTest extends TestCase { @@ -34,6 +35,6 @@ public function it_returns_the_original_string_if_search_string_is_empty() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('test')->replaceFirst('search', 'replace')); + $this->assertInstanceOf(Str::class, string('test')->replaceFirst('search', 'replace')); } } diff --git a/tests/Functions/ReplaceLastTest.php b/tests/Functions/ReplaceLastTest.php index dba2534..68ff06a 100644 --- a/tests/Functions/ReplaceLastTest.php +++ b/tests/Functions/ReplaceLastTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class ReplaceLastTest extends TestCase { @@ -34,6 +35,6 @@ public function it_returns_the_original_string_if_search_string_is_empty() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('test')->replaceLast('search', 'replace')); + $this->assertInstanceOf(Str::class, string('test')->replaceLast('search', 'replace')); } } diff --git a/tests/Functions/SegmentTest.php b/tests/Functions/SegmentTest.php index b31327a..665dbc0 100644 --- a/tests/Functions/SegmentTest.php +++ b/tests/Functions/SegmentTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class SegmentTest extends TestCase { @@ -51,9 +52,9 @@ public function it_pops_the_last_segment() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->segment('/', 0)); - $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->firstSegment('/')); - $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->lastSegment('/')); - $this->assertInstanceOf(\Spatie\String\Str::class, string('foo/bar/baz')->pop('/')); + $this->assertInstanceOf(Str::class, string('foo/bar/baz')->segment('/', 0)); + $this->assertInstanceOf(Str::class, string('foo/bar/baz')->firstSegment('/')); + $this->assertInstanceOf(Str::class, string('foo/bar/baz')->lastSegment('/')); + $this->assertInstanceOf(Str::class, string('foo/bar/baz')->pop('/')); } } diff --git a/tests/Functions/SuffixTest.php b/tests/Functions/SuffixTest.php index 8b370dd..209b59e 100644 --- a/tests/Functions/SuffixTest.php +++ b/tests/Functions/SuffixTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class SuffixTest extends TestCase { @@ -15,6 +16,6 @@ public function it_can_suffix_a_string() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('hello')->suffix(' world')); + $this->assertInstanceOf(Str::class, string('hello')->suffix(' world')); } } diff --git a/tests/Functions/TeaseTest.php b/tests/Functions/TeaseTest.php index 649bc1c..22f6369 100644 --- a/tests/Functions/TeaseTest.php +++ b/tests/Functions/TeaseTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class TeaseTest extends TestCase { @@ -25,7 +26,7 @@ public function it_can_shorten_a_text_in_a_beautiful_way_to_a_specified_length() } /** @test */ - public function it_can_shorten_a_text_in_a_beautiful_way_to_a_specified_length_with_a_custom_moreTextIndicator() + public function it_can_shorten_a_text_in_a_beautiful_way_to_a_specified_length_with_a_custom_more_text_indicator() { $this->assertEquals('Now that!', (string) string($this->longText)->tease(10, '!')); } @@ -69,6 +70,6 @@ public function it_return_an_empty_string_if_after_trimming_everything_is_cleane /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('test')->tease()); + $this->assertInstanceOf(Str::class, string('test')->tease()); } } diff --git a/tests/Functions/ToLowerTest.php b/tests/Functions/ToLowerTest.php index 1d95c8b..3859932 100644 --- a/tests/Functions/ToLowerTest.php +++ b/tests/Functions/ToLowerTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class ToLowerTest extends TestCase { @@ -15,6 +16,6 @@ public function it_can_convert_a_string_to_lowercase() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('test')->toLower()); + $this->assertInstanceOf(Str::class, string('test')->toLower()); } } diff --git a/tests/Functions/ToUpperTest.php b/tests/Functions/ToUpperTest.php index 321e3c4..8695b78 100644 --- a/tests/Functions/ToUpperTest.php +++ b/tests/Functions/ToUpperTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class ToUpperTest extends TestCase { @@ -15,6 +16,6 @@ public function it_can_convert_a_string_to_uppercase() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('test')->toUpper()); + $this->assertInstanceOf(Str::class, string('test')->toUpper()); } } diff --git a/tests/Functions/TrimTest.php b/tests/Functions/TrimTest.php index 4dac880..2d18284 100644 --- a/tests/Functions/TrimTest.php +++ b/tests/Functions/TrimTest.php @@ -3,6 +3,7 @@ namespace Spatie\String\Test\Functions; use PHPUnit\Framework\TestCase; +use Spatie\String\Str; class TrimTest extends TestCase { @@ -21,6 +22,6 @@ public function it_trims_custom_characters() /** @test */ public function it_is_chainable() { - $this->assertInstanceOf(\Spatie\String\Str::class, string(' foo ')->trim()); + $this->assertInstanceOf(Str::class, string(' foo ')->trim()); } } diff --git a/tests/StringTest.php b/tests/StringTest.php index 8d3064c..2d27b2d 100644 --- a/tests/StringTest.php +++ b/tests/StringTest.php @@ -4,13 +4,14 @@ use PHPUnit\Framework\TestCase; use Spatie\String\Exceptions\ErrorCreatingString; +use Spatie\String\Str; class StringTest extends TestCase { /** @test */ public function the_string_function_returns_a_string_instance() { - $this->assertInstanceOf(\Spatie\String\Str::class, string('test')); + $this->assertInstanceOf(Str::class, string('test')); } /** @test */ @@ -46,7 +47,7 @@ public function it_doesnt_accept_objects_that_dont_implement_tostring() { $this->expectException(ErrorCreatingString::class); - string(new \StdClass()); + string(new \StdClass); } /** @test */ From bc4fa759d57953d1ded64b858285bf4a03fc5dd8 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 17 Apr 2026 07:29:33 +0200 Subject: [PATCH 3/4] Trigger CI From 6f2625a49b5d44e011e9227b146f6fe90690c4c5 Mon Sep 17 00:00:00 2001 From: Freek Van der Herten Date: Fri, 17 Apr 2026 07:30:25 +0200 Subject: [PATCH 4/4] Update deprecated GitHub Actions versions --- .github/workflows/run-tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 4b99c74..38417d7 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -19,10 +19,10 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ~/.composer/cache/files key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} @@ -35,7 +35,7 @@ jobs: coverage: none - name: Install dependencies - run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest + run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction - name: Configure matchers uses: mheap/phpunit-matcher-action@v1