Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| RelativeFilepathLogProcessor | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * A logger that changes file paths to be relative to the project directory. |
| 4 | * |
| 5 | * @see \BrianHenryIE\Strauss\Helpers\FileSystem::getProjectRelativePath() |
| 6 | */ |
| 7 | |
| 8 | namespace BrianHenryIE\Strauss\Helpers\Log; |
| 9 | |
| 10 | use BrianHenryIE\Strauss\Helpers\FileSystem; |
| 11 | use Monolog\Processor\ProcessorInterface; |
| 12 | |
| 13 | class RelativeFilepathLogProcessor implements ProcessorInterface |
| 14 | { |
| 15 | protected FileSystem $fileSystem; |
| 16 | |
| 17 | public function __construct( |
| 18 | FileSystem $fileSystem |
| 19 | ) { |
| 20 | $this->fileSystem = $fileSystem; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Checks all context values for keys containing 'path' modifies their values to be |
| 25 | * relative to the project root. |
| 26 | * |
| 27 | */ |
| 28 | public function __invoke(array $record): array |
| 29 | { |
| 30 | $context = $record['context']; |
| 31 | |
| 32 | foreach ($context as $key => $val) { |
| 33 | if (false !== stripos($key, 'path') && is_string($val)) { |
| 34 | $record['context'][$key] = $this->fileSystem->getProjectRelativePath($val); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return $record; |
| 39 | } |
| 40 | } |