-
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathXDebugUtil.php
More file actions
83 lines (68 loc) · 1.92 KB
/
Copy pathXDebugUtil.php
File metadata and controls
83 lines (68 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*
* This file is part of the PHPBench package
*
* (c) Daniel Leech <daniel@dantleech.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
*/
namespace PhpBench\Extensions\XDebug;
use PhpBench\Executor\ExecutionContext;
use RuntimeException;
class XDebugUtil
{
public static function fromEnvironment(): XDebugUtil
{
$xdebugVersion = phpversion('xdebug');
$xdebugUseCompression = ini_get('xdebug.use_compression') === '1';
return new XDebugUtil($xdebugVersion, $xdebugUseCompression);
}
/**
* @var string|false
*/
private $xdebugVersion;
/**
* @var bool
*/
private $xdebugUseCompression;
/**
* @param string|false $xdebugVersion
*/
public function __construct($xdebugVersion, bool $xdebugUseCompression)
{
$this->xdebugVersion = $xdebugVersion;
$this->xdebugUseCompression = $xdebugUseCompression;
}
/**
* @param string $extension
*/
public function filenameFromContext(ExecutionContext $context, $extension = ''): string
{
$name = sprintf(
'%s%s%s',
$context->getClassName(),
$context->getMethodName(),
$context->getParameterSetName()
);
return md5($name) . $extension;
}
public function getCachegrindExtensionOfGeneratedFile(): string
{
$xdebugVersion = $this->discoverXdebugMajorVersion();
if ($xdebugVersion === '3' && $this->xdebugUseCompression) {
return '.cachegrind.gz';
}
return '.cachegrind';
}
public function discoverXdebugMajorVersion(): string
{
if ($this->xdebugVersion === false) {
throw new RuntimeException(
'Xdebug is not installed'
);
}
return substr($this->xdebugVersion, 0, 1);
}
}