diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..162da22 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,8 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + target-branch: "develop" + schedule: + interval: "monthly" + open-pull-requests-limit: 5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5467742..be0156f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,27 +1,26 @@ -name: Check code +name: Run tests on: push: pull_request: jobs: - - check: - name: Run checks - PHP ${{ matrix.php }} - ${{ matrix.dependency-version }} + test: + name: Run tests - PHP ${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }} runs-on: ${{ matrix.os }} strategy: - fail-fast: false + fail-fast: true matrix: - php: [8.1, 8.2] - dependency-version: [prefer-lowest, prefer-stable] - os: [ubuntu-latest] + os: [ ubuntu-latest ] + php: [ 8.3, 8.4 ] + stability: [ prefer-lowest, prefer-stable ] steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Cache PHP dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: '**/vendor' key: ${{ runner.os }}-vendor-cache-${{ hashFiles('**/composer.lock') }} @@ -29,7 +28,7 @@ jobs: ${{ runner.os }}-vendor-cache- - name: Cache Composer dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.composer/cache/files key: composer-${{ runner.os }}-php-${{ matrix.php }}-${{ hashFiles('composer.json') }} @@ -45,10 +44,10 @@ jobs: coverage: none - name: Install dependencies - run: composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress --optimize-autoloader + run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress --optimize-autoloader - name: Lint code - run: PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --dry-run --diff + run: vendor/bin/pint --test - name: Run tests run: vendor/bin/phpunit diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php deleted file mode 100644 index 70d0ba3..0000000 --- a/.php-cs-fixer.dist.php +++ /dev/null @@ -1,247 +0,0 @@ - true, - '@PSR2' => true, - '@PhpCsFixer' => true, - '@Symfony' => true, - '@PHP70Migration' => true, - '@PHP70Migration:risky' => true, - '@PHP71Migration' => true, - '@PHP71Migration:risky' => true, - '@PHP73Migration' => true, - '@PHPUnit75Migration:risky' => true, - 'final_class' => false, - 'new_with_braces' => false, - 'strict_comparison' => true, - 'list_syntax' => ['syntax' => 'short'], - 'mb_str_functions' => true, - 'class_attributes_separation' => [ - 'elements' => [ - 'method' => 'one', - ], - ], - 'no_extra_blank_lines' => [ - 'tokens' => [ - 'break', - 'continue', - 'curly_brace_block', - 'extra', - 'parenthesis_brace_block', - 'return', - 'square_brace_block', - 'throw', - 'use', - 'use_trait', - 'switch', - - 'case', - 'default', - ], - ], - 'no_blank_lines_before_namespace' => false, - 'nullable_type_declaration_for_default_null_value' => true, - 'increment_style' => ['style' => 'pre'], - 'self_static_accessor' => true, - 'static_lambda' => false, - 'no_empty_phpdoc' => true, - 'no_superfluous_phpdoc_tags' => [ - 'remove_inheritdoc' => true, - ], - 'phpdoc_line_span' => [ - 'const' => 'multi', - 'method' => 'multi', - 'property' => 'multi', - ], - 'general_phpdoc_tag_rename' => true, - 'phpdoc_add_missing_param_annotation' => ['only_untyped' => true], - 'phpdoc_align' => ['align' => 'left'], - 'phpdoc_indent' => true, - 'phpdoc_inline_tag_normalizer' => true, - 'phpdoc_no_access' => true, - 'phpdoc_no_empty_return' => false, - 'phpdoc_no_package' => true, - 'phpdoc_no_useless_inheritdoc' => true, - 'phpdoc_order' => true, - 'phpdoc_order_by_value' => false, - 'phpdoc_scalar' => true, - 'phpdoc_single_line_var_spacing' => true, - 'phpdoc_summary' => true, - 'phpdoc_tag_casing' => ['tags' => ['inheritDoc']], - 'phpdoc_tag_type' => true, - 'phpdoc_to_comment' => true, - 'phpdoc_trim' => true, - 'phpdoc_types' => ['groups' => ['simple', 'alias']], - 'phpdoc_types_order' => ['null_adjustment' => 'always_last'], - 'phpdoc_var_annotation_correct_order' => true, - 'phpdoc_var_without_name' => true, - 'align_multiline_comment' => ['comment_type' => 'phpdocs_like'], - 'php_unit_test_class_requires_covers' => false, - 'php_unit_internal_class' => false, - 'yoda_style' => false, - 'ordered_class_elements' => [ - 'order' => [ - 'use_trait', - 'constant_public', - 'constant_protected', - 'constant_private', - - 'property_static', - 'property_public_static', - 'property_protected_static', - 'property_private_static', - - 'property', - 'property_public', - 'property_protected', - 'property_private', - - 'construct', - 'destruct', - 'magic', - - 'method_static', - 'method_public_abstract_static', - 'method_public_static', - 'method_protected_abstract_static', - 'method_protected_static', - 'method_private_static', - 'method_public_abstract', - 'method_public', - 'method_protected_abstract', - 'method_protected', - 'method_private', - ], - ], - 'array_syntax' => ['syntax' => 'short'], - 'blank_line_after_namespace' => true, - 'blank_line_after_opening_tag' => true, - 'braces' => true, - 'cast_spaces' => true, - 'concat_space' => [ - 'spacing' => 'none', - ], - 'declare_equal_normalize' => true, - 'elseif' => true, - 'encoding' => true, - 'full_opening_tag' => true, - 'fully_qualified_strict_types' => true, // added by Shift - 'function_declaration' => true, - 'function_typehint_space' => true, - 'heredoc_to_nowdoc' => true, - 'include' => true, - 'indentation_type' => true, - 'linebreak_after_opening_tag' => true, - 'line_ending' => true, - 'lowercase_cast' => true, - 'lowercase_keywords' => true, - 'lowercase_static_reference' => true, // added from Symfony - 'magic_method_casing' => true, // added from Symfony - 'magic_constant_casing' => true, - 'method_argument_space' => true, - 'native_function_casing' => true, - 'no_alias_functions' => false, - 'no_blank_lines_after_class_opening' => true, - 'no_blank_lines_after_phpdoc' => true, - 'no_closing_tag' => true, - 'no_empty_statement' => true, - 'no_leading_import_slash' => true, - 'no_leading_namespace_whitespace' => true, - 'no_mixed_echo_print' => [ - 'use' => 'echo', - ], - 'no_multiline_whitespace_around_double_arrow' => true, - 'multiline_whitespace_before_semicolons' => [ - 'strategy' => 'no_multi_line', - ], - 'no_short_bool_cast' => true, - 'no_singleline_whitespace_before_semicolons' => true, - 'no_spaces_after_function_name' => true, - 'no_spaces_inside_parenthesis' => true, - 'no_trailing_comma_in_list_call' => false, - 'no_trailing_comma_in_singleline_array' => true, - 'no_trailing_whitespace' => true, - 'no_trailing_whitespace_in_comment' => true, - 'no_unreachable_default_argument_value' => true, - 'no_useless_return' => true, - 'no_whitespace_before_comma_in_array' => true, - 'no_whitespace_in_blank_line' => true, - 'normalize_index_brace' => true, - 'not_operator_with_successor_space' => true, - 'object_operator_without_whitespace' => true, - 'self_accessor' => false, - 'short_scalar_cast' => true, - 'simplified_null_return' => false, // disabled by Shift - 'single_blank_line_at_eof' => true, - 'single_blank_line_before_namespace' => true, - 'single_import_per_statement' => true, - 'single_line_after_imports' => true, - 'single_line_comment_style' => [ - 'comment_types' => ['hash'], - ], - 'single_quote' => true, - 'space_after_semicolon' => true, - 'standardize_not_equals' => true, - 'switch_case_semicolon_to_colon' => true, - 'switch_case_space' => true, - 'ternary_operator_spaces' => true, - 'trim_array_spaces' => true, - 'unary_operator_spaces' => true, - 'whitespace_after_comma_in_array' => true, - 'constant_case' => ['case' => 'lower'], - 'psr_autoloading' => true, - 'trailing_comma_in_multiline' => ['elements' => ['arrays']], - 'binary_operator_spaces' => [ - 'default' => 'single_space', - ], - 'types_spaces' => [ - 'space' => 'none', - ], - 'blank_line_before_statement' => [ - 'statements' => ['return'], - ], - 'class_definition' => [ - 'multi_line_extends_each_single_line' => true, - 'single_item_single_line' => true, - 'single_line' => true, - ], - 'ordered_imports' => [ - 'sort_algorithm' => 'alpha', - ], - 'global_namespace_import' => [ - 'import_classes' => true, - 'import_constants' => true, - 'import_functions' => true, - ], - 'no_unneeded_control_parentheses' => [ - 'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'], - ], - 'no_spaces_around_offset' => [ - 'positions' => ['inside', 'outside'], - ], - 'visibility_required' => [ - 'elements' => ['property', 'method', 'const'], - ], -]; - -$finder = Finder::create() - ->in([ - __DIR__.'/src', - __DIR__.'/tests', - ]) - ->name('*.php') - ->notName('*.blade.php') - ->ignoreDotFiles(true) - ->ignoreVCS(true); - -return (new Config) - ->setRules($rules) - ->setFinder($finder) - ->setRiskyAllowed(true) - ->setUsingCache(true); diff --git a/CHANGELOG.md b/CHANGELOG.md index f9a2977..a0e2c70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ All notable changes to `sebastiaanluca/php-pipe-operator` will be documented in Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## 7.0.0 (2025-02-07) + +### Added + +- Added support for PHP 8.4 + +### Removed + +- Dropped support for PHP 8.2 + ## 6.0.0 (2023-02-06) ### Added diff --git a/README.md b/README.md index c6ca25e..bf5199c 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![Total downloads][downloads-badge]][link-packagist] [![Total stars][stars-badge]][link-github] -[![Read my blog][blog-link-badge]][link-blog] +[![Visit my website][website-link-badge]][link-website] [![View my other packages and projects][packages-link-badge]][link-packages] [![Follow @sebastiaanluca on Twitter][twitter-profile-badge]][link-twitter] [![Share this package on Twitter][twitter-share-badge]][link-twitter-share] @@ -332,18 +332,17 @@ If you discover any security related issues, please email [hello@sebastiaanluca. ## About -My name is Sebastiaan and I'm a freelance Laravel developer specializing in building custom Laravel applications. Check out my [portfolio][link-portfolio] for more information, [my blog][link-blog] for the latest tips and tricks, and my other [packages][link-packages] to kick-start your next project. +My name is Sebastiaan and I'm a freelance back-end developer specializing in building custom Laravel web apps. Check out my [website][link-website] for more information and my other [packages][link-packages] to kick-start your next project. Have a project that could use some guidance? Send me an e-mail at [hello@sebastiaanluca.com][link-author-email]! - [version-badge]: https://img.shields.io/packagist/v/sebastiaanluca/php-pipe-operator.svg?label=stable [license-badge]: https://img.shields.io/badge/license-MIT-informational.svg [githubaction-badge]: https://github.com/sebastiaanluca/php-pipe-operator/actions/workflows/test.yml/badge.svg?branch=master [downloads-badge]: https://img.shields.io/packagist/dt/sebastiaanluca/php-pipe-operator.svg?color=brightgreen [stars-badge]: https://img.shields.io/github/stars/sebastiaanluca/php-pipe-operator.svg?color=brightgreen -[blog-link-badge]: https://img.shields.io/badge/link-blog-lightgrey.svg +[website-link-badge]: https://img.shields.io/badge/link-website-lightgrey.svg [packages-link-badge]: https://img.shields.io/badge/link-other_packages-lightgrey.svg [twitter-profile-badge]: https://img.shields.io/twitter/follow/sebastiaanluca.svg?style=social [twitter-share-badge]: https://img.shields.io/twitter/url/http/shields.io.svg?style=social @@ -354,8 +353,7 @@ Have a project that could use some guidance? Send me an e-mail at [hello@sebasti [link-twitter-share]: https://twitter.com/intent/tweet?text=Use%20PHP%27s%20pipe%20operator%20now!%20https%3A%2F%2Fgithub.com%2Fsebastiaanluca%2Fphp-pipe-operator%20via%20%40sebastiaanluca [link-contributors]: ../../contributors -[link-portfolio]: https://sebastiaanluca.com -[link-blog]: https://sebastiaanluca.com/blog +[link-website]: https://sebastiaanluca.com [link-packages]: https://packagist.org/packages/sebastiaanluca [link-twitter]: https://twitter.com/sebastiaanluca [link-github-profile]: https://github.com/sebastiaanluca diff --git a/composer.json b/composer.json index 159e26f..a0463de 100644 --- a/composer.json +++ b/composer.json @@ -19,12 +19,13 @@ } ], "require": { - "php": "~8.1|~8.2" + "php": "^8.3.0" }, "require-dev": { - "ext-mbstring": "~8.1|~8.2", - "friendsofphp/php-cs-fixer": "^3.14", - "phpunit/phpunit": "^9.6" + "ext-mbstring": "^8.3.0", + "laravel/pint": "^1.20", + "phpunit/phpunit": "^9.6", + "rector/rector": "^2.0" }, "autoload": { "psr-4": { @@ -45,23 +46,35 @@ "minimum-stability": "dev", "prefer-stable": true, "scripts": { - "composer:validate": "@composer validate --strict --ansi", - "test": "vendor/bin/phpunit", - "lint": "PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --dry-run --diff --ansi", - "fix": "PHP_CS_FIXER_IGNORE_ENV=true vendor/bin/php-cs-fixer fix --ansi", - "check": [ - "@composer:validate", - "@lint", - "@test" + "post-update-cmd": [ + "@fix" + ], + + "validate:composer": "@composer validate --strict --ansi", + "pint:check": "@php vendor/bin/pint --test --ansi", + "pint": "@php vendor/bin/pint --ansi", + "rector:check": "@php vendor/bin/rector --dry-run --ansi", + "rector": "@php vendor/bin/rector --ansi", + "phpunit": "@php vendor/bin/phpunit --order-by=random", + + "test": [ + "@validate:composer", + "@pint:check", + "@rector:check", + "@phpunit" + ], + "fix": [ + "@pint", + "@rector" ], - "check:lowest": [ + + "test:lowest": [ "composer update --prefer-lowest --prefer-dist --no-interaction --ansi", - "@check" + "@test" ], - "check:stable": [ + "test:stable": [ "composer update --prefer-stable --prefer-dist --no-interaction --ansi", - "@check" + "@test" ] } } - diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..48f419f --- /dev/null +++ b/pint.json @@ -0,0 +1,12 @@ +{ + "preset": "laravel", + "rules": { + "phpdoc_single_line_var_spacing": true, + "phpdoc_align": false, + "class_attributes_separation": { + "elements": { + "method": "one" + } + } + } +} diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..deeb58d --- /dev/null +++ b/rector.php @@ -0,0 +1,54 @@ +withParallel() + ->withPaths([ + __DIR__.'/src', + __DIR__.'/tests', + ]) + ->withImportNames( + importDocBlockNames: false, + removeUnusedImports: true, + ) + ->withPhpSets() + ->withPreparedSets( + deadCode: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + earlyReturn: true, + strictBooleans: true, + ) + ->withSets([ + PHPUnitSetList::PHPUNIT_80, + PHPUnitSetList::PHPUNIT_90, + PHPUnitSetList::PHPUNIT_100, + PHPUnitSetList::PHPUNIT_110, + ]) + ->withRules([ + ReadOnlyClassRector::class, + ReadOnlyPropertyRector::class, + ]) + ->withSkip([ + CatchExceptionNameMatchingTypeRector::class, + ChangeOrIfContinueToMultiContinueRector::class, + ClosureToArrowFunctionRector::class, + FirstClassCallableRector::class, + NewlineAfterStatementRector::class, + RemoveUnusedPrivateMethodRector::class => [ + __DIR__.'/tests/MethodsTest.php', + ], + ]); diff --git a/src/Pipe.php b/src/Pipe.php index 5c7a7c7..c20087b 100644 --- a/src/Pipe.php +++ b/src/Pipe.php @@ -6,12 +6,8 @@ class Pipe { - protected mixed $value; - - public function __construct(mixed $value) + public function __construct(protected mixed $value) { - $this->value = $value; - if (! defined('PIPED_VALUE')) { define('PIPED_VALUE', 'PIPED_VALUE-'.uniqid('', true)); } diff --git a/src/PipeProxy.php b/src/PipeProxy.php index 033ce8c..407efb8 100644 --- a/src/PipeProxy.php +++ b/src/PipeProxy.php @@ -8,14 +8,7 @@ class PipeProxy { - protected Pipe $item; - protected object $object; - - public function __construct(Pipe $item, object $object) - { - $this->item = $item; - $this->object = $object; - } + public function __construct(protected Pipe $item, protected object $object) {} public function __call(string $method, array $arguments): Pipe { diff --git a/tests/MethodsTest.php b/tests/MethodsTest.php index 2af9508..a0f5a2a 100644 --- a/tests/MethodsTest.php +++ b/tests/MethodsTest.php @@ -88,7 +88,7 @@ public function it can transform a value using a closure(): void $this->assertSame( 'prefixed-string', take('string') - ->pipe(function (string $value) { + ->pipe(function (string $value): string { return 'prefixed-'.$value; }) ->get() @@ -147,6 +147,11 @@ public function it can transform a value using a proxied public class  ); } + public function uppercase(string $value): string + { + return mb_strtoupper($value); + } + /** * @test */ @@ -174,6 +179,16 @@ public function it can transform a value using a proxied private class ); } + private function lowercase(string $value): string + { + return mb_strtolower($value); + } + + private function join(string ...$values): string + { + return implode('-', $values); + } + /** * @test */ @@ -199,19 +214,4 @@ public function it can transform a value while accepting pipe parameters ->get() ); } - - public function uppercase(string $value): string - { - return mb_strtoupper($value); - } - - private function lowercase(string $value): string - { - return mb_strtolower($value); - } - - private function join(string ...$values): string - { - return implode('-', $values); - } }