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
Push — master ( 42287f...fba610 )
by Andy
03:33
created

Schedule   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 57
ccs 16
cts 17
cp 0.9412
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 isSchedulePropertyValid() 0 21 7
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2016-11-10
7
 *
8
 */
9
10
namespace Chapi\Service\JobValidator\PropertyValidator;
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 Schedule extends AbstractPropertyValidator implements PropertyValidatorInterface
19
{
20
    const DIC_NAME = 'ScheduleValidator';
21
    const MESSAGE_TEMPLATE = '"%s" is not a valid ISO8601 string and/or DatePeriodFactory is not able to create a valid DatePeriod';
22
23
    /**
24
     * @var DatePeriodFactoryInterface
25
     */
26
    private $datePeriodFactory;
27
28
    /**
29
     * Epsilon constructor.
30
     * @param DatePeriodFactoryInterface $datePeriodFactory
31
     */
32 5
    public function __construct(DatePeriodFactoryInterface $datePeriodFactory)
33
    {
34 5
        $this->datePeriodFactory = $datePeriodFactory;
35 5
    }
36
    
37
    /**
38
     * @inheritDoc
39
     */
40 5
    public function isValid($property, JobEntityInterface $jobEntity)
41
    {
42 5
        return $this->returnIsValidHelper(
43 5
            $this->isSchedulePropertyValid($jobEntity),
44
            $property,
45 5
            self::MESSAGE_TEMPLATE
46
        );
47
    }
48
49
    /**
50
     * @param JobEntityInterface $jobEntity
51
     * @return bool
52
     */
53 5
    private function isSchedulePropertyValid(JobEntityInterface $jobEntity)
54
    {
55 5
        if (!$jobEntity instanceof ChronosJobEntity) {
56
            throw new \RuntimeException('Required ChronosJobEntity. Something else found.');
57
        }
58
59 5
        if (empty($jobEntity->schedule) && !empty($jobEntity->parents)) {
60 1
            return true;
61
        }
62
63 5
        if (!empty($jobEntity->schedule) && empty($jobEntity->parents)) {
64
            try {
65 4
                $datePeriod = $this->datePeriodFactory->createDatePeriod($jobEntity->schedule, $jobEntity->scheduleTimeZone);
66 3
                return (false !== $datePeriod);
67 1
            } catch (\Exception $exception) {
68
                // invalid: Iso8601 is not valid and/or DatePeriodFactory is able to create a valid DatePeriod
69
            }
70
        }
71
72 4
        return false;
73
    }
74
}
75