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
Pull Request — master (#61)
by Marc
02:33
created

Epsilon   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 68
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isValid() 0 8 1
B isEpsilonPropertyValid() 0 32 5
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2016-11-10
7
 */
8
9
namespace Chapi\Service\JobValidator\PropertyValidator;
10
11
12
use Chapi\Component\DatePeriod\DatePeriodFactoryInterface;
13
use Chapi\Entity\Chronos\JobEntity;
14
use Chapi\Service\JobValidator\PropertyValidatorInterface;
15
16
class Epsilon extends AbstractPropertyValidator implements PropertyValidatorInterface
17
{
18
    const DIC_NAME = 'EpsilonValidator';
19
    const MESSAGE_TEMPLATE = '"%s" is not ISO8601 conform not less than the time period';
20
21
    /**
22
     * @var DatePeriodFactoryInterface
23
     */
24
    private $oDatePeriodFactory;
25
26
    /**
27
     * Epsilon constructor.
28
     * @param DatePeriodFactoryInterface $oDatePeriodFactory
29
     */
30 3
    public function __construct(DatePeriodFactoryInterface $oDatePeriodFactory)
31
    {
32 3
        $this->oDatePeriodFactory = $oDatePeriodFactory;
33 3
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 3
    public function isValid($sProperty, JobEntity $oJobEntity)
39
    {
40 3
        return $this->returnIsValidHelper(
41 3
            $this->isEpsilonPropertyValid($oJobEntity),
42 3
            $sProperty,
43
            self::MESSAGE_TEMPLATE
44 3
        );
45
    }
46
47
    /**
48
     * @param JobEntity $oJobEntity
49
     * @return bool
50
     */
51 3
    private function isEpsilonPropertyValid(JobEntity $oJobEntity)
52
    {
53 3
        if ($oJobEntity->isSchedulingJob() && !empty($oJobEntity->epsilon))
54 3
        {
55
            try
56
            {
57 3
                $_oDateIntervalEpsilon = new \DateInterval($oJobEntity->epsilon);
58 3
                $_iIntervalEpsilon = (int) $_oDateIntervalEpsilon->format('%Y%M%D%H%I%S');
59
60 3
                if ($_iIntervalEpsilon > 30) // if epsilon > "PT30S"
61 3
                {
62 3
                    $_oIso8601Entity = $this->oDatePeriodFactory->createIso8601Entity($oJobEntity->schedule);
63
64 3
                    $_oDateIntervalScheduling = new \DateInterval($_oIso8601Entity->sInterval);
65 3
                    $_iIntervalScheduling = (int) $_oDateIntervalScheduling->format('%Y%M%D%H%I%S');
66
67 3
                    return ($_iIntervalScheduling > $_iIntervalEpsilon);
68
                }
69
70
                // if epsilon is less or equal than 30sec the not empty check is enough
71 1
                return true;
72
            }
73 1
            catch (\Exception $_oException)
74
            {
75
                // can't init \DateInterval instance
76 1
                return false;
77
            }
78
        }
79
80
        // else
81 1
        return (!empty($oJobEntity->epsilon));
82
    }
83
}