DataChecker   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
ccs 0
cts 25
cp 0
wmc 10
lcom 1
cbo 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getError() 0 3 1
A run() 0 11 2
A getUserDataValue() 0 9 3
A addCheck() 0 3 1
A runChecks() 0 6 2
A error() 0 3 1
populateData() 0 1 ?
1
<?php
2
3
namespace SES;
4
5
use Exception;
6
7
/**
8
 * An abstract data getter and checker class.
9
 * Its concrete subclasses should incapsulate all the necessary data getting
10
 * and environment checks.
11
 *
12
 * @license GNU GPL v3+
13
 * @since 1.0
14
 *
15
 * @author Serhii Kutnii
16
 */
17
abstract class DataChecker {
18
19
	private $mError = null;
20
21
	// Checks
22
	private $mEnvCheckCalls = array();
23
24
	public function getError() {
25
		return $this->mError;
26
	}
27
28
	public function run() {
29
		try
30
		{
31
			$this->populateData();
32
			$this->runChecks();
33
		}
34
		catch ( Exception $e )
35
		{
36
			$this->mError = $e->getMessage();
37
		}
38
	}
39
40
 	/*
0 ignored issues
show
Coding Style introduced by
There is some trailing whitespace on this line which should be avoided as per coding-style.
Loading history...
41
 	 * Get a value from the request.
42
 	 * $err_message_id specifies an error that should be thrown
43
 	 * if the value is empty
44
 	 */
45
 	protected function getUserDataValue( $id, $err_message_id = null ) {
46
 		global $wgRequest;
47
 		$value = $wgRequest->getText( $id );
48
49
 		if ( $err_message_id && !$value )
50
 			$this->error( wfMessage( $err_message_id )->plain() );
51
52
 		return $value;
53
 	}
54
55
	protected function addCheck( $method_callback, array $args ) {
56
		$this->mEnvCheckCalls[] = array( $method_callback, $args );
57
	}
58
59
	protected function runChecks() {
60
		foreach ( $this->mEnvCheckCalls as $call_array )
61
		{
62
			call_user_func_array( $call_array[0], $call_array[1] );
63
		}
64
	}
65
66
	// Abstracting error calls in order to make this functionality changeable in subclasses
67
	protected function error( $message ) {
68
		throw new Exception( $message );
69
	}
70
71
	abstract protected function populateData();
72
73
}
74