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::isSchedulePropertyValid()   B

Complexity

Conditions 7
Paths 5

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 7.049

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 9
cts 10
cp 0.9
rs 7.551
c 0
b 0
f 0
cc 7
eloc 11
nc 5
nop 1
crap 7.049
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