Completed
Push — master ( a77eea...3c57b0 )
by Carl
02:25
created

FlashMsg::info()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace helikopterspark\FlashMsg;
4
5
/**
6
* Class for displaying flash messages
7
*/
8
class FlashMsg implements \Anax\DI\IInjectionAware {
0 ignored issues
show
Coding Style introduced by
As per PSR2, the opening brace for this class should be on a new line.
Loading history...
9
10
	use \Anax\DI\TInjectable;
11
12
	/**
13
	 * Initialize the controller.
14
	 *
15
	 * @return void
16
	 */
17
	public function initialize() {
18
		if (!$this->session->has('flashmsgs')) {
0 ignored issues
show
Documentation introduced by
The property session does not exist on object<helikopterspark\FlashMsg\FlashMsg>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
19
			$this->session->set('flashmsgs', array());
0 ignored issues
show
Documentation introduced by
The property session does not exist on object<helikopterspark\FlashMsg\FlashMsg>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
20
		}
21
	}
22
23
	/**
24
	 * Add message to session array
25
	 *
26
	 * @param $type string with message type
27
	 * @param $message string with message text
28
	 *
29
	 * @return void
30
	 */
31 9
	public function setMessage($type, $message) {
32 9
		$temp = $this->session->get('flashmsgs');
0 ignored issues
show
Documentation introduced by
The property session does not exist on object<helikopterspark\FlashMsg\FlashMsg>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
33 9
		$temp[] = array('type' => $type, 'content' => $message);
34 9
		$this->session->set('flashmsgs', $temp);
0 ignored issues
show
Documentation introduced by
The property session does not exist on object<helikopterspark\FlashMsg\FlashMsg>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
35 9
	}
36
37
	/**
38
	 * Add alert message to session array
39
	 *
40
	 * @param $message string with message text
41
	 *
42
	 * @return void
43
	 */
44 1
	public function alert($message) {
45 1
		$this->setMessage('alert', $message);
46 1
	}
47
48
	/**
49
	 * Add error message to session array
50
	 *
51
	 * @param $message string with message text
52
	 *
53
	 * @return void
54
	 */
55 1
	public function error($message) {
56 1
		$this->setMessage('error', $message);
57 1
	}
58
59
	/**
60
	 * Add info message to session array
61
	 *
62
	 * @param $message string with message text
63
	 *
64
	 * @return void
65
	 */
66 1
	public function info($message) {
67 1
		$this->setMessage('info', $message);
68 1
	}
69
70
	/**
71
	 * Add notice message to session array
72
	 *
73
	 * @param $message string with message text
74
	 *
75
	 * @return void
76
	 */
77 3
	public function notice($message) {
78 3
		$this->setMessage('notice', $message);
79 3
	}
80
81
	/**
82
	 * Add success message to session array
83
	 *
84
	 * @param $message string with message text
85
	 *
86
	 * @return void
87
	 */
88 3
	public function success($message) {
89 3
		$this->setMessage('success', $message);
90 3
	}
91
92
	/**
93
	 * Add warning message to session array
94
	 *
95
	 * @param $message string with message text
96
	 *
97
	 * @return void
98
	 */
99 3
	public function warning($message) {
100 3
		$this->setMessage('warning', $message);
101 3
	}
102
103
	/**
104
	 * Build HTML of messages in session array
105
	 *
106
	 * @return $output HTML string with messages
0 ignored issues
show
Documentation introduced by
The doc-type $output could not be parsed: Unknown type name "$output" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
107
	 */
108 1
	public function outputMsgs() {
109 1
		$messages = $this->session->get('flashmsgs');
0 ignored issues
show
Documentation introduced by
The property session does not exist on object<helikopterspark\FlashMsg\FlashMsg>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
110 1
		$output = null;
111
112 1
		if ($messages) {
113 1
			foreach ($messages as $key => $message) {
114 1
				$output .= '<div class="' . $message['type'] . '"><p>' . $message['content'] . '</p></div>';
115 1
			}
116 1
		}
117
118 1
		return $output;
119
	}
120
121
	/**
122
	 * Clear session message array
123
	 *
124
	 * @return void
125
	 */
126 1
	public function clearMessages() {
127 1
		$this->session->set('flashmsgs', []);
0 ignored issues
show
Documentation introduced by
The property session does not exist on object<helikopterspark\FlashMsg\FlashMsg>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
128 1
	}
129
}
130