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 (#61)
by Marc
04:35
created

Schedule   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 58
ccs 19
cts 19
cp 1
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 22 6
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
13
use Chapi\Component\DatePeriod\DatePeriodFactoryInterface;
14
use Chapi\Entity\Chronos\JobEntity;
15
use Chapi\Service\JobValidator\PropertyValidatorInterface;
16
17
class Schedule extends AbstractPropertyValidator implements PropertyValidatorInterface
18
{
19
    const DIC_NAME = 'ScheduleValidator';
20
    const MESSAGE_TEMPLATE = '"%s" is not a valid ISO8601 string and/or DatePeriodFactory is not able to create a valid DatePeriod';
21
22
    /**
23
     * @var DatePeriodFactoryInterface
24
     */
25
    private $oDatePeriodFactory;
26
27
    /**
28
     * Epsilon constructor.
29
     * @param DatePeriodFactoryInterface $oDatePeriodFactory
30
     */
31 5
    public function __construct(DatePeriodFactoryInterface $oDatePeriodFactory)
32
    {
33 5
        $this->oDatePeriodFactory = $oDatePeriodFactory;
34 5
    }
35
    
36
    /**
37
     * @inheritDoc
38
     */
39 5
    public function isValid($sProperty, JobEntity $oJobEntity)
40
    {
41 5
        return $this->returnIsValidHelper(
42 5
            $this->isSchedulePropertyValid($oJobEntity),
43 5
            $sProperty,
44
            self::MESSAGE_TEMPLATE
45 5
        );
46
    }
47
48
    /**
49
     * @param JobEntity $oJobEntity
50
     * @return bool
51
     */
52 5
    private function isSchedulePropertyValid(JobEntity $oJobEntity)
53
    {
54 5
        if (empty($oJobEntity->schedule) && !empty($oJobEntity->parents))
55 5
        {
56 1
            return true;
57
        }
58
59 5
        if (!empty($oJobEntity->schedule) && empty($oJobEntity->parents))
60 5
        {
61
            try
62
            {
63 4
                $_oDataPeriod = $this->oDatePeriodFactory->createDatePeriod($oJobEntity->schedule, $oJobEntity->scheduleTimeZone);
64 3
                return (false !== $_oDataPeriod);
65
            }
66 1
            catch (\Exception $oException)
67
            {
68
                // invalid: Iso8601 is not valid and/or DatePeriodFactory is able to create a valid DatePeriod
69
            }
70 1
        }
71
72 4
        return false;
73
    }
74
}