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
Push — master ( 89fb33...cd256e )
by Ema
02:19
created

ModelBuilder::validate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
crap 3
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
    const BUILD_FOR_CREATE = 'create';
12
    const BUILD_FOR_UPDATE = 'update';
13
    const BUILD_FOR_PATCH = 'patch';
14
15
    protected $params = [];
16
17 15
    public function build($buildType = self::BUILD_FOR_CREATE)
18
    {
19 15
        $this->validate($buildType);
20
21 9
        return $this->params;
22
    }
23
24
    /**
25
     * Defined the required fields for the given build type.
26
     *
27
     * @param string $buildType
28
     *
29
     * @return array
30
     */
31
    abstract protected function getRequiredFields($buildType = self::BUILD_FOR_CREATE);
32
33
    /**
34
     * Validate the parameters.
35
     *
36
     * @param string $buildType the build type to validate the parameters
37
     */
38 15
    protected function validate($buildType = self::BUILD_FOR_CREATE)
39
    {
40 15
        $requiredFields = $this->getRequiredFields($buildType);
41
42 15
        if (empty($requiredFields)) {
43 3
            return;
44
        }
45
46 12
        $missingFields = array_diff_key(array_flip($requiredFields), $this->params);
47 12
        if (!empty($missingFields)) {
48 6
            throw new InvalidArgumentException(sprintf('Required parameters missing: %s', implode(', ', array_keys($missingFields))));
49
        }
50 6
    }
51
}
52