Message::generic()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
1
<?php
2
/**
3
 * This field lets you put an arbitrary message into your backend.
4
 *
5
 * <code>
6
 * Message::generic(
7
 *    $content = 'your message'
8
 * )
9
 * </code>
10
 *
11
 * or with the optional name parameter
12
 *
13
 * <code>
14
 * Message::generic(
15
 *    $content = 'your message',
16
 *    $CSSClass = null,
17
 *    $name = 'fieldName'
18
 * )
19
 * </code>
20
 */
21
class Message
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
22
{
23
    /**
24
     * Creates a error message.
25
     *
26
     * @param string $message
0 ignored issues
show
Documentation introduced by
Should the type for parameter $message not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
27
     * @param string $CSSClass (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $CSSClass not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
28
     * @param string $name (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
29
     *
30
     * @return MessageBoxField
31
     */
32
    public static function generic($message = null, $CSSClass = null, $name = null)
33
    {
34
        // ensure that we are having a name as well as keeping it consistent with the original behaviour
35
        if ($name == null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $name of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison === instead.
Loading history...
36
            $name = md5($message);
37
        }
38
39
        return MessageBoxField::create(
40
            $name,
41
            $message
42
        )->addCSSClass($CSSClass);
43
    }
44
45
    /**
46
     * Creates a error message.
47
     *
48
     * @param string $message
0 ignored issues
show
Documentation introduced by
Should the type for parameter $message not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
49
     * @param string $name (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
50
     *
51
     * @return MessageBoxField
52
     */
53
    public static function error($message = null, $name = null)
54
    {
55
        return self::generic($message, ErrorMessage::$CSSClass, $name);
56
    }
57
58
    /**
59
     * Creates a warning message.
60
     *
61
     * @param string $message
0 ignored issues
show
Documentation introduced by
Should the type for parameter $message not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
62
     * @param string $name (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
63
     *
64
     * @return MessageBoxField
65
     */
66
    public static function warning($message = null, $name = null)
67
    {
68
        return self::generic($message, WarningMessage::$CSSClass, $name);
69
    }
70
71
    /**
72
     * Creates a success message.
73
     *
74
     * @param string $message
0 ignored issues
show
Documentation introduced by
Should the type for parameter $message not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
75
     * @param string $name (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
76
     *
77
     * @return MessageBoxField
78
     */
79
    public static function success($message = null, $name = null)
80
    {
81
        return self::generic($message, SuccessMessage::$CSSClass, $name);
82
    }
83
84
    /**
85
     * Creates a notice message.
86
     *
87
     * @param string $message
0 ignored issues
show
Documentation introduced by
Should the type for parameter $message not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
88
     * @param string $name (optional)
0 ignored issues
show
Documentation introduced by
Should the type for parameter $name not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
89
     *
90
     * @return MessageBoxField
91
     */
92
    public static function notice($message = null, $name = null)
93
    {
94
        return self::generic($message, NoticeMessage::$CSSClass, $name);
95
    }
96
}
97