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   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 67
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B isEpsilonPropertyValid() 0 31 6
A isValid() 0 8 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
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