Requires PHP ^8.1 and PHPStan ^2.0.4.
To use this extension, require it in Composer:
composer require --dev jbboehr/phpstan-array-mergeIf you also install phpstan/extension-installer then you're all set!
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.neonHave 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);
}
}
// @akashi-phpstan-error phpstan.dumpType: array{foo: 'bar', baz: 'bat'}
\PHPStan\dumpType(ConstFixture::constMerge(['baz' => 'bat']));This project is licensed under the GNU Affero General Public License version 3
with the Romic Exception (AGPL-3.0-only WITH romic-exception).
The Romic Exception permits linking or combining this extension with other code without that other code becoming subject to the AGPL merely because of the linking or combination. Modifications to the extension remain subject to the AGPL, including its source-availability requirements for modified versions made available to users over a computer network.
See LICENSE.md and the Romic Exception for the complete terms.
Alternative commercial licenses may be available from the Project Steward. Contact John Boehr at jbboehr@gmail.com.