Download the PHP package fleshgrinder/assertion without Composer

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

Latest Stable Version Latest Unstable Version Travis Build status License Total Downloads

Coveralls branch Scrutinizer SensioLabs Insight Code Climate: GPA Code Climate: Issues

PHP Assertions

Library to ease defensive and design by contract (DbC) programming with assert() in PHP.

Installation

Open a terminal, enter your project directory and execute the following command to add this package to your dependencies:

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

NOTE: Do not install the library as a development requirement because composer does not install them when a library is installed as a dependency of another library. You want your assertions to be executed at all times, except when the full application goes into production; which is managed through the configuration.

Usage

This library provides a single purely static class that can be used in assertions to ease repetitive scalar inspections as well as writing custom inspections on top of it. The following code example illustrates the basic usage:

Big Floats

The PHP extension BC Math is required to validate big float numbers. It is not required but a E_USER_NOTICE error is triggered if a big float is encountered and the extension is not available. PHP must be compiled with the --enable-bcmath flag and the extension is always loaded on Windows systems.

Defensive Programming / Design by Contract

Be polite, Never Assert

Avoid the assert() mechanism, because it could turn a three-day debug fest into a ten minute one.”

How to Write Unmaintainable Code, Roedy Green.

Be sure to check the Weblinks section and read through all the sources to find out what assertions are good for, when to use them, and when not. Feel free to open an issue if you are still in doubt.

Configuration

Assertions need to be configured appropriately in order to be useful during Production.

Development

Production

Note

Default functions that are already provided by PHP are not redefined in this library. Use the language functions whenever possible, e.g.: is_string, is_int, is_float, is_numeric, …

However, many of the filter functions are exposed via methods that do not require additional arguments, for instance the integer and float assertions pass their arguments to the filter function with the appropriate filter and options set. Be careful and consider using is_int and is_float if you actually need the correct type but be even more careful if you need to handle very big numbers, in these cases use this library again since it will fall back to bcmath functions as needed while ensuring best performance by using the most appropriate library in the background.

FAQ

Why is the class called Variable?

In order to result in nice English sentences, just look at the following:

Why is it a class in the first place and not a collection of procedural functions?

Because PHP (composer) does not support lazy loading of procedural functions and it makes no sense to include the file in production. Using a class on the other hand makes lazy loading possible.

Why does the class not follow PSR-4 (and the associated vendor prefixing to avoid conflicts) while the tests do?

To minimize noise within the assert calls and possible extra work with IDEs (like PhpStorm) that automatically import classes with use statements that do not work nicely together with assert. I consider the likelihood of another class being named after something generic as variable to be very low and thus concluded that above arguments are reason enough to put it in the global namespace.

Credits

Credit where credit is due: this library was inspired by Drupal’s Inspector class.

Weblinks

License

MIT License


All versions of assertion with dependencies

PHP Build Version
Package Version
Requires php Version ^7.0
symfony/polyfill-php71 Version ^1.3
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 fleshgrinder/assertion contains the following files

Loading the files please wait ....