PHP code example of glpi-project / phpstan-glpi

1. Go to this page and download the library: Download glpi-project/phpstan-glpi library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

glpi-project / phpstan-glpi example snippets


$class = $_GET['itemtype'];

$object = new $class(); // unsafe

if (is_a($class, CommonDBTM::class, true)) {
    $object = new $class(); // safe
}

class MyClass
{
    /**
     * @var class-string<\CommonDBTM> $class
     */
    public function doSomething(string $class): void
    {
        $object = new $class(); // safe

        // ...
    }
}

Session::checkRight('computer', READ); // wrong

Session::checkRight(Computer::$rightname, READ); // correct

/** @var \Migration $migration */
global migration;
neon
parameters:
    level: 0
    paths:
        - ajax
        - front
        - inc # or `src` if your PHP class files are in the `src` directory
        - hook.php
        - setup.php
    scanDirectories:
        - ../../inc
        - ../../src

    bootstrapFiles:
        - ../../stubs/glpi_constants.php
        - ../../vendor/autoload.php