jbboehr / phpstan-array-merge
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:phpstan-extension
Requires
- php: ^8.1
- phpstan/phpstan: ^1.12 || ^2.0
Requires (Dev)
- composer-runtime-api: *
- brick/varexporter: *
- phpstan/phpstan-phpunit: ^1.4.2 || ^2.0.6
- phpstan/phpstan-strict-rules: ^1.6.2 || ^2.0.4
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.5
- slevomat/coding-standard: ^8.18
- squizlabs/php_codesniffer: ^3.13
- symfony/var-dumper: *
This package is auto-updated.
Last update: 2025-06-07 21:07:26 UTC
README
Installation
To use this extension, require it in Composer:
composer require --dev jbboehr/phpstan-array-merge
If you also install phpstan/extension-installer then you're all set!
Manual installation
If you don't want to use phpstan/extension-installer
, include extension.neon
in your project's PHPStan config:
includes: - vendor/jbboehr/phpstan-array-merge/extension.neon
Usage
Have you ever wanted to have a function that performs an array_merge()
-like operation but want that generic goodness
PHPStan has to offer? WAIT NO MORE!
<?php class ConstFixture { public const ARRAY = ['foo' => 'bar']; /** * @template T of array<mixed> * @param T $a * @phpstan-return array-merge<self::ARRAY, T> */ public static function constMerge(array $a): array { return array_merge(self::ARRAY, $a); } }
<?php \PHPStan\dumpType(ConstFixture::constMerge(['baz' => 'bat']));
$ phpstan ------ -------------------------------------------- Line tmp.php ------ -------------------------------------------- 3 Dumped type: array{foo: 'bar', baz: 'bat'} ------ --------------------------------------------
If you mix generic arrays and array shapes, you get what is coming to you (or open an issue).
License
This project is licensed under the AGPL v3+ License - see the LICENSE.md file for details.