shopware-blog /
shopware-bugsnag
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | namespace ShopwareBlogBugsnag\Source; |
||
| 4 | |||
| 5 | use Bugsnag\Client; |
||
| 6 | use Shopware\Components\Plugin\CachedConfigReader; |
||
|
0 ignored issues
–
show
|
|||
| 7 | |||
| 8 | class BugsnagClient |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var CachedConfigReader |
||
| 12 | */ |
||
| 13 | private $configReader; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var Client |
||
| 17 | */ |
||
| 18 | private $bugsnagClient; |
||
| 19 | |||
| 20 | public function __construct(CachedConfigReader $configReader) |
||
| 21 | { |
||
| 22 | $this->configReader = $configReader; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function getInstance(): Client |
||
| 26 | { |
||
| 27 | if (!$this->bugsnagClient) { |
||
| 28 | $config = $this->getConfig(); |
||
| 29 | if (empty($config['apiKey'])) { |
||
| 30 | $this->bugsnagClient = Client::make(); |
||
| 31 | } else { |
||
| 32 | $this->bugsnagClient = Client::make($config['apiKey']); |
||
| 33 | } |
||
| 34 | |||
| 35 | if ($config['anonymizeIp']) { |
||
| 36 | $this->bugsnagClient->registerCallback( |
||
| 37 | function ($report) { |
||
| 38 | // replaces the automatically collected IP |
||
| 39 | $report->setUser(['id' => null]); |
||
| 40 | |||
| 41 | // replaces the automatically collected IP |
||
| 42 | $report->addMetaData(['request' => ['clientIp' => null],]); |
||
| 43 | } |
||
| 44 | ); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | return $this->bugsnagClient; |
||
| 49 | } |
||
| 50 | |||
| 51 | public function registerHandler() |
||
| 52 | { |
||
| 53 | $config = $this->getConfig(); |
||
| 54 | $bugsnag = $this->getInstance(); |
||
| 55 | |||
| 56 | $bugsnagHandler = new \Bugsnag\Handler($bugsnag); |
||
| 57 | |||
| 58 | if ($config['exceptionHandler']) { |
||
| 59 | $bugsnagHandler->registerExceptionHandler(false); |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($config['errorHandler']) { |
||
| 63 | $bugsnagHandler->registerErrorHandler(false); |
||
| 64 | } |
||
| 65 | |||
| 66 | // restore default error handler |
||
| 67 | restore_error_handler(); |
||
| 68 | restore_exception_handler(); |
||
| 69 | } |
||
| 70 | |||
| 71 | private function getConfig(): array |
||
| 72 | { |
||
| 73 | return $this->configReader->getByPluginName('ShopwareBlogBugsnag'); |
||
| 74 | } |
||
| 75 | } |
||
| 76 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths