PHP code example of knplabs / phpstan-rules

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

    

knplabs / phpstan-rules example snippets


$a = new DateTime();
$b = new DateTime('now');
$c = new DateTimeImmutable();
$d = new DateTimeImmutable('now');
$e = new DateTimeImmutable('yesterday');
$f = new DateTimeImmutable('tomorrow');
$g = new DateTime('+1 day');
$h = new DateTimeImmutable('next Monday');

$a = new DateTime('2023-01-01');
$b = new DateTimeImmutable('2023-12-31 23:59:59');
$c = new DateTimeImmutable($dateVariable);

use Psr\Clock\ClockInterface;

final class MyService
{
    public function __construct(private readonly ClockInterface $clock) {}

    public function doSomething(): void
    {
        $now = $this->clock->now();
        // ...
    }
}

$a = time();
$b = date('Y-m-d');
$c = date('Y-m-d', time());
$d = date('Y-m-d', 'now');

$a = date('Y-m-d', 1672531200);
$b = date('Y-m-d', $someTimestamp);

use Psr\Clock\ClockInterface;

final class MyService
{
    public function __construct(private readonly ClockInterface $clock) {}

    public function doSomething(): void
    {
        $now = $this->clock->now();
        // ...
    }
}