1414use Fbn \Debug \Logger ;
1515use Psr \Log \LoggerInterface ;
1616
17- /**
18- * Main class.
19- */
2017class Debug
2118{
2219 /**
@@ -33,8 +30,6 @@ class Debug
3330 private $ defaultFlags ;
3431
3532 /**
36- * The logger instance.
37- *
3833 * @var LoggerInterface
3934 */
4035 private $ logger ;
@@ -47,23 +42,19 @@ class Debug
4742 private static $ instance ;
4843
4944 /**
50- * Constructor.
51- *
52- * @param int $defaultFlags Default flags for tweaking the output.
53- * @param LoggerInterface $logger The logger instance.
54- *
55- * @return void
45+ * @param int $defaultFlags Default flags for tweaking the output.
46+ * @param LoggerInterface $logger
5647 */
57- final private function __construct (int $ defaultFlags , LoggerInterface $ logger )
58- {
48+ final private function __construct (
49+ int $ defaultFlags ,
50+ LoggerInterface $ logger
51+ ) {
5952 $ this ->defaultFlags = $ defaultFlags ;
6053 $ this ->logger = $ logger ;
6154 }
6255
6356 /**
6457 * Get singleton instance.
65- *
66- * @return Debug
6758 */
6859 public static function getInstance (): Debug
6960 {
@@ -87,22 +78,28 @@ public static function getInstance(): Debug
8778 * If `logger` is specified, `log_file` will be ignored. If neither is present,
8879 * nothing will be logged.
8980 *
90- * @param array $settings Settings.
91- *
92- * @return void
81+ * @param array<string,mixed> $settings
9382 */
94- public static function init (array $ settings = [])
83+ public static function init (array $ settings = []): void
9584 {
9685 $ defaultFlags = 0 ;
97-
98- if (isset ($ settings ['use_vardump ' ]) && $ settings ['use_vardump ' ]) {
86+ if (
87+ isset ($ settings ['use_vardump ' ])
88+ && $ settings ['use_vardump ' ] === true
89+ ) {
9990 $ defaultFlags |= self ::USE_VARDUMP ;
10091 }
101- if (isset ($ settings ['use_htmlentities ' ]) && $ settings ['use_htmlentities ' ]) {
92+ if (
93+ isset ($ settings ['use_htmlentities ' ])
94+ && $ settings ['use_htmlentities ' ] === true
95+ ) {
10296 $ defaultFlags |= self ::USE_HTMLENTITIES ;
10397 }
10498
105- if (isset ($ settings ['logger ' ]) && $ settings ['logger ' ] instanceof LoggerInterface) {
99+ if (
100+ isset ($ settings ['logger ' ])
101+ && $ settings ['logger ' ] instanceof LoggerInterface
102+ ) {
106103 $ logger = $ settings ['logger ' ];
107104 } else {
108105 if (isset ($ settings ['log_file ' ])) {
@@ -117,14 +114,12 @@ public static function init(array $settings = [])
117114 }
118115
119116 /**
120- * Print debug value
117+ * Print debug value.
121118 *
122- * @param mixed $var The variable to analyse.
123- * @param int|null $flags Flags for tweaking the output.
124- *
125- * @return void
119+ * @param mixed $var The variable to analyse.
120+ * @param int|null $flags Flags for tweaking the output.
126121 */
127- public function printValue ($ var , int $ flags = null )
122+ public function printValue ($ var , ? int $ flags = null ): void
128123 {
129124 if ($ flags === null ) {
130125 $ flags = $ this ->defaultFlags ;
@@ -140,12 +135,11 @@ public function printValue($var, int $flags = null)
140135 /**
141136 * Return debug value.
142137 *
143- * @param mixed $var The variable to analyse.
144- * @param int|null $flags Flags for tweaking the output.
145- *
138+ * @param mixed $var The variable to analyse.
139+ * @param int|null $flags Flags for tweaking the output.
146140 * @return mixed
147141 */
148- public function debugValue ($ var , int $ flags = null )
142+ public function debugValue ($ var , ? int $ flags = null )
149143 {
150144 if ($ flags === null ) {
151145 $ flags = $ this ->defaultFlags ;
@@ -162,6 +156,12 @@ public function debugValue($var, int $flags = null)
162156 $ output = ob_get_contents ();
163157 ob_end_clean ();
164158
159+ if ($ output === false ) {
160+ throw new \UnexpectedValueException (
161+ 'Unable to get debug value of variable '
162+ );
163+ }
164+
165165 if (($ flags & self ::USE_HTMLENTITIES ) === self ::USE_HTMLENTITIES ) {
166166 $ output = htmlentities ($ output , ENT_NOQUOTES );
167167 }
@@ -172,20 +172,16 @@ public function debugValue($var, int $flags = null)
172172 /**
173173 * Log debug value.
174174 *
175- * @param mixed $var The variable to analyse.
176- * @param int|null $flags Flags for tweaking the output.
177- *
178- * @return mixed
175+ * @param mixed $var The variable to analyse.
176+ * @param int|null $flags Flags for tweaking the output.
179177 */
180- public function logValue ($ var , int $ flags = null )
178+ public function logValue ($ var , ? int $ flags = null ): void
181179 {
182180 $ this ->logger ->debug (static ::debugValue ($ var , $ flags ));
183181 }
184182
185183 /**
186184 * Check whether we are in a CLI environment.
187- *
188- * @return bool
189185 */
190186 protected function isCli (): bool
191187 {
0 commit comments