GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 841b7d...3ed1d3 )
by
unknown
13:44 queued 04:45
created

src/MessageLog.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * File holding the Lingo\MessageLog class.
5
 *
6
 * This file is part of the MediaWiki extension Lingo.
7
 *
8
 * @copyright 2011 - 2018, Stephan Gambke
9
 * @license   GNU General Public License, version 2 (or any later version)
10
 *
11
 * The Lingo extension is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by the Free
13
 * Software Foundation; either version 2 of the License, or (at your option) any
14
 * later version.
15
 *
16
 * The Lingo extension is distributed in the hope that it will be useful, but
17
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19
 * details.
20
 *
21
 * You should have received a copy of the GNU General Public License along
22
 * with this program. If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 * @author Stephan Gambke
25
 *
26
 * @file
27
 * @ingroup Lingo
28
 */
29
30
namespace Lingo;
31
use Html;
32
use Parser;
33
use ParserOptions;
34
35
/**
36
 * This class holds messages (errors, warnings, notices) for Lingo
37
 *
38
 * Contains a static function to initiate the parsing.
39
 *
40
 * @ingroup Lingo
41
 */
42
class MessageLog {
43
44
	private $mMessages = [];
45
	private $mParser = null;
46
47
	const MESSAGE_ERROR = 1;
48
	const MESSAGE_WARNING = 2;
49
	const MESSAGE_NOTICE = 3;
50
51
	/**
52
	 * @param $message
53
	 * @param int $severity
54
	 */
55
	public function addMessage( $message, $severity = self::MESSAGE_NOTICE ) {
56
		$this->mMessages[] = [ $message, $severity ];
57
58
		// log errors and warnings in debug log
59
		if ( $severity == self::MESSAGE_WARNING ||
60
			$severity == self::MESSAGE_ERROR
61
		) {
62
			wfDebug( $message );
63
		}
64
	}
65
66
	/**
67
	 * @param $message
68
	 */
69
	public function addError( $message ) {
70
		$this->mMessages[] = [ $message, self::MESSAGE_ERROR ];
71
		wfDebug( "Error: $message\n" );
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $message instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
72
	}
73
74
	/**
75
	 * @param $message
76
	 */
77
	public function addWarning( $message ) {
78
		$this->mMessages[] = [ $message, self::MESSAGE_WARNING ];
79
		wfDebug( "Warning: $message\n" );
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $message instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
80
	}
81
82
	/**
83
	 * @param $message
84
	 */
85
	public function addNotice( $message ) {
86
		$this->mMessages[] = [ $message, self::MESSAGE_NOTICE ];
87
	}
88
89
	/**
90
	 * @param int $severity
91
	 * @param null $header
92
	 * @return null|string
93
	 */
94
	public function getMessagesFormatted( $severity = self::MESSAGE_WARNING, $header = null ) {
95
		global $wgTitle, $wgUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
96
97
		$ret = '';
98
99
		foreach ( $this->mMessages as $message ) {
100
			if ( $message[ 1 ] <= $severity ) {
101
				$ret .= '* ' . $message[ 0 ] . "\n";
102
			}
103
		}
104
105
		if ( $ret != '' ) {
106
			if ( !$this->mParser ) {
107
				$parser = new Parser();
108
			}
109
110
			if ( $header == null ) {
111
				$header = '';
112
			} elseif ( $header != '' ) {
113
				$header = Html::rawElement( 'div', [ 'class' => 'heading' ], $header );
114
			}
115
116
			$ret = Html::rawElement( 'div', [ 'class' => 'messages' ],
117
				$header . "\n" .
118
				$ret
119
			);
120
121
			// FIXME: Variable 'parser' might have not been defined
122
			// FIXME: $parser->parse returns ParserOutput, not String
123
			$ret = $parser->parse( $ret, $wgTitle, ParserOptions::newFromUser( $wgUser ) );
124
		} else {
125
			// FIXME: Should probably return '' (and throw an error if necessary)
126
			$ret = null;
127
		}
128
129
		return $ret;
130
	}
131
132
}
133
134