Skip to content

Stern lets you built type-safe PHP projects, even if your project's users aren't writing type-safe code

License

Notifications You must be signed in to change notification settings

paragonie/stern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Stern

Build Status Latest Stable Version Latest Unstable Version License

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:

  1. Make your class use the SternTrait.
  2. Rename your methods from whateverName to strictWhateverName.
  3. 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
      {
      }
  }