-
Notifications
You must be signed in to change notification settings - Fork 12
/
Failure.php
61 lines (55 loc) · 1.58 KB
/
Failure.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace Df\Qa;
use Df\Qa\Trace\Formatter;
/**
* @see \Df\Qa\Failure\Error
* @see \Df\Qa\Failure\Exception
*/
abstract class Failure {
/**
* @used-by self::report()
* @see \Df\Qa\Failure\Error::main()
* @see \Df\Qa\Failure\Exception::main()
*/
abstract protected function main():string;
/**
* @abstract
* @used-by self::postface()
* @see \Df\Qa\Failure\Error::trace()
* @see \Df\Qa\Failure\Exception::trace()
* @return array(array(string => string|int))
*/
abstract protected function trace():array;
/**
* @used-by df_log_l()
* @used-by \Df\Qa\Failure\Error::log()
*/
final function report():string {return dfc($this, function() {return $this->sections(
$this->preface(), $this->main(), $this->postface()
);});}
/**
* @used-by self::report()
* @used-by \Df\Qa\Failure\Exception::postface()
* @see \Df\Qa\Failure\Exception::postface()
*/
protected function postface():string {return Formatter::p(new Trace(array_slice($this->trace(), $this->stackLevel())));}
/**
* @used-by self::report()
* @see \Df\Qa\Failure\Error::preface()
*/
protected function preface():string {return '';}
/**
* @used-by self::report()
* @used-by \Df\Qa\Failure\Exception::postface()
*/
final protected function sections(string ...$a):string {
static $s; $s = $s ? $s : "\n" . str_repeat('*', 36) . "\n"; /** @var string $s */
return implode($s, array_filter(df_trim($a)));
}
/**
* @used-by self::postface()
* @see \Df\Qa\Failure\Exception::stackLevel()
* @see \Df\Qa\Failure\Error::stackLevel()
*/
protected function stackLevel():int {return 0;}
}