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

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 38
ccs 10
cts 10
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 5 1
A validate() 0 11 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
    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