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::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
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
}