paragonie / stern
Stern lets you built type-safe PHP projects, even if your project's users aren't writing type-safe code
Installs: 1 414
Dependents: 1
Suggesters: 0
Security: 0
Stars: 21
Watchers: 6
Forks: 1
Open Issues: 0
Requires
- php: ^7|^8
Requires (Dev)
- phpunit/phpunit: ^6|^7|^8|^9
- vimeo/psalm: ^1|^3|^4
This package is auto-updated.
Last update: 2024-12-12 10:34:46 UTC
README
Stern lets you built type-safe PHP projects, even if your project's users aren't writing type-safe code.
Requires PHP 7+
Usage
Using Stern is simply:
- Make your class use the
SternTrait
. - Rename your methods from
whateverName
tostrictWhateverName
. - Enjoy strict-typing whether your users like it or not.
Example
<?php declare(strict_types=1); namespace YourVendor\YourNamespace; class YourClassThatUsesStrictTypes { + use \ParagonIE\Stern\SternTrait; /* ... */ - public function foo(string $param = ''): bool + public function strictFoo(string $param = ''): bool { } }
Docblock Usability
For better usability (especially with type-aware IDEs like PHPStorm), make sure
you use @method
docblocks.
<?php declare(strict_types=1); namespace YourVendor\YourNamespace; + /** + * @method bool foo(string $param = '') + */ class YourClassThatUsesStrictTypes { + use \ParagonIE\Stern\SternTrait; /* ... */ - public function foo(string $param = ''): bool + public function strictFoo(string $param = ''): bool { } }