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

Container::isContainerPropertyValid()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 27
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 27
ccs 16
cts 16
cp 1
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 11
nc 6
nop 1
crap 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\Entity\Chronos\JobEntity;
13
use Chapi\Service\JobValidator\PropertyValidatorInterface;
14
15
class Container extends AbstractPropertyValidator implements PropertyValidatorInterface
16
{
17
    const DIC_NAME = 'ContainerValidator';
18
    const MESSAGE_TEMPLATE = '"%s" is not valid. Type (required), image (required), forcePullImage (optional), network (optional), and volumes (optional)';
19
20
    /**
21
     * @inheritDoc
22
     */
23 3
    public function isValid($sProperty, JobEntity $oJobEntity)
24
    {
25 3
        return $this->returnIsValidHelper(
26 3
            $this->isContainerPropertyValid($oJobEntity->{$sProperty}),
27 3
            $sProperty,
28
            self::MESSAGE_TEMPLATE
29 3
        );
30
    }
31
32
    /**
33
     * @param JobEntity\ContainerEntity $oContainer
34
     * @return bool
35
     *
36
     * @see http://mesos.github.io/chronos/docs/api.html#adding-a-docker-job
37
     * This contains the subfields for the Docker container:
38
     *  type (required), image (required), forcePullImage (optional), network (optional),
39
     *  and volumes (optional)
40
     */
41 3
    private function isContainerPropertyValid($oContainer)
42
    {
43 3
        if (is_null($oContainer))
44 3
        {
45 2
            return true;
46
        }
47
48 3
        if (empty($oContainer->type) || empty($oContainer->image))
49 3
        {
50 2
            return false;
51
        }
52
53 2
        if (!is_array($oContainer->volumes))
54 2
        {
55 1
            return false;
56
        }
57
58 2
        foreach ($oContainer->volumes as $_oVolume)
59
        {
60 2
            if (!in_array($_oVolume->mode, ['RO', 'RW']))
61 2
            {
62 1
                return false;
63
            }
64 1
        }
65
66 1
        return true;
67
    }
68
}