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

ValidatorFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 46
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValidator() 0 9 2
1
<?php
2
/**
3
 * @package: Chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2016-11-10
7
 *
8
 */
9
10
namespace Chapi\Service\JobValidator;
11
12
13
use Chapi\Entity\Chronos\JobEntity;
14
use Chapi\Service\JobValidator\PropertyValidator\Command;
15
use Chapi\Service\JobValidator\PropertyValidator\Constraints;
16
use Chapi\Service\JobValidator\PropertyValidator\Container;
17
use Chapi\Service\JobValidator\PropertyValidator\Epsilon;
18
use Chapi\Service\JobValidator\PropertyValidator\IsArray;
19
use Chapi\Service\JobValidator\PropertyValidator\IsBoolean;
20
use Chapi\Service\JobValidator\PropertyValidator\JobName;
21
use Chapi\Service\JobValidator\PropertyValidator\NotEmpty;
22
use Chapi\Service\JobValidator\PropertyValidator\Retries;
23
use Chapi\Service\JobValidator\PropertyValidator\Schedule;
24
use Symfony\Component\DependencyInjection\ContainerInterface;
25
26
class ValidatorFactory implements ValidatorFactoryInterface
27
{
28
    /**
29
     * @var PropertyValidatorInterface[]
30
     */
31
    private static $aValidatorMap = [
32
        self::NOT_EMPTY_VALIDATOR => NotEmpty::DIC_NAME,
33
        self::NAME_VALIDATOR => JobName::DIC_NAME,
34
        self::EPSILON_VALIDATOR => Epsilon::DIC_NAME,
35
        self::BOOLEAN_VALIDATOR => IsBoolean::DIC_NAME,
36
        self::SCHEDULE_VALIDATOR => Schedule::DIC_NAME,
37
        self::ARRAY_VALIDATOR => IsArray::DIC_NAME,
38
        self::RETRY_VALIDATOR => Retries::DIC_NAME,
39
        self::CONSTRAINTS_VALIDATOR => Constraints::DIC_NAME,
40
        self::CONTAINER_VALIDATOR => Container::DIC_NAME,
41
        self::COMMAND_VALIDATOR => Command::DIC_NAME,
42
    ];
43
44
    /**
45
     * @var ContainerInterface
46
     */
47
    private $oServiceContainer;
48
49
    /**
50
     * ValidatorFactory constructor.
51
     * @param ContainerInterface $oServiceContainer
52
     */
53
    public function __construct(ContainerInterface $oServiceContainer)
54
    {
55
        $this->oServiceContainer = $oServiceContainer;
56
    }
57
58
    /**
59
     * @param int $iValidator
60
     * @return PropertyValidatorInterface
61
     */
62
    public function getValidator($iValidator)
63
    {
64
        if (!isset(self::$aValidatorMap[$iValidator]))
65
        {
66
            throw new \InvalidArgumentException(sprintf('Unknown validator type "%s"', $iValidator));
67
        }
68
        
69
        return $this->oServiceContainer->get(self::$aValidatorMap[$iValidator]);
0 ignored issues
show
Documentation introduced by
self::$aValidatorMap[$iValidator] is of type object<Chapi\Service\Job...ertyValidatorInterface>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
    }
71
}