Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
80.00% covered (warning)
80.00%
4 / 5
CRAP
0.00% covered (danger)
0.00%
0 / 1
error_collector
92.31% covered (success)
92.31%
12 / 13
80.00% covered (warning)
80.00%
4 / 5
8.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 install
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
 uninstall
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 error_handler
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 format_errors
87.50% covered (warning)
87.50%
7 / 8
0.00% covered (danger)
0.00%
0 / 1
3.02
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14namespace phpbb;
15
16class error_collector
17{
18    var $errors;
19    var $error_types;
20
21    /**
22     * Constructor.
23     *
24     * The variable $error_types may be set to a mask of PHP error types that
25     * the collector should keep, e.g. `E_ALL`. If unset, the current value of
26     * the error_reporting() function will be used to determine which errors
27     * the collector will keep.
28     *
29     * @see https://tracker.phpbb.com/browse/PHPBB3-13306
30     * @param int|null $error_types
31     */
32    function __construct($error_types = null)
33    {
34        $this->errors = array();
35        $this->error_types = $error_types;
36    }
37
38    function install()
39    {
40        set_error_handler(array(&$this, 'error_handler'), ($this->error_types !== null) ? $this->error_types : error_reporting());
41    }
42
43    function uninstall()
44    {
45        restore_error_handler();
46    }
47
48    function error_handler($errno, $msg_text, $errfile, $errline)
49    {
50        $this->errors[] = array($errno, $msg_text, $errfile, $errline);
51    }
52
53    function format_errors()
54    {
55        $text = '';
56        foreach ($this->errors as $error)
57        {
58            if (!empty($text))
59            {
60                $text .= "<br />\n";
61            }
62
63            list($errno, $msg_text, $errfile, $errline) = $error;
64
65            // Prevent leakage of local path to phpBB install
66            $errfile = phpbb_filter_root_path($errfile);
67
68            $text .= "Errno $errno$msg_text at $errfile line $errline";
69        }
70
71        return $text;
72    }
73}