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.

ModelBuilder::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 11
ccs 7
cts 7
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Pnz\MattermostClient\Model;
6
7
use Pnz\MattermostClient\Exception\InvalidArgumentException;
8
9
abstract class ModelBuilder implements ModelBuilderInterface
10
{
11
    public const BUILD_FOR_CREATE = 'create';
12
    public const BUILD_FOR_UPDATE = 'update';
13
    public const BUILD_FOR_PATCH = 'patch';
14
15
    protected $params = [];
16
17 19
    public function build(string $buildType = self::BUILD_FOR_CREATE): array
18
    {
19 19
        $this->validate($buildType);
20
21 13
        return $this->params;
22
    }
23
24
    /**
25
     * Defined the required fields for the given build type.
26
     *
27
     * @param string $buildType the build type see BUILD_FOR_* consts
28
     */
29
    abstract protected function getRequiredFields(string $buildType = self::BUILD_FOR_CREATE): array;
30
31
    /**
32
     * Validate the parameters.
33
     *
34
     * @param string $buildType the build type to validate the parameters
35
     */
36 19
    protected function validate(string $buildType = self::BUILD_FOR_CREATE): void
37
    {
38 19
        $requiredFields = $this->getRequiredFields($buildType);
39
40 19
        if (empty($requiredFields)) {
41 6
            return;
42
        }
43
44 13
        $missingFields = array_diff_key(array_flip($requiredFields), $this->params);
45 13
        if (!empty($missingFields)) {
46 6
            throw new InvalidArgumentException(sprintf('Required parameters missing: %s', implode(', ', array_keys($missingFields))));
47
        }
48 7
    }
49
}
50