SwapDirection   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 19
c 2
b 0
f 0
dl 0
loc 47
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 0 3 1
A __construct() 0 3 1
A forward() 0 7 2
A getDateTimeDirection() 0 10 3
A rewind() 0 7 2
1
<?php
2
3
/**
4
 * Copyright Andreas Heigl <[email protected]>
5
 *
6
 * Licenses under the MIT-license. For details see the included file LICENSE.md
7
 */
8
9
declare(strict_types=1);
10
11
namespace Org_Heigl\Holidaychecker;
12
13
final class SwapDirection
14
{
15
	private const FORWARD = 'forward';
16
	private const REWIND = 'rewind';
17
	/** @var array<string, self> */
18
	private static $instances = [];
19
	/** @var string */
20
	private $value;
21
22
	private function __construct(string $value)
23
	{
24
		$this->value = $value;
25
	}
26
27
	public static function forward(): self
28
	{
29
		if (!isset(self::$instances[self::FORWARD])) {
30
			self::$instances[self::FORWARD] = new self(self::FORWARD);
31
		}
32
33
		return self::$instances[self::FORWARD];
34
	}
35
36
	public static function rewind(): self
37
	{
38
		if (!isset(self::$instances[self::REWIND])) {
39
			self::$instances[self::REWIND] = new self(self::REWIND);
40
		}
41
42
		return self::$instances[self::REWIND];
43
	}
44
45
	public function getValue(): string
46
	{
47
		return $this->value;
48
	}
49
50
	public function getDateTimeDirection(): string
51
	{
52
		switch ($this->value) {
53
			case self::REWIND:
54
				return 'previous';
55
			case self::FORWARD:
56
				return 'next';
57
		}
58
59
		return '';
60
	}
61
}
62