DateTimeGetter   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 1
dl 0
loc 74
ccs 43
cts 43
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C get() 0 61 13
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