Completed
Push — master ( f86636...85c2f1 )
by Carl
02:11
created

FlashMsg::error()   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 {
9
10
	use \Anax\DI\TInjectable;
11
12
	/**
13
	 * Add message to session array
14
	 *
15
	 * @param $type string with message type
16
	 * @param $message string with message text
17
	 *
18
	 * @return void
19
	 */
20 9
	public function setMessage($type, $message) {
21 9
		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...
22 9
			$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...
23 9
		}
24 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...
25 9
		$temp[] = array('type' => $type, 'content' => $message);
26 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...
27 9
	}
28
29
	/**
30
	 * Add alert message to session array
31
	 *
32
	 * @param $message string with message text
33
	 *
34
	 * @return void
35
	 */
36 3
	public function alert($message) {
37 3
		$this->setMessage('alert', $message);
38 3
	}
39
40
	/**
41
	 * Add error message to session array
42
	 *
43
	 * @param $message string with message text
44
	 *
45
	 * @return void
46
	 */
47 3
	public function error($message) {
48 3
		$this->setMessage('error', $message);
49 3
	}
50
51
	/**
52
	 * Add info message to session array
53
	 *
54
	 * @param $message string with message text
55
	 *
56
	 * @return void
57
	 */
58 3
	public function info($message) {
59 3
		$this->setMessage('info', $message);
60 3
	}
61
62
	/**
63
	 * Add notice message to session array
64
	 *
65
	 * @param $message string with message text
66
	 *
67
	 * @return void
68
	 */
69 3
	public function notice($message) {
70 3
		$this->setMessage('notice', $message);
71 3
	}
72
73
	/**
74
	 * Add success message to session array
75
	 *
76
	 * @param $message string with message text
77
	 *
78
	 * @return void
79
	 */
80 3
	public function success($message) {
81 3
		$this->setMessage('success', $message);
82 3
	}
83
84
	/**
85
	 * Add warning message to session array
86
	 *
87
	 * @param $message string with message text
88
	 *
89
	 * @return void
90
	 */
91 3
	public function warning($message) {
92 3
		$this->setMessage('warning', $message);
93 3
	}
94
95
	/**
96
	 * Build HTML of messages in session array
97
	 *
98
	 * @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...
99
	 */
100 1
	public function outputMsgs() {
101 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...
102 1
		$output = null;
103
104 1
		if ($messages) {
105 1
			foreach ($messages as $key => $message) {
106 1
				$output .= '<div class="' . $message['type'] . '"><p>' . $message['content'] . '</p></div>';
107 1
			}
108 1
		}
109
110 1
		return $output;
111
	}
112
113
	/**
114
	 * Clear session message array
115
	 *
116
	 * @return void
117
	 */
118 1
	public function clearMessages() {
119 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...
120 1
	}
121
}
122