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   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 43
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 6 1
getRequiredFields() 0 1 ?
A validate() 0 13 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