OnErrorHandler::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 14
ccs 0
cts 6
cp 0
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 12
1
<?php
2
/**
3
 * OnErrorHandler.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:NewRelic!
9
 * @subpackage     Events
10
 * @since          1.0.0
11
 *
12
 * @date           25.05.14
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\NewRelic\Events;
18
19
use Nette;
20
use Nette\Application;
21
22
/**
23
 * On application error event
24
 *
25
 * @package        iPublikuj:NewRelic!
26
 * @subpackage     Events
27
 *
28
 * @author         Adam Kadlec <[email protected]>
29
 */
30 1
final class OnErrorHandler
31
{
32
	/**
33
	 * Implement nette smart magic
34
	 */
35 1
	use Nette\SmartObject;
36
37
	/**
38
	 * @param Application\Application $app
39
	 * @param \Exception|\TypeError $ex
40
	 *
41
	 * @return void
42
	 */
43
	public function __invoke(Application\Application $app, $ex) : void
44
	{
45
		// Check if new relict extension is loaded
46
		if (!extension_loaded('newrelic')) {
47
			return;
48
		}
49
50
		if ($ex instanceof Application\BadRequestException) {
0 ignored issues
show
Bug introduced by
The class Nette\Application\BadRequestException does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
51
			return; // Skip
52
		}
53
54
		// Log only errors with code 500
55
		newrelic_notice_error($ex->getMessage(), $ex);
56
	}
57
}
58