PHP code example of edhrendal-sf-tools / phpstan-edhrendal

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

    

edhrendal-sf-tools / phpstan-edhrendal example snippets


// ❌ reported
$this->userRepository->findBy(['active' => true]);
$this->userRepository->findByEmail($email);

// ✅ ok
$this->userRepository->findActive();
$this->userRepository->findOneByEmail($email); // if declared in the class

// config/phpstan/excluded_controllers.php

return [
    App\Controller\Legacy\SomeLegacyController::class,
];

// ❌ reported — missing HTTP method in name, no __invoke, public non-magic method
class UserController
{
    public function index(): Response { … }
    public function show(int $id): Response { … }
}

// ✅ ok
class UserGetController
{
    public function __invoke(int $id): Response { … }
}

// ❌ reported — wrong order
str_replace(subject: $html, search: '<br>', replace: "\n");

// ❌ reported — positional arguments (forceNamed: true)
str_replace('<br>', "\n", $html);

// ✅ ok
str_replace(search: '<br>', replace: "\n", subject: $html);

// ✅ ok — single 
neon
# phpstan.neon
ndal-sf-tools/phpstan-edhrendal/rules/php/named-arguments.neon
neon
# phpstan.neon
ndal-sf-tools/phpstan-edhrendal/rules/php/named-arguments.neon

parameters:
    edhrendal:
        php:
            namedArguments:
                forceNamed: true          # default: true
                forceSingleRequired: false # default: false