Completed
Pull Request — staging (#840)
by
unknown
19:58
created

Debugger   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 3 1
A register_log() 0 5 2
A get_log() 0 3 1
A pretty_log() 0 4 1
A pretty_debug() 0 7 1
1
<?php
2
3
namespace YIKES\EasyForms\Util;
4
5
use YIKES\EasyForms\Service;
6
7
class Debugger implements Service {
8
9
    const LOG_NAME = 'freddie_log';
10
11
    public function register() {
12
        $this->register_log();
13
    }
14
15
    public function register_log() :void {
16
        if ( ! get_option( self::LOG_NAME ) ) {
17
            add_option( self::LOG_NAME, [] );
18
        }
19
    }
20
21
    public function get_log() {
22
        return get_option( self::LOG_NAME, [] );
23
    }
24
25
   public function pretty_log() {
26
       $log = $this->get_log();
27
       return $this->pretty_debug( 'Pretty Log', $log );
28
   }
29
30
    public function pretty_debug( $label, $value ) {
31
            $res = "<strong>{$label}</strong>";
32
            $res .= "<pre>";
33
            $res .= esc_html( json_encode( $value, JSON_PRETTY_PRINT ) );
34
            $res .= "</pre>";
35
            echo $res;
36
    }
37
}