XdebugAdapter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
c 1
b 1
f 0
lcom 0
cbo 1
dl 0
loc 44
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 4
A start() 0 4 1
A isSupportXdebugVersion() 0 4 1
A isXdebugCoverageEnabled() 0 4 1
A stop() 0 7 1
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