XdebugAdapter::isSupportXdebugVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of cloak.
5
 *
6
 * (c) Noritaka Horio <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace cloak\analyzer\adapter;
13
14
use cloak\analyzer\AnalyzeAdapter;
15
16
17
/**
18
 * Class XdebugAdapter
19
 * @package cloak\analyzer
20
 */
21
class XdebugAdapter implements AnalyzeAdapter
22
{
23
24
    public function __construct()
25
    {
26
        if (!extension_loaded('xdebug')) {
27
            throw new AdapterNotAvailableException('This adapter requires Xdebug');
28
        }
29
30
        if ($this->isSupportXdebugVersion() && $this->isXdebugCoverageEnabled()) {
31
            throw new AdapterNotAvailableException('xdebug.coverage_enable=On has to be set in php.ini');
32
        }
33
    }
34
35
    public function start()
36
    {
37
        xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
38
    }
39
40
    public function stop()
41
    {
42
        $result = xdebug_get_code_coverage();
43
        xdebug_stop_code_coverage();
44
45
        return $result;
46
    }
47
48
    /**
49
     * @return boolean
50
     */
51
    private function isSupportXdebugVersion()
52
    {
53
        return version_compare(phpversion('xdebug'), '2.2.0-dev', '>=');
54
    }
55
56
    /**
57
     * @return boolean
58
     */
59
    private function isXdebugCoverageEnabled()
60
    {
61
        return !ini_get('xdebug.coverage_enable');
62
    }
63
64
}
65