Skip to content

spatie/phpstan-module-boundaries

Repository files navigation

A PhpStan plugin to keep make classes private for their contexts

Latest Version on Packagist Tests Total Downloads

This plugin is just a proof of concept for now. The goal is to have a linter that allows the developer to specify which classes can and can't be used across contexts. For example, a StripePayment class that's an implementation detail of the Payment context shouldn't be used in the Order context.

$ ./vendor/bin/phpstan analyse
Note: Using configuration file /Users/sebastiandedeyne/Sites/phpstan-module-boundaries/phpstan.neon.
 4/4 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%

 ------ -----------------------------------------------------------------------
  Line   Context/Order/Order.php
 ------ -----------------------------------------------------------------------
  21     Internal class App\Context\Payment\Internal\StripePayment was used in
         Order module.
 ------ -----------------------------------------------------------------------



 [ERROR] Found 1 error

In this bare-bones implementation, classes nested in an Internal namespace aren't allowed to be used in other context. In the future, I'll probably provide an #[Internal] #[Expose] attribute to flag classes as (in)accessible for other contexts.

This idea is inspired by Java's class visibility. In Java, a class is only visible in the package it lives in. You need to explicitly make it public to allow others to use it.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/phpstan-module-boundaries

Usage

$skeleton = new Spatie\PhpStanModuleBoundaries();
echo $skeleton->echoPhrase('Hello, Spatie!');

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages