Download the PHP package vkcom/modulite-phpstan without Composer

On this page you can find all versions of the php package vkcom/modulite-phpstan. 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 modulite-phpstan

Modulite plugin for PHPStan

Modulite is a conception that brings modules into the PHP language. PHP does not have native modules (internal classes, private namespaces, explicit exports), and Modulite tries to eliminate this drawback.

Actually, all "modularity" is represented as .modulite.yaml files, which declare exports and requires. There is a PHPStorm plugin that deeply integrates into an IDE, visualizes yaml config and provides actions to modify it.

This PHPStan plugin reads .modulite.yaml files and fires errors if your code breaks modularity. That allows you to check a whole project in Git hooks, in CI, etc.

Tip. If you are unfamiliar with Modulite, consider a PHPStorm plugin and a landing page (in Russian).

Installation and configuration

To install, just use Composer:

After installing, include the plugin in your phpstan.neon and pass 2 parameters:

Example project

Clone modulite-example-project, run composer install, run vendor/bin/phpstan analyze, and see some errors.

The example intentionally contains some errors :) Also, it describes several steps of making its code perfect.

You can use Modulite while developing Composer packages, too. Moreover, you can control which symbols are exported from your package. That ability is covered in documentation.

How the plugin works

As expected, modulite-phpstan analyzes function calls, class usages, PHPDocs, etc., and ensures that your code fits export, require, and other Modulite rules.

We advise you to use PHPStorm while development, because PHPStorm's plugin smoothly integrates into an IDE, producing .modulite.yaml files, which are analyzed by modulite-phpstan.

Typically, a project structure is the following:

When PHPStan starts analyzing your code, this plugin

The plugin has to scan vendor, because Composer packages are also checked to be required, etc. Moreover, a package can also be developed using Modulite and contain private symbols, so when embedded into your project, the plugin would check against their usages also.

Modulite files are parsed, resolved and validated once PHPStan runs. In case they contain no errors, all modularity checks will be performed. Otherwise, yaml errors are dumped and no checks are performed.

Composer packages outside vendor dir

In rare situations, you may be developing Composer packages locally, in the same repo. Being installed to vendor, they are just symlinked:

In such cases, PHPStan's internal reflection discovers some classes in packages/, which are expected to be in vendor/ from the Modulite's point of view. Without additional hints, Modulite will produce errors, thinking vendor/ uses files out of scope.

To overcome this problem, pass additionalPackagesRoot parameter besides srcRoot. Then modulite-phpstan will also scan that directory and create necessary path mappings.

A sad note about PHPStan cache

If a PHP file is unchanged, PHPStan doesn't run analysis within it. It caches files state and errors, and just dumps them out, it analyzes only diff and changed dependencies.

As appears from the above,

For now, a 100% working advice is to clear cache from time to time:

That will make PHPStan analyze a whole project, and the plugin will work as expected.

Probably, this may be fixed using some deep knowledge of PHPStan cache internals, how to embed into it and how to tell PHPStan about PHP<->yaml interconnection. If you are experienced in writing plugins, give a suggestion in this issue.

Limitations

Contributing notes

Keep in mind, that all logic of Modulite behavior must be equal in 3 places:

If you find a bug, it's either a specific bug related to PHPStan peculiarities, or it may be a bug that also exists in other implementations and should be fixed simultaneously. If you have a feature request, it must be implemented in three repos at the same time, covered with the same tests, also. So, feel free to file issues, we'll find a way to manage them.

If you are experienced in PHPStan internals, and you have some advices to make this plugin more canonical, we'd be glad to see your comments and PRs.

Ask questions and provide feedback

This plugin was developed by the KPHP Team at VK.com.

To communicate with our community, use GitHub issues or a Telegram chat.


All versions of modulite-phpstan with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
phpstan/phpstan Version ^1.8
symfony/polyfill-php80 Version ^v1.27.0
symfony/yaml Version ^5.4 || ^6.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 vkcom/modulite-phpstan contains the following files

Loading the files please wait ....