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 ( f74f4f...20c617 )
by
unknown
10:07
created

ConstraintManager   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 23
c 0
b 0
f 0
lcom 0
cbo 1
dl 0
loc 77
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C normalizeConstraints() 0 68 23
1
<?php
2
3
/**
4
 * @file
5
 * Class ConstraintManager
6
 */
7
8
namespace Roomify\Bat\Constraint;
9
10
class ConstraintManager {
11
12
  /**
13
   * @param $constraints
14
   *
15
   * @return array
16
   */
17
  public static function normalizeConstraints($constraints) {
18
    $new_constraints = array();
19
20
    foreach (array_reverse($constraints) as $constraint) {
21
      $start_date = $constraint->getStartDate();
22
      $end_date = $constraint->getEndDate();
23
24
      if (get_class($constraint) == 'Roomify\Bat\Constraint\MinMaxDaysConstraint') {
25
        $split_constraint = NULL;
26
27
        if (!empty($new_constraints)) {
28
          foreach ($new_constraints as $new_constraint) {
29
            if (get_class($new_constraint) == 'Roomify\Bat\Constraint\MinMaxDaysConstraint') {
30
              $new_start_date = $new_constraint->getStartDate();
31
              $new_end_date = $new_constraint->getEndDate();
32
33
              if ($constraint->getMinDays() && $new_constraint->getMinDays() ||
34
                  ($constraint->getMaxDays() && $new_constraint->getMaxDays())) {
35
                if ($start_date >= $new_start_date && $start_date <= $new_end_date) {
36
                  $constraint->setStartDate(clone($new_end_date)->add(new \DateInterval('P1D')));
37
                }
38
                elseif ($end_date >= $new_start_date && $end_date <= $new_end_date) {
39
                  $constraint->setEndDate(clone($new_start_date)->sub(new \DateInterval('P1D')));
40
                }
41
                elseif ($start_date < $new_start_date && $end_date > $new_end_date) {
42
                  if ($constraint->getEndDate() > $new_start_date) {
43
                    $constraint->setEndDate(clone($new_start_date)->sub(new \DateInterval('P1D')));
44
                  }
45
46
                  if ($split_constraint == NULL) {
47
                    $split_start_date = clone($new_end_date)->add(new \DateInterval('P1D'));
48
                    $split_end_date = $end_date;
49
50
                    $split_constraint = new MinMaxDaysConstraint($constraint->getUnits(), $constraint->getMinDays(), $constraint->getMaxDays(), $split_start_date, $split_end_date , $constraint->getCheckinDay());
51
                  }
52
                  else {
53
                    $split_start_date = $split_constraint->getStartDate();
54
                    $split_end_date = $split_constraint->getEndDate();
55
56
                    if ($split_start_date < $new_end_date) {
57
                      $split_constraint->setStartDate(clone($new_end_date)->add(new \DateInterval('P1D')));
58
                    }
59
                    if ($split_end_date < $new_start_date) {
60
                      $split_constraint->setEndDate(clone($new_start_date)->sub(new \DateInterval('P1D')));
61
                    }
62
                  }
63
                }
64
              }
65
            }
66
          }
67
        }
68
69
        if ($split_constraint != NULL) {
70
          $new_constraints[] = $split_constraint;
71
        }
72
      }
73
74
      $new_constraints[] = $constraint;
75
    }
76
77
    foreach ($new_constraints as $i => $constraint) {
78
      if ($constraint->getStartDate() > $constraint->getEndDate()) {
79
        unset($new_constraints[$i]);
80
      }
81
    }
82
83
    return $new_constraints;
84
  }
85
  
86
}
87