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

Date::isAdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
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