PHP code example of gian-tiaga / phpstan-strict-rules

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

    

gian-tiaga / phpstan-strict-rules example snippets




namespace App\Example;



declare(strict_types=1);

namespace App\Example;

$user = new User('[email protected]', 'Иван');
$logger->info('message', ['userId' => $userId]);

$user = new User(email: '[email protected]', name: 'Иван');
$logger->info(message: 'message', context: ['userId' => $userId]);

if ($status == 'active') {
}

if ($status != 'active') {
}

if ($status === UserStatus::Active) {
}

if ($status !== UserStatus::Active) {
}

/**
 * @param array $items
 * @return array
 */
public function names(array $items): array
{
    return $items;
}

/**
 * @param list<UserName> $items
 * @return list<string>
 */
public function names(array $items): array
{
    return array_map(
        callback: static fn(UserName $name): string => $name->value,
        array: $items,
    );
}

final class MarkNotificationsRead
{
    public function __construct(
        private readonly DatabaseInterface $database,
    ) {}

    public function run(): void
    {
        $this->database->update('notifications');
    }
}

final class MarkNotificationsRead implements SetBasedWrite
{
    public function __construct(
        private readonly DatabaseInterface $database,
    ) {}

    public function run(): void
    {
        $this->database->update('notifications');
    }
}

final class StockChangedEvent implements IntegrationEventContract
{
    public string $traceId = 'trace-1';

    public function __construct(
        public array $rows,
        public mixed $anything,
        public object $payload,
    ) {}
}

final readonly class StockChangedEvent implements IntegrationEventContract
{
    /** @param list<StockLine> $rows */
    public function __construct(
        public string $clientId,
        public StockReason $reason,
        public \DateTimeImmutable $occurredAt,
        public array $rows,
    ) {}
}