Passed
Push — develop ( bdf49e...53bd5d )
by Paul
12:20
created

Development   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 79
rs 10
c 6
b 0
f 0
wmc 20

11 Methods

Rating   Name   Duplication   Size   Complexity  
A capture() 0 5 1
A __construct() 0 3 1
A isProduction() 0 3 1
A isDev() 0 3 3
A debug() 0 3 1
A className() 0 3 2
A printFiltersFor() 0 7 3
A templatePaths() 0 3 1
A storeTemplatePath() 0 4 2
A printF() 0 14 4
A printTemplatePaths() 0 3 1
1
<?php
2
3
namespace GeminiLabs\Castor\Helpers;
4
5
class Development
6
{
7
    public $templatePaths = [];
8
9
    protected $utility;
10
11
    public function __construct(Utility $utility)
12
    {
13
        $this->utility = $utility;
14
    }
15
16
    public function capture()
17
    {
18
        ob_start();
19
        call_user_func_array([$this, 'printF'], func_get_args());
20
        return ob_get_clean();
21
    }
22
23
    public function className($override = 'dev')
24
    {
25
        return $this->isDev() ? $override : '';
26
    }
27
28
    public function debug()
29
    {
30
        call_user_func_array([$this, 'printF'], func_get_args());
31
    }
32
33
    public function isDev()
34
    {
35
        return defined('DEV') && (bool) DEV && WP_ENV == 'development';
36
    }
37
38
    public function isProduction()
39
    {
40
        return WP_ENV == 'production';
41
    }
42
43
    public function printFiltersFor($hook = '')
44
    {
45
        global $wp_filter;
46
        if (empty($hook) || !isset($wp_filter[$hook])) {
47
            return;
48
        }
49
        $this->printF($wp_filter[$hook]);
50
    }
51
52
    public function printTemplatePaths()
53
    {
54
        $this->printF(implode("\n", $this->templatePaths()));
55
    }
56
57
    public function storeTemplatePath($template)
58
    {
59
        if (is_string($template)) {
60
            $this->templatePaths[] = $this->utility->trimLeft($template, trailingslashit(WP_CONTENT_DIR));
61
        }
62
    }
63
64
    protected function printF()
65
    {
66
        $args = func_num_args();
67
68
        if (1 == $args) {
69
            printf('<div class="print__r"><pre>%s</pre></div>',
70
                htmlspecialchars(print_r(func_get_arg(0), true), ENT_QUOTES, 'UTF-8')
0 ignored issues
show
Bug introduced by
It seems like print_r(func_get_arg(0), true) can also be of type true; however, parameter $string of htmlspecialchars() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

70
                htmlspecialchars(/** @scrutinizer ignore-type */ print_r(func_get_arg(0), true), ENT_QUOTES, 'UTF-8')
Loading history...
71
            );
72
        } elseif ($args > 1) {
73
            echo '<div class="print__r_group">';
74
            foreach (func_get_args() as $value) {
75
                $this->printF($value);
76
            }
77
            echo '</div>';
78
        }
79
    }
80
81
    public function templatePaths()
82
    {
83
        return $this->templatePaths;
84
    }
85
}
86