Download the PHP package forrest79/phpstan-narrow-types without Composer

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

PHPStan narrowing complex array/list types with assert

Build

Introduction

Check complex array/list types in runtime (via assert) and narrow variables for PHPStan.

This library is "in proof of concept" state. It could be changed or canceled anytime. Source code and tests are written in "it is working just fine" way. Parsing types is very naive and is not well tested.

The goal of this library is to get rid of @var annotations. You can check complex array/list types with assert PHP function in the same way as for the simple types (assert(is_int($var));).

Array/object shapes are not supported. Arrays must be defined with <...>, [] syntax is not supported.

There is one global function is_type(mixed $var, string $type) or static method Forrest79\NarrowTypes::isType(mixed $var, string $type). That really check data in $var against the type description and there is corresponding PHPStan extension so PHPStan will understand, that $var is in described type.

Example:

In common the assert function is disabled on production, so check is performed only on devel/test environments and there is no need to distribute this library on the production environment.

Installation

To use this extension, require it in Composer:

You probably want this extension only for dev.

Using

All simple types with correspondent is_... function are supported NULL, int, float, string, bool, callable and object. Arrays array and lists list can be defined with specified types with classic <...> syntax (known from PHPStan).

You can also use | operator like int|string.

All strings that are not matched as an internal simple types are resolved as object name. Object name can be defined with whole namespace (when starting with \) or is completed from actual class namespace/use in a classic way (thanks to nikic/php-parser).

Simple example:

For simple types is recommended to use internal PHP functions is_....

The main goal is to replace something like this:

With:

With the benefit variable $arr is checked for defined type.

To use this library as PHPStan extension include extension.neon in your project's PHPStan config:


All versions of phpstan-narrow-types with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
phpstan/phpstan Version ^2.0
nikic/php-parser Version ^5.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 forrest79/phpstan-narrow-types contains the following files

Loading the files please wait ....