PHP code example of struggle-for-php / sfp-phpstan-psr-log

1. Go to this page and download the library: Download struggle-for-php/sfp-phpstan-psr-log 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/ */

    

struggle-for-php / sfp-phpstan-psr-log example snippets


// bad
$logger->info('message are {foo-hyphen}');

// bad
$logger->info('message are {{foo}}');

// bad
$logger->info('message has {nonContext} .');

// bad
$logger->info('user {user_id} gets an error {error} .', ['user_id' => $user_id]);

// bad
[123 => 'foo']`, `['' => 'bar']`, `['baz']


/** @var \Psr\Log\LoggerInterface $logger */
try {
    //
} catch (LogicException $exception) {
    $logger->warning("foo");
}

} catch (\Exception $e) {
  $logger->info('more info'); // allow
  $logger->warning($e->getMessage(), ['exception' => $e]);
}

// bad
$logger->info(sprintf('Message contains %s variable', $var));
neon
 - vendor/struggle-for-php/sfp-phpstan-psr-log/extension.neon
    - vendor/struggle-for-php/sfp-phpstan-psr-log/rules.neon