PHP code example of tzmfreedom / phpstan-extensions

1. Go to this page and download the library: Download tzmfreedom/phpstan-extensions 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/ */

    

tzmfreedom / phpstan-extensions example snippets




use Tzmfreedom\Attributes\VisibleForTesting;

class Foo
{
    #[VisibleForTesting]
    public function exampleWithAttribute()
    {}

    /**
     * @visibleForTesting
     */
    public function exampleWithPhpdoc()
    {}
}

(new Foo)->exampleWithAttribute();
// error: VisibleForTesting annotated method Foo::visibleForTestingWithAttribute should be called in private scope outside of the test environment



class Foo
{
    public function getString(): string
    {
        return '';
    }
}

(new Foo)->getString(); // error: Return value on Method Foo::getString() is unused
$_ = (new Foo)->getString(); // OK



$var = null;
$var = 'hoge'; // OK, changing from null to any
$var = 'fuga'; // NG



$var = null;
$var = 'hoge'; // OK, changing from null to any
$var = 1; // NG, changing from string to integer
$var = 1.0; // OK, changing from integer to float
$var = 1; // OK, changeing from float to integer
$var = new \stdClass(); // NG
$var = new class extends \stdClass{}; // OK
$var = new \stdClass(); // OK