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.

Epsilon::isEpsilonPropertyValid()   B
last analyzed

Complexity

Conditions 6
Paths 9

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 6.0106

Importance

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