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 (#68)
by Bidesh
04:18
created

Epsilon::isEpsilonPropertyValid()   B

Complexity

Conditions 6
Paths 9

Size

Total Lines 37
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 6.0061

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
ccs 17
cts 18
cp 0.9444
rs 8.439
cc 6
eloc 16
nc 9
nop 1
crap 6.0061
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\ChronosJobEntity;
14
use Chapi\Entity\Chronos\JobEntity;
15
use Chapi\Entity\JobEntityInterface;
16
use Chapi\Service\JobValidator\PropertyValidatorInterface;
17
18
class Epsilon extends AbstractPropertyValidator implements PropertyValidatorInterface
19
{
20
    const DIC_NAME = 'EpsilonValidator';
21
    const MESSAGE_TEMPLATE = '"%s" is not ISO8601 conform not less than the time period';
22
23
    /**
24
     * @var DatePeriodFactoryInterface
25
     */
26
    private $oDatePeriodFactory;
27
28
    /**
29
     * Epsilon constructor.
30
     * @param DatePeriodFactoryInterface $oDatePeriodFactory
31
     */
32 3
    public function __construct(DatePeriodFactoryInterface $oDatePeriodFactory)
33
    {
34 3
        $this->oDatePeriodFactory = $oDatePeriodFactory;
35 3
    }
36
37
    /**
38
     * @inheritDoc
39
     */
40 3
    public function isValid($sProperty, JobEntityInterface $oJobEntity)
41
    {
42 3
        return $this->returnIsValidHelper(
43 3
            $this->isEpsilonPropertyValid($oJobEntity),
44 3
            $sProperty,
45
            self::MESSAGE_TEMPLATE
46 3
        );
47
    }
48
49
    /**
50
     * @param JobEntityInterface $oJobEntity
51
     * @return bool
52
     */
53 3
    private function isEpsilonPropertyValid(JobEntityInterface $oJobEntity)
54
    {
55 3
        if (!$oJobEntity instanceof ChronosJobEntity)
56 3
        {
57
            throw new \RuntimeException('Required ChronosJobEntity. Something else found.');
58
        }
59
60 3
        if ($oJobEntity->isSchedulingJob() && !empty($oJobEntity->epsilon))
61 3
        {
62
            try
63
            {
64 3
                $_oDateIntervalEpsilon = new \DateInterval($oJobEntity->epsilon);
65 3
                $_iIntervalEpsilon = (int) $_oDateIntervalEpsilon->format('%Y%M%D%H%I%S');
66
67 3
                if ($_iIntervalEpsilon > 30) // if epsilon > "PT30S"
68 3
                {
69 3
                    $_oIso8601Entity = $this->oDatePeriodFactory->createIso8601Entity($oJobEntity->schedule);
70
71 3
                    $_oDateIntervalScheduling = new \DateInterval($_oIso8601Entity->sInterval);
72 3
                    $_iIntervalScheduling = (int) $_oDateIntervalScheduling->format('%Y%M%D%H%I%S');
73
74 3
                    return ($_iIntervalScheduling > $_iIntervalEpsilon);
75
                }
76
77
                // if epsilon is less or equal than 30sec the not empty check is enough
78 1
                return true;
79
            }
80 1
            catch (\Exception $_oException)
81
            {
82
                // can't init \DateInterval instance
83 1
                return false;
84
            }
85
        }
86
87
        // else
88 1
        return (!empty($oJobEntity->epsilon));
89
    }
90
}