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

ConvertNoticesToAdminNotices::process()   C

Complexity

Conditions 11
Paths 18

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 11
eloc 20
nc 18
nop 1
dl 0
loc 32
rs 5.2653
c 2
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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