Passed
Branch master (7ba29e)
by refat
03:38
created

Date   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 26
c 1
b 1
f 0
dl 0
loc 57
rs 10
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isAdate() 0 3 1
A minimum() 0 8 2
A __construct() 0 7 1
A isDateBetween() 0 11 5
A maximum() 0 8 2
1
<?php
2
3
namespace System;
4
use DateTime;
5
6
class Date
7
{
8
   private $start;
9
   private $end;
10
   private $format;
11
   private $value;
12
   private $year;
13
14
  /**
15
   * Constructor
16
   *
17
   */
18
  public function __construct($options, $value)
19
  {
20
    $this->start = $options->start ?? null;
21
    $this->end = $options->end ?? null;
22
    $this->format = $$options->format ?? 'd M Y';
23
    $this->value = $value;
24
    $this->year = DateTime::createFromFormat($this->format, $this->value)->format('Y');
25
  }
26
27
  public function isAdate()
28
  {
29
    return DateTime::createFromFormat($this->format, $this->value);
30
  }
31
32
  public function isDateBetween($start = null, $end = null)
33
  {
34
    if (!$this->start || !$this->end) {
35
      $this->start = $start;
36
      $this->end = $end;
37
    }
38
39
    if ($this->year < $this->start || $this->year > $this->end) {
40
      return false;
41
    }
42
    return true;
43
  }
44
45
  public function minimum($start = null)
46
  {
47
    $this->start = $this->start ?? $start;
48
49
    if ($this->year < $this->start) {
50
      return false;
51
    }
52
    return true;
53
  }
54
55
  public function maximum($end = null)
56
  {
57
    $this->end = $this->end ?? $end;
58
59
    if ($this->year > $this->end) {
60
      return false;
61
    }
62
    return true;
63
  }
64
}
65