Completed
Branch BUG-10738-inconsistency-in-ses... (860590)
by
unknown
57:39 queued 45:30
created

ConvertNoticesToEeErrors::process()   D

Complexity

Conditions 9
Paths 10

Size

Total Lines 44
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
eloc 31
nc 10
nop 1
dl 0
loc 44
rs 4.909
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\services\notices;
4
5
use EE_Error;
6
7
defined('EVENT_ESPRESSO_VERSION') || exit;
8
9
10
11
/**
12
 * Class ConvertNoticesToEeErrors
13
 * Converts notifications in a NoticesContainer into EE_Error notifications
14
 *
15
 * @package       Event Espresso
16
 * @author        Brent Christensen
17
 * @since         $VID:$
18
 */
19
class ConvertNoticesToEeErrors extends NoticeConverter
20
{
21
22
    /**
23
     * Converts Notice objects into EE_Error notifications
24
     *
25
     * @param NoticesContainerInterface $notices
26
     * @throws EE_Error
27
     */
28
    public function process(NoticesContainerInterface $notices)
29
    {
30
        $this->setNotices($notices);
31
        $notices = $this->getNotices();
32
        if ($notices->hasAttention()) {
33
            foreach ($notices->getAttention() as $notice) {
34
                EE_Error::add_attention(
35
                    $notice->message(),
36
                    $notice->file(),
37
                    $notice->func(),
38
                    $notice->line()
39
                );
40
            }
41
        }
42
        if ($notices->hasError()) {
43
            $error_string = esc_html__('The following errors occurred:', 'event_espresso');
44
            foreach ($notices->getError() as $notice) {
45
                if ($this->getThrowExceptions()) {
46
                    $error_string .= '<br />' . $notice->message();
47
                } else {
48
                    EE_Error::add_error(
49
                        $notice->message(),
50
                        $notice->file(),
51
                        $notice->func(),
52
                        $notice->line()
53
                    );
54
                }
55
            }
56
            if ($this->getThrowExceptions()) {
57
                throw new EE_Error($error_string);
58
            }
59
        }
60
        if ($notices->hasSuccess()) {
61
            foreach ($notices->getSuccess() as $notice) {
62
                EE_Error::add_success(
63
                    $notice->message(),
64
                    $notice->file(),
65
                    $notice->func(),
66
                    $notice->line()
67
                );
68
            }
69
        }
70
        $this->clearNotices();
71
    }
72
73
74
}
75