Completed
Push — master ( 01a3d7...cd5a13 )
by Adam
03:05
created

OnRequestHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 18.18%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 34
ccs 2
cts 11
cp 0.1818
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 22 4
1
<?php
2
/**
3
 * OnRequestHandler.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec https://www.ipublikuj.eu
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 request event
24
 *
25
 * @package        iPublikuj:NewRelic!
26
 * @subpackage     Events
27
 *
28
 * @author         Adam Kadlec <[email protected]>
29
 */
30 1
final class OnRequestHandler
31
{
32
	/**
33
	 * Implement nette smart magic
34
	 */
35 1
	use Nette\SmartObject;
36
37
	/**
38
	 * @param Application\Application $application
39
	 * @param Application\Request $request
40
	 */
41
	public function __invoke(Application\Application $application, Application\Request $request) : void
42
	{
43
		// Check if new relict extension is loaded
44
		if (!extension_loaded('newrelic')) {
45
			return;
46
		}
47
48
		if (PHP_SAPI === 'cli') {
49
			// Save in human readable format
50
			newrelic_name_transaction('$ ' . basename($_SERVER['argv'][0]) . ' ' . implode(' ', array_slice($_SERVER['argv'], 1)));
51
52
			// Mark process as background job
53
			newrelic_background_job(TRUE);
54
55
			return;
56
		}
57
58
		// Get request info for naming exception
59
		$params = $request->getParameters();
60
61
		newrelic_name_transaction($request->getPresenterName() . (isset($params['action']) ? ':' . $params['action'] : ''));
62
	}
63
}
64