DateTimeGetter::get()   C
last analyzed

Complexity

Conditions 13
Paths 13

Size

Total Lines 61
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 43
CRAP Score 13

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 43
cts 43
cp 1
rs 6.2659
c 0
b 0
f 0
cc 13
eloc 43
nc 13
nop 2
crap 13

How to fix   Long Method    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
 * Part of the Joomla Framework DateTime Package
4
 *
5
 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
6
 * @license    GNU Lesser General Public License version 2.1 or later; see LICENSE
7
 */
8
9
namespace Joomla\DateTime\Getter;
10
11
use Joomla\DateTime\DateTime;
12
13
/**
14
 * Default implementation of GetterInterface.
15
 *
16
 * @since  2.0.0
17
 */
18
final class DateTimeGetter implements GetterInterface
19
{
20
	/**
21
	 * Return a value of the property.
22
	 *
23
	 * @param   DateTime  $datetime  The DateTime object.
24
	 * @param   string    $name      The name of the property.
25
	 *
26
	 * @return  string
27
	 *
28
	 * @since   2.0.0
29
	 */
30 29
	public function get(DateTime $datetime, $name)
31
	{
32 29
		$value = null;
33
34
		switch ($name)
35
		{
36 29
			case 'daysinmonth':
37 2
				$value = $datetime->format('t');
38 2
				break;
39
40 27
			case 'dayofweek':
41 2
				$value = $datetime->format('N');
42 2
				break;
43
44 25
			case 'dayofyear':
45 2
				$value = $datetime->format('z');
46 2
				break;
47
48 23
			case 'isleapyear':
49 4
				$value = (boolean) $datetime->format('L');
50 4
				break;
51
52 19
			case 'day':
53 2
				$value = $datetime->format('d');
54 2
				break;
55
56 17
			case 'hour':
57 2
				$value = $datetime->format('H');
58 2
				break;
59
60 15
			case 'minute':
61 2
				$value = $datetime->format('i');
62 2
				break;
63
64 13
			case 'second':
65 2
				$value = $datetime->format('s');
66 2
				break;
67
68 11
			case 'month':
69 2
				$value = $datetime->format('m');
70 2
				break;
71
72 9
			case 'ordinal':
73 4
				$value = $datetime->format('S');
74 4
				break;
75
76 5
			case 'week':
77 2
				$value = $datetime->format('W');
78 2
				break;
79
80 3
			case 'year':
81 2
				$value = $datetime->format('Y');
82 2
				break;
83
84 1
			default:
85 1
				$trace = debug_backtrace();
86 1
				trigger_error('Undefined property: ' . $name . ' in ' . $trace[0]['file'] . ' on line ' . $trace[0]['line'], E_USER_NOTICE);
87 1
		}
88
89 28
		return $value;
90
	}
91
}
92