LanguageWa::date()   C
last analyzed

Complexity

Conditions 13
Paths 12

Size

Total Lines 39
Code Lines 26

Duplication

Lines 8
Ratio 20.51 %

Importance

Changes 0
Metric Value
cc 13
eloc 26
nc 12
nop 4
dl 8
loc 39
rs 5.1234
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Walloon (Walon) specific code.
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License along
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
 * http://www.gnu.org/copyleft/gpl.html
19
 *
20
 * @file
21
 * @ingroup Language
22
 */
23
24
/**
25
 * Walloon (Walon)
26
 *
27
 * NOTE: cweri après "NOTE:" po des racsegnes so des ratournaedjes
28
 * k' i gn a.
29
 *
30
 * @ingroup Language
31
 */
32
class LanguageWa extends Language {
33
34
	/**
35
	 * Dates in Walloon are "1î d' <monthname>" for 1st of the month,
36
	 * "<day> di <monthname>" for months starting by a consoun, and
37
	 * "<day> d' <monthname>" for months starting with a vowel
38
	 *
39
	 * @param string $ts
40
	 * @param bool $adj
41
	 * @param bool $format
42
	 * @param bool $tc
43
	 * @return string
44
	 */
45
	public function date( $ts, $adj = false, $format = true, $tc = false ) {
46
		$ts = wfTimestamp( TS_MW, $ts );
47
		if ( $adj ) {
48
			$ts = $this->userAdjust( $ts, $tc );
0 ignored issues
show
Security Bug introduced by
It seems like $ts defined by $this->userAdjust($ts, $tc) on line 48 can also be of type false; however, Language::userAdjust() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
49
		}
50
		$datePreference = $this->dateFormat( $format );
51
52
		# ISO (YYYY-mm-dd) format
53
		# we also output this format for YMD (eg: 2001 January 15)
54 View Code Duplication
		if ( $datePreference == 'ISO 8601' ) {
55
			$d = substr( $ts, 0, 4 ) . '-' . substr( $ts, 4, 2 ) . '-' . substr( $ts, 6, 2 );
56
			return $d;
57
		}
58
59
		# dd/mm/YYYY format
60 View Code Duplication
		if ( $datePreference == 'walloon short' ) {
61
			$d = substr( $ts, 6, 2 ) . '/' . substr( $ts, 4, 2 ) . '/' . substr( $ts, 0, 4 );
62
			return $d;
63
		}
64
65
		# Walloon format
66
		# we output this in all other cases
67
		$m = substr( $ts, 4, 2 );
68
		$n = substr( $ts, 6, 2 );
69
		if ( $n == 1 ) {
70
			$d = "1î d' " . $this->getMonthName( $m ) .
71
				" " . substr( $ts, 0, 4 );
72
		} elseif ( $n == 2 || $n == 3 || $n == 20 || $n == 22 || $n == 23 ) {
73
			$d = ( 0 + $n ) . " d' " . $this->getMonthName( $m ) .
74
				" " . substr( $ts, 0, 4 );
75
		} elseif ( $m == 4 || $m == 8 || $m == 10 ) {
76
			$d = ( 0 + $n ) . " d' " . $this->getMonthName( $m ) .
77
				" " . substr( $ts, 0, 4 );
78
		} else {
79
			$d = ( 0 + $n ) . " di " . $this->getMonthName( $m ) .
80
				" " . substr( $ts, 0, 4 );
81
		}
82
		return $d;
83
	}
84
85
	/**
86
	 * @param string $ts
87
	 * @param bool $adj
88
	 * @param bool $format
89
	 * @param bool $tc
90
	 * @return string
91
	 */
92
	public function timeanddate( $ts, $adj = false, $format = true, $tc = false ) {
93
		if ( $adj ) {
94
			$ts = $this->userAdjust( $ts, $tc );
95
		}
96
		$datePreference = $this->dateFormat( $format );
97
		if ( $datePreference == 'ISO 8601' ) {
98
			return parent::timeanddate( $ts, $adj, $format, $tc );
99
		} else {
100
			return $this->date( $ts, $adj, $format, $tc ) . ' a ' .
101
				$this->time( $ts, $adj, $format, $tc );
102
		}
103
	}
104
}
105