Completed
Branch BUG-10738-inconsistency-in-ses... (a1eed8)
by
unknown
24:27 queued 12:29
created

ConvertNoticesToAdminNotices   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 43
rs 10
c 2
b 0
f 0
wmc 11
lcom 0
cbo 4

1 Method

Rating   Name   Duplication   Size   Complexity  
C process() 0 32 11
1
<?php
2
3
namespace EventEspresso\core\services\notices;
4
5
use DomainException;
6
7
defined('EVENT_ESPRESSO_VERSION') || exit;
8
9
10
11
/**
12
 * Class ConvertNoticesToAdminNotices
13
 * Converts notifications in a NoticesContainer into AdminNotice notifications
14
 *
15
 * @package EventEspresso\core\services\notices
16
 * @author  Brent Christensen
17
 * @since   $VID:$
18
 */
19
class ConvertNoticesToAdminNotices extends NoticeConverter
20
{
21
22
    /**
23
     * Converts Notice objects into AdminNotice notifications
24
     *
25
     * @param NoticesContainerInterface $notices
26
     * @throws DomainException
27
     */
28
    public function process(NoticesContainerInterface $notices)
29
    {
30
        if ($notices->hasAttention()) {
31
            foreach ($notices->getAttention() as $notice) {
32
                new AdminNotice($notice);
33
            }
34
        }
35
        if ($notices->hasError()) {
36
            $error_string = esc_html__('The following errors occurred:', 'event_espresso');
37
            foreach ($notices->getError() as $notice) {
38
                if ($this->getThrowExceptions()) {
39
                    $error_string .= '<br />' . $notice->message();
40
                } else {
41
                    new AdminNotice($notice);
42
                }
43
            }
44
            if ($this->getThrowExceptions()) {
45
                throw new DomainException($error_string);
46
            }
47
        }
48
        if ($notices->hasSuccess()) {
49
            foreach ($notices->getSuccess() as $notice) {
50
                new AdminNotice($notice);
51
            }
52
        }
53
        if ($notices->hasInformation()) {
54
            foreach ($notices->getInformation() as $notice) {
55
                new AdminNotice($notice);
56
            }
57
        }
58
        $this->clearNotices();
59
    }
60
61
}
62
// Location: ConvertNoticesToAdminNotices.php
63