Debugger   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 51
ccs 20
cts 20
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A debug() 0 12 2
A printMessages() 0 13 4
A clearQueue() 0 4 1
1
<?php
2
/**
3
 * @author Sergii Bondarenko, <[email protected]>
4
 */
5
namespace Behat\DebugExtension;
6
7
/**
8
 * Trait Debugger.
9
 *
10
 * @package Behat\DebugExtension
11
 */
12
trait Debugger
13
{
14
    /**
15
     * Store message for debugging.
16
     *
17
     * @param string[] $strings
18
     *   The lines to print. One item per line. Every item will be processed by sprintf().
19
     * @param string[] $placeholders
20
     *   Placeholder values for sprintf().
21
     */
22 4
    public static function debug(array $strings, array $placeholders = [])
23
    {
24
        // Initialize messages storage.
25 4
        if (!isset($_SESSION[__TRAIT__])) {
26 4
            $_SESSION[__TRAIT__] = [];
27 4
        }
28
29
        // Mark debug message.
30 4
        array_unshift($strings, '<question>DEBUG:</question>');
31
32 4
        $_SESSION[__TRAIT__][] = new Message('comment', 4, $strings, $placeholders, (bool) getenv('BEHAT_DEBUG'));
33 4
    }
34
35
    /**
36
     * Output messages to a command line.
37
     *
38
     * @param bool $clearQueue
39
     *   Is message queue should be cleared after output?
40
     */
41 8
    public static function printMessages($clearQueue = true)
42
    {
43 4
        if (!empty($_SESSION[__TRAIT__])) {
44
            /** @var Message $message */
45 4
            foreach ($_SESSION[__TRAIT__] as $message) {
46 4
                $message->output();
47 8
            }
48 4
        }
49
50 4
        if ($clearQueue) {
51 4
            static::clearQueue();
52 4
        }
53 4
    }
54
55
    /**
56
     * Clear messages queue.
57
     */
58 4
    public static function clearQueue()
59
    {
60 4
        unset($_SESSION[__TRAIT__]);
61 4
    }
62
}
63