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
02:33
created

JobValidatorService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-07-31
7
 *
8
 */
9
10
namespace Chapi\Service\JobValidator;
11
12
use Chapi\Component\DatePeriod\DatePeriodFactoryInterface;
13
use Chapi\Entity\Chronos\JobEntity;
14
use Chapi\Entity\JobValidator\ValidationResult;
15
16
class JobValidatorService implements JobValidatorServiceInterface
17
{
18
    /**
19
     * @var ValidatorFactoryInterface
20
     */
21
    private $oValidatorFactory;
22
23
    /**
24
     * @var array
25
     */
26
    private static $aValidationMap = [
27
        'name' => ValidatorFactoryInterface::NAME_VALIDATOR,
28
        'command' => ValidatorFactoryInterface::COMMAND_VALIDATOR,
29
        'description' => ValidatorFactoryInterface::NOT_EMPTY_VALIDATOR,
30
        'owner' => ValidatorFactoryInterface::NOT_EMPTY_VALIDATOR,
31
        'ownerName' => ValidatorFactoryInterface::NOT_EMPTY_VALIDATOR,
32
        'epsilon' => ValidatorFactoryInterface::EPSILON_VALIDATOR,
33
        'async' => ValidatorFactoryInterface::BOOLEAN_VALIDATOR,
34
        'disabled' => ValidatorFactoryInterface::BOOLEAN_VALIDATOR,
35
        'softError' => ValidatorFactoryInterface::BOOLEAN_VALIDATOR,
36
        'highPriority' => ValidatorFactoryInterface::BOOLEAN_VALIDATOR,
37
        'schedule' => ValidatorFactoryInterface::SCHEDULE_VALIDATOR,
38
        'parents' => ValidatorFactoryInterface::ARRAY_VALIDATOR,
39
        'retries' => ValidatorFactoryInterface::RETRY_VALIDATOR,
40
        'constraints' => ValidatorFactoryInterface::CONSTRAINTS_VALIDATOR,
41
        'container' => ValidatorFactoryInterface::CONTAINER_VALIDATOR,
42
    ];
43
44
    /**
45
     * JobValidatorService constructor.
46
     * @param ValidatorFactoryInterface $oValidatorFactory
47
     */
48 4
    public function __construct(
49
        ValidatorFactoryInterface $oValidatorFactory
50
    )
51
    {
52 4
        $this->oValidatorFactory = $oValidatorFactory;
53 4
    }
54
55
    /**
56
     * @param JobEntity $oJobEntity
57
     * @return bool
58
     */
59 2
    public function isEntityValid(JobEntity $oJobEntity)
60
    {
61 2
        foreach ($this->validateJobEntity($oJobEntity) as $_oValidatorResult)
62
        {
63 2
            if (!$_oValidatorResult->bIsValid)
64 2
            {
65 1
                return false;
66
            }
67 1
        }
68
69 1
        return true;
70
    }
71
    
72
    /**
73
     * @param JobEntity $oJobEntity
74
     * @return array
75
     */
76 2
    public function getInvalidProperties(JobEntity $oJobEntity)
77
    {
78 2
        $_aValidationFields = $this->validateJobEntity($oJobEntity);
79
80 2
        $_aInvalidFields = [];
81 2
        foreach ($_aValidationFields as $_sProperty => $_oValidationResult)
82
        {
83 2
            if (false == $_oValidationResult->bIsValid)
84 2
            {
85 1
                $_aInvalidFields[$_sProperty] = $_oValidationResult->sErrorMessage;
86 1
            }
87 2
        }
88
89 2
        return $_aInvalidFields;
90
    }
91
92
    /**
93
     * @param JobEntity $oJobEntity
94
     * @return array
95
     */
96 4
    private function validateJobEntity(JobEntity $oJobEntity)
97
    {
98 4
        $_aValidProperties = [];
99
100 4
        foreach (self::$aValidationMap as $_sProperty => $_iValidator)
101
        {
102 4
            $_aValidProperties[$_sProperty] = $this->getValidationResult($_iValidator, $_sProperty, $oJobEntity);
103 4
        }
104
105 4
        return $_aValidProperties;
106
    }
107
108
    /**
109
     * @param int $iValidator
110
     * @param string $sProperty
111
     * @param JobEntity $oJobEntity
112
     * @return ValidationResult
113
     */
114 4
    private function getValidationResult($iValidator, $sProperty, JobEntity $oJobEntity)
115
    {
116 4
        $_oValidator = $this->oValidatorFactory->getValidator($iValidator);
117 4
        return new ValidationResult(
118 4
            $sProperty,
119 4
            $_oValidator->isValid($sProperty, $oJobEntity),
120 4
            $_oValidator->getLastErrorMessage()
121 4
        );
122
    }
123
}