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.
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.
You can install the package via composer:
composer require spatie/phpstan-module-boundaries
$skeleton = new Spatie\PhpStanModuleBoundaries();
echo $skeleton->echoPhrase('Hello, Spatie!');
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.