Download the PHP package cooldevguys/phpstan-dhexpendency-rules without Composer

On this page you can find all versions of the php package cooldevguys/phpstan-dhexpendency-rules. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package phpstan-dhexpendency-rules

๐Ÿงญ phpstan-dhexpendency-rules

Latest Version CI

A set of additional PHPStan rules that help enforce the dependency flow of a hexagonal (ports & adapters) architecture โ€” so a stray use statement in the wrong direction gets caught in CI, not in code review. ๐Ÿšฆ

๐Ÿ“ The rule this package enforces

These rules assume the typical hexagonal architecture with 3 layers: Infrastructure, Application and Domain, and that dependencies must only ever flow one way:

In other words:

Layer May depend on May not depend on
๐Ÿ—๏ธ Infrastructure Application, Domain, external vendors (nothing forbidden)
โš™๏ธ Application Domain only Infrastructure
๐Ÿง  Domain itself only Infrastructure, Application

The Domain layer is the one that matters most to protect: it's your business logic, and it should never know that a database, an HTTP client, or a specific framework exists.

โœจ What you get

๐Ÿ“ฆ Installation

โš ๏ธ Dev-only package. This is a static analysis tool โ€” its rules only run while phpstan analyse runs, never in your application's runtime code. Always install it with --dev (as below) so it lands in require-dev, not require, and never ships to production. If you forget the flag, Composer itself will notice (this package is tagged static analysis) and offer to re-run the command with --dev for you.

If you use PHPStan's extension installer, you're all set. ๐ŸŽ‰ Otherwise, register the rules manually in your phpstan.neon:

Requirements: PHP >=7.4 and phpstan/phpstan ^2.0.

โš™๏ธ Configuration

Add your project's values nested under a single dhexpendency key in phpstan.neon:

Parameter Type Required Default Description
myVendorName string โœ… โ€” Your project's top-level namespace segment (e.g. CoolDevGuys in CoolDevGuys\App\...). Must be a valid PHP identifier.
infrastructureLayerName string โœ… โ€” The namespace segment you use for the Infrastructure layer.
applicationLayerName string โœ… โ€” The namespace segment you use for the Application layer.
domainLayerName string โœ… โ€” The namespace segment you use for the Domain layer.
vendorStrictMode bool โŒ false Enables NoExternalVendorsAllowedRule (see above).
ignoredExternalVendors string[] โŒ [] Vendor namespaces exempted from vendorStrictMode. Only has an effect when vendorStrictMode is true.

The three layer names must all be different from each other, and every name above must be a valid PHP namespace segment (letters, digits, underscores; can't start with a digit) โ€” an invalid value fails fast with a clear error instead of silently misbehaving.

โฌ†๏ธ Upgrading from 1.x?

This is a breaking change (v2.0): parameters moved from the top level of parameters: into a nested dhexpendency: key, and NoExternalVendorsAllowedFromDomainRule was renamed to NoExternalVendorsAllowedRule (it always checked Application and Domain, not just Domain โ€” the new name matches what it actually does). To migrate, just move your existing six keys under dhexpendency: as shown above; nothing else changes, and no error messages or rule identifiers were affected, so any phpstan-baseline.neon you already generated stays valid.

๐Ÿงฉ How your namespaces should look

Each layer is identified by a segment in the namespace, placed after your vendor name and an optional "context" segment โ€” for example, with the config above:

When a namespace could plausibly match more than one configured layer name at different depths, the leftmost (earliest, shallowest) match wins โ€” so a Domain module with an unrelated nested segment that happens to share a name with another layer is still correctly recognized as Domain. Files whose namespace doesn't start with your configured vendor name, or has no recognizable layer segment at all, are silently skipped by both rules (they're none of this package's business).

๐Ÿšจ What a violation looks like

Both errors carry a stable ๐Ÿชช identifier, so if you ever need to allow a specific case, you can target it precisely in phpstan.neon:

๐Ÿงญ Scope & limitations

This package covers the classic 3-layer hexagonal setup with a single project vendor namespace. It does not support additional layers (e.g. a separate Presentation/UI layer) or checking more than one vendor namespace at once.

๐Ÿงช Development

Pull requests are welcome! Please make sure vendor/bin/phpunit passes before opening one.

๐Ÿ“„ License

MIT ยฉ Alejandro Romero โ€” see LICENSE.md.


All versions of phpstan-dhexpendency-rules with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4.0
phpstan/phpstan Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package cooldevguys/phpstan-dhexpendency-rules contains the following files

Loading the files please wait ...