Download the PHP package nish/phpstan-safestring-rule without Composer

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

PHPStan SafeString Rule Extension

This package is a PHPStan extension for checking unsafe string, e.g. Check calling echo without calling htmlspecialchars, check calling database query without using prepared statement.

Notice

This package does not meet the "backward compatibility promise". Because it extends the basic processing of the core, it is not guaranteed to work with version differences.

https://phpstan.org/developing-extensions/backward-compatibility-promise

Install

How to use

Add to phpstan.neon

composer.json is:

Value Object class src/ProductDto.php:

Html Template src/ProductHtml.php:

The execution result of phpstan in this case is as followings:

Then, can not call echo the string type directly.

safehtml-string is a virtual type, it can be fixed by adding a helper function.

src/functions.php:

phpstan.neon

src/ProductHtml.php:

run phpstan

OK, no errors and it's secure!

Tips

Constant String Type is not needs convert to safehtml-string.

This is no error.

When used for methods instead of functions:

Cannot specify more than one at a time.

Use safe-string Custom Type

If you have the following database access program

pdo->query() is not secure.

If the class is the following program,

I want an error to be displayed.

Achieve that by writing the following settings to phpstan.neon.

0 is the index of the argument.

Run phpstan.

More control, it can use the safe-string type.

What happens if I write a hint?

Changed to caller error.

If the string is clearly known to be "constant string (and its derivatives)", no error is raised.

Tips

Add return type rules:

factory: Nish\PHPStan\Rules\SafeStringReturnTypeRule([
    App\Db\Utils::getSafeConditionString,
])
tags: [phpstan.rules.rule]

All versions of phpstan-safestring-rule with dependencies

PHP Build Version
Package Version
Requires php Version ~7.1 || ~8.0
phpstan/phpstan Version ^1.4.6
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 nish/phpstan-safestring-rule contains the following files

Loading the files please wait ....