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.

Container::isContainerPropertyValid()   C
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 7

Importance

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