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   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 49
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 8 1
C isContainerPropertyValid() 0 22 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