Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UserProcessor | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Logger; |
| 4 | |
| 5 | use Monolog\Attribute\AsMonologProcessor; |
| 6 | use Monolog\LogRecord; |
| 7 | use Symfony\Bundle\SecurityBundle\Security; |
| 8 | use Symfony\Component\HttpFoundation\RequestStack; |
| 9 | |
| 10 | /** |
| 11 | * Add login name in logger. |
| 12 | */ |
| 13 | #[AsMonologProcessor] |
| 14 | class UserProcessor |
| 15 | { |
| 16 | private Security $security; |
| 17 | private RequestStack $requestStack; |
| 18 | |
| 19 | public function __construct(Security $security, RequestStack $requestStack) |
| 20 | { |
| 21 | $this->security = $security; |
| 22 | $this->requestStack = $requestStack; |
| 23 | } |
| 24 | |
| 25 | // this method is called for each log record; optimize it to not hurt performance |
| 26 | public function __invoke(LogRecord $record): LogRecord |
| 27 | { |
| 28 | $user = $this->security->getUser(); |
| 29 | $record->extra['user'] = $user?->getUserIdentifier(); |
| 30 | $record->extra['url'] = $this->requestStack->getCurrentRequest()?->getRequestUri(); |
| 31 | |
| 32 | return $record; |
| 33 | } |
| 34 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 19 | public function __construct(Security $security, RequestStack $requestStack) |
| 20 | { |
| 21 | $this->security = $security; |
| 22 | $this->requestStack = $requestStack; |
| 23 | } |
| 26 | public function __invoke(LogRecord $record): LogRecord |
| 27 | { |
| 28 | $user = $this->security->getUser(); |
| 29 | $record->extra['user'] = $user?->getUserIdentifier(); |
| 30 | $record->extra['url'] = $this->requestStack->getCurrentRequest()?->getRequestUri(); |
| 31 | |
| 32 | return $record; |
| 33 | } |