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 ( 84136f...fd9624 )
by Ronald
02:33
created

IntervalValuator::determineValue()   B

Complexity

Conditions 6
Paths 6

Size

Total Lines 39
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 39
rs 8.439
cc 6
eloc 22
nc 6
nop 0
1
<?php
2
3
/**
4
 * @file
5
 */
6
7
namespace Roomify\Bat\Valuator;
8
9
use Roomify\Bat\Calendar\Calendar;
10
use Roomify\Bat\Store\Store;
11
use Roomify\Bat\Valuator\AbstractValuator;
12
use Roomify\Bat\Unit\Unit;
13
14
/**
15
 * The IntervalValuator sums the aggregate value of an event by dividing time
16
 * in discreet intervals (using \DateInterval) and then assigning value to those
17
 * intervals based on the value the unit has during that interval.
18
 *
19
 * For example, if we are dealing with a hotel room and want to calculate nightly rates
20
 * we can set the date interval to P1D. We will query the calendar for events whose value
21
 * represents prices over that period and the split the time in 1-day intervals and sum up
22
 * accordingly.
23
 *
24
 * If we are selling activities at 15m intervals we can set the interval at PT15M and we would
25
 * be splitting events on 15m intervals and would assign the value of each interval to the value
26
 * of the event during that interval.
27
 *
28
 * Class IntervalValuator
29
 * @package Roomify\Bat\Valuator
30
 */
31
class IntervalValuator extends AbstractValuator {
32
33
  protected $duration_unit;
34
35
  public function __construct(\DateTime $start_date, \DateTime $end_date, Unit $unit, Store $store, \DateInterval $duration_unit){
36
    parent::__construct($start_date, $end_date, $unit, $store);
37
    $this->duration_unit = $duration_unit;
38
  }
39
40
  public function determineValue() {
41
42
    $value = 0;
43
44
    // Instantiate a calendar
45
    $calendar = new Calendar(array($this->unit), $this->store);
46
47
    $events = $calendar->getEvents($this->start_date, $this->end_date);
48
49
    foreach ($events as $unit => $unit_events) {
50
      // Create a period with the duration and dates supplied
51
      $period = new \DatePeriod($this->start_date, $this->duration_unit, $this->end_date);
52
      print_r("NEW CYCLE\n");
53
      //var_dump($period);
54
      //var_dump($unit);
55
      //var_dump($unit_events);
56
      foreach ($unit_events as $event){
57
        if ($unit = $this->unit->getUnitId()){
0 ignored issues
show
Unused Code introduced by
$unit is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
          foreach ($period as $dt) {
59
              // If event in period involved add value of event
60
              // If event is not completely in period involved then add just the percentage that is
61
              $last_period = $dt;
0 ignored issues
show
Unused Code introduced by
$last_period is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
62
            print_r("Event is: ");
63
            print_r($event->getStartDate()->format('Y-m-d H:i:s') ." to ");
64
            print_r($event->getEndDate()->format('Y-m-d H:i:s') ."\n");
65
            print_r("Period is: ");
66
            print_r($dt->format('Y-m-d H:i:s') ."\n");
67
            if ($event->dateIsInRange($dt)){
68
              print_r("In range adding: " . $event->getValue() . " to event.\n");
69
              $value = $value + $event->getValue();
70
              print_r("Current Value " .$value . "\n");
71
            }
72
          }
73
        }
74
      }
75
    }
76
    var_dump($value);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($value); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
77
    return $value;
78
  }
79
80
}