Completed
Push — master ( 692bc3...b58f0a )
by mw
333:43 queued 298:51
created

DeprecationNoticeTaskHandler::createList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 3
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SMW\MediaWiki\Specials\Admin;
4
5
use SMW\Message;
6
use Html;
7
use WebRequest;
8
9
/**
10
 * @license GNU GPL v2+
11
 * @since   3.0
12
 *
13
 * @author mwjames
14
 */
15
class DeprecationNoticeTaskHandler extends TaskHandler {
16
17
	/**
18
	 * @var OutputFormatter
19
	 */
20
	private $outputFormatter;
21
22
	/**
23
	 * @var array
24
	 */
25
	private $deprecationNoticeList = array();
26
27
	/**
28
	 * @since 3.0
29
	 *
30
	 * @param OutputFormatter $outputFormatter
31
	 * @param array $deprecationNoticeList
32
	 */
33
	public function __construct( OutputFormatter $outputFormatter, array $deprecationNoticeList = array() ) {
34
		$this->outputFormatter = $outputFormatter;
35
		$this->deprecationNoticeList = $deprecationNoticeList;
36
	}
37
38
	/**
39
	 * @since 3.0
40
	 *
41
	 * {@inheritDoc}
42
	 */
43
	public function getHtml() {
44
45
		$noticeConfigList = array();
46
		$replacementConfigList = array();
47
		$removedConfigList = array();
48
49
		if ( isset( $this->deprecationNoticeList['notice'] ) ) {
50
			$noticeConfigList = $this->deprecationNoticeList['notice'];
51
		}
52
53
		if ( isset( $this->deprecationNoticeList['replacement'] ) ) {
54
			$replacementConfigList = $this->deprecationNoticeList['replacement'];
55
		}
56
57
		if ( isset( $this->deprecationNoticeList['removal'] ) ) {
58
			$removedConfigList = $this->deprecationNoticeList['removal'];
59
		}
60
61
		$noticeList = $this->detectOn(
62
			$noticeConfigList,
63
			$replacementConfigList,
64
			$removedConfigList
65
		);
66
67
		if ( $noticeList === array() ) {
68
			return '';
69
		}
70
71
		return Html::rawElement( 'h2', array(), $this->getMessageAsString( 'smw-admin-deprecation-notice-title' ) ) .
72
			Html::rawElement( 'div', array( 'class' => 'smw-admin-deprecation-notice-section' ),
73
				Html::rawElement( 'p', array( 'class' => 'smw-admin-deprecation-notice-docu-section plainlinks' ), $this->getMessageAsString( 'smw-admin-deprecation-notice-docu' ) ) .
74
				Html::rawElement( 'div', array( 'class' => 'plainlinks' ),
75
					Html::rawElement( 'p', array(), implode( '', $noticeList ) )
76
			)
77
		);
78
	}
79
80
	/**
81
	 * @since 3.0
82
	 *
83
	 * {@inheritDoc}
84
	 */
85
	public function isTaskFor( $task ) {}
86
87
	/**
88
	 * @since 3.0
89
	 *
90
	 * {@inheritDoc}
91
	 */
92
	public function handleRequest( WebRequest $webRequest ) {}
93
94
	private function detectOn( $noticeConfigList, $replacementConfigList, $removedConfigList ) {
0 ignored issues
show
Coding Style introduced by
detectOn uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
95
96
		$noticeList = array();
97
		$list = array();
98
99
		foreach ( $noticeConfigList as $setting => $msg ) {
100
			if ( isset( $GLOBALS[$setting] ) ) {
101
				$list[] = $this->createListItem( array( 'smw-admin-deprecation-notice-config-msg', '$' . $setting, $msg ) );
102
			}
103
		}
104
105
		$this->createList( $noticeList, $list, 'smw-admin-deprecation-notice-title-notice' );
106
107
		foreach ( $replacementConfigList as $old => $new ) {
108
			if ( isset( $GLOBALS[$old] ) ) {
109
				$list[] = $this->createListItem( array( 'smw-admin-deprecation-notice-config-replacement', '$' . $old, '$' . $new ) );
110
			}
111
		}
112
113
		$this->createList( $noticeList, $list, 'smw-admin-deprecation-notice-title-replacement' );
114
115
		foreach ( $removedConfigList as $setting => $msg ) {
116
			if ( isset( $GLOBALS[$setting] ) ) {
117
				$list[] = $this->createListItem( array( 'smw-admin-deprecation-notice-config-msg', '$' . $setting, $msg ) );
118
			}
119
		}
120
121
		$this->createList( $noticeList, $list, 'smw-admin-deprecation-notice-title-removal' );
122
123
		return $noticeList;
124
	}
125
126
	private function createList( &$noticeList, &$list, $title ) {
127
128
		if ( $list === array() ) {
129
			return;
130
		}
131
132
		$noticeList[] = Html::rawElement(
133
			'h3',
134
			array(),
135
			$this->getMessageAsString( $title )
136
		) .	Html::rawElement(
137
			'ul',
138
			array(),
139
			implode( '', $list )
140
		);
141
142
		$list = array();
143
	}
144
145
	private function createListItem( $message ) {
146
		return Html::rawElement( 'li', array(), $this->getMessageAsString( $message, Message::PARSE ) );
147
	}
148
149
}
150