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

Container   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
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 54
ccs 21
cts 21
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 27 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
}