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

SwapDirection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 19
c 1
b 0
f 0
dl 0
loc 49
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 rewind() 0 7 2
A getDateTimeDirection() 0 10 3
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