Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
10 / 10
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractHandler
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
10 / 10
12
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 setName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLogger
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLogger
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasLogger
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLoggingParams
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getLoggingParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasLoggingParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 prepare
n/a
0 / 0
n/a
0 / 0
0
 prepareHeaderAsString
n/a
0 / 0
n/a
0 / 0
0
 prepareAsString
n/a
0 / 0
n/a
0 / 0
0
 log
n/a
0 / 0
n/a
0 / 0
0
1<?php
2/**
3 * Pop PHP Framework (http://www.popphp.org/)
4 *
5 * @link       https://github.com/popphp/popphp-framework
6 * @author     Nick Sagona, III <dev@nolainteractive.com>
7 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
8 * @license    http://www.popphp.org/license     New BSD License
9 */
10
11/**
12 * @namespace
13 */
14namespace Pop\Debug\Handler;
15
16use Pop\Log\Logger;
17
18/**
19 * Debug handler abstract class
20 *
21 * @category   Pop
22 * @package    Pop\Debug
23 * @author     Nick Sagona, III <dev@nolainteractive.com>
24 * @copyright  Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)
25 * @license    http://www.popphp.org/license     New BSD License
26 * @version    2.2.0
27 */
28abstract class AbstractHandler implements HandlerInterface
29{
30
31    /**
32     * Name of time measurement
33     * @var ?string
34     */
35    protected ?string $name = null;
36
37    /**
38     * Logger object
39     * @var ?Logger
40     */
41    protected ?Logger $logger = null;
42
43    /**
44     * Logging params
45     * @var array
46     */
47    protected array $loggingParams = [];
48
49    /**
50     * Constructor
51     *
52     * Instantiate a handler object
53     *
54     * @param ?string $name
55     * @param ?Logger $logger
56     * @param array   $loggingParams
57     */
58    public function __construct(?string $name = null, ?Logger $logger = null, array $loggingParams = [])
59    {
60        if ($name !== null) {
61            $this->setName($name);
62        }
63        if ($logger !== null) {
64            $this->setLogger($logger);
65            $this->setLoggingParams($loggingParams);
66        }
67    }
68
69    /**
70     * Set name
71     *
72     * @param  string  $name
73     * @return AbstractHandler
74     */
75    public function setName(string $name): AbstractHandler
76    {
77        $this->name = $name;
78        return $this;
79    }
80
81    /**
82     * Get name
83     *
84     * @return ?string
85     */
86    public function getName(): ?string
87    {
88        return $this->name;
89    }
90
91    /**
92     * Has name
93     *
94     * @return bool
95     */
96    public function hasName(): bool
97    {
98        return !empty($this->name);
99    }
100
101    /**
102     * Set logger
103     *
104     * @param  Logger $logger
105     * @return AbstractHandler
106     */
107    public function setLogger(Logger $logger): AbstractHandler
108    {
109        $this->logger = $logger;
110        return $this;
111    }
112
113    /**
114     * Get logger
115     *
116     * @return ?Logger
117     */
118    public function getLogger(): ?Logger
119    {
120        return $this->logger;
121    }
122
123    /**
124     * Has logger
125     *
126     * @return bool
127     */
128    public function hasLogger(): bool
129    {
130        return !empty($this->logger);
131    }
132
133    /**
134     * Set logger
135     *
136     * @param  array $loggingParams
137     * @return AbstractHandler
138     */
139    public function setLoggingParams(array $loggingParams): AbstractHandler
140    {
141        $this->loggingParams = $loggingParams;
142        return $this;
143    }
144
145    /**
146     * Get logging params
147     *
148     * @return array
149     */
150    public function getLoggingParams(): array
151    {
152        return $this->loggingParams;
153    }
154
155    /**
156     * Has logging parameters
157     *
158     * @return bool
159     */
160    public function hasLoggingParams(): bool
161    {
162        return !empty($this->loggingParams);
163    }
164
165    /**
166     * Prepare handler data for storage
167     *
168     * @return array
169     */
170    abstract public function prepare(): array;
171
172    /**
173     * Prepare header string
174     *
175     * @return string
176     */
177    abstract public function prepareHeaderAsString(): string;
178
179    /**
180     * Prepare handler data as string
181     *
182     * @return string
183     */
184    abstract public function prepareAsString(): string;
185
186    /**
187     * Trigger handle logging
188     *
189     * @return void
190     */
191    abstract public function log(): void;
192
193}