Completed
Push — main ( ec0f68...b41cf0 )
by Andreas
14s queued 12s
created

SwapDirection::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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
	/** @var string */
16
	private $value;
17
18
	/** @var array<string, self> */
19
	private static $instances = [];
20
21
	private const FORWARD = 'forward';
22
	private const REWIND = 'rewind';
23
24
	private function __construct(string $value)
25
    {
26
		$this->value = $value;
27
	}
28
29
	public function getValue(): string
30
	{
31
		return $this->value;
32
	}
33
34
	public function getDateTimeDirection(): string
35
	{
36
		switch ($this->value) {
37
			case self::REWIND:
38
				return 'previous';
39
			case self::FORWARD:
40
				return 'next';
41
		}
42
43
		return '';
44
	}
45
46
	public static function forward(): self
47
	{
48
		if (! isset(self::$instances[self::FORWARD])) {
49
			self::$instances[self::FORWARD] = new self(self::FORWARD);
50
		}
51
52
		return self::$instances[self::FORWARD];
53
	}
54
55
	public static function rewind(): self
56
	{
57
		if (! isset(self::$instances[self::REWIND])) {
58
			self::$instances[self::REWIND] = new self(self::REWIND);
59
		}
60
61
		return self::$instances[self::REWIND];
62
	}
63
}
64