GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( e913e9...2988ab )
by Ronald
02:35
created

IntervalValuator::determineValue()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 19
rs 9.2
cc 4
eloc 10
nc 4
nop 0
1
<?php
2
3
/**
4
 * @file
5
 * Class IntervalValuator
6
 */
7
8
namespace Roomify\Bat\Valuator;
9
10
use Roomify\Bat\Calendar\Calendar;
11
use Roomify\Bat\Store\Store;
12
use Roomify\Bat\Valuator\AbstractValuator;
13
use Roomify\Bat\Unit\Unit;
14
use Roomify\Bat\Event\EventInterval;
15
16
/**
17
 * The IntervalValuator sums the aggregate value of an event by dividing time
18
 * in discreet intervals and then assigning value to those
19
 * intervals based on the value the unit has during that interval.
20
 *
21
 * For example, if we are dealing with a hotel room and want to calculate nightly rates
22
 * we can set the date interval to P1D. We will query the calendar for events whose value
23
 * represents prices over that period and the split the time in 1-day intervals and sum up
24
 * accordingly.
25
 *
26
 * If we are selling activities at 15m intervals we can set the interval at PT15M and we would
27
 * be splitting events on 15m intervals and would assign the value of each interval to the value
28
 * of the event during that interval.
29
 */
30
class IntervalValuator extends AbstractValuator {
31
32
  /**
33
   * @var \DateInterval
34
   */
35
  protected $duration_unit;
36
37
  /**
38
   * @param \DateTime $start_date
39
   * @param \DateTime $end_date
40
   * @param Unit $unit
41
   * @param Store $store
42
   * @param \DateInterval $duration_unit
43
   */
44
  public function __construct(\DateTime $start_date, \DateTime $end_date, Unit $unit, Store $store, \DateInterval $duration_unit) {
45
    parent::__construct($start_date, $end_date, $unit, $store);
46
    $this->duration_unit = $duration_unit;
47
  }
48
49
  /**
50
   * {@inheritdoc}
51
   */
52
  public function determineValue() {
53
    $value = 0;
54
55
    // Instantiate a calendar
56
    $calendar = new Calendar(array($this->unit), $this->store);
57
58
    $events = $calendar->getEvents($this->start_date, $this->end_date);
59
60
    foreach ($events as $unit => $unit_events) {
61
      if ($unit == $this->unit->getUnitId()) {
62
        foreach ($unit_events as $event) {
63
          $percentage = EventInterval::divide($event->getStartDate(), $event->getEndDate(), $this->duration_unit);
64
          $value = $value + $event->getValue() * $percentage;
65
        }
66
      }
67
    }
68
69
    return round($value, 2);
70
  }
71
72
}
73