Formatter::formatUsername()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
use Noair\Event;
4
5
/**
6
 * A default Noair Observer
7
 *
8
 * This is the default Noair Observer, which other plugins/listeners
9
 * will override its functionality
10
 *
11
 * @author      Garrett Whitehorn
12
 * @author      David Tkachuk
13
 * @package     Noair
14
 * @subpackage  NoairExample
15
 * @version     1.0
16
 */
17
class Formatter extends Noair\Observer
18
{
19
    public function subscribe() {
20
        // This is just here for an example of explicitly-defined handlers
21
        $this->handlers = [
22
            'formatUsername' => [[$this, 'formatUsername']],
23
            'formatGroup'    => [[$this, 'formatGroup']],
24
            'formatDate'     => [[$this, 'formatDate']],
25
            'formatMessage'  => [[$this, 'formatMessage']],
26
        ];
27
28
        return parent::subscribe();
29
    }
30
31
    public function formatUsername(Event $event) {
32
        return $event->data;
33
    }
34
35
    public function formatGroup(Event $event) {
36
        return $event->data;
37
    }
38
39
    public function formatMessage(Event $event) {
40
        return nl2br($event->data);
41
    }
42
43
    public function formatDate(Event $event) {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
44
        // return date('F j, Y h:i:s A', $event->data);
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        return '';
46
    }
47
48
    public function onCreatePost(Event $event) {
49
        $result = '<div style="padding: 9px 16px;border:1px solid #EEE;margin-bottom:16px;">'
50
                 .'<strong>Posted by</strong> '
51
                 .$this->mediator->publish(new Event('formatUsername', $event->data['username'], $this))
52
                 .' ('
53
                 .$this->mediator->publish(new Event('formatGroup', $event->data['group'], $this))
54
                 .')<br /><strong>Posted Date</strong> '
55
                 .$this->mediator->publish(new Event('formatDate', $event->data['date'], $this))
56
                 .'<br />'
57
                 .$this->mediator->publish(new Event('formatMessage', $event->data['message'], $this))
58
                 .'</div>';
59
        return $result;
60
    }
61
}
62