SoaResourceRecord::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 9
dl 0
loc 19
ccs 9
cts 9
cp 1
crap 1
rs 10

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Afonso\Dns;
6
7
/**
8
 * This class represents a DNS Resource Record of type SOA.
9
 */
10
class SoaResourceRecord extends ResourceRecord
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $nameserver;
16
17
    /**
18
     * @var string
19
     */
20
    protected $email;
21
22
    /**
23
     * @var int
24
     */
25
    protected $serialNumber;
26
27
    /**
28
     * @var int
29
     */
30
    protected $refresh;
31
32
    /**
33
     * @var int
34
     */
35
    protected $retry;
36
37
    /**
38
     * @var int
39
     */
40
    protected $expiry;
41
42
    /**
43
     * @var int
44
     */
45
    protected $negativeCachingTime;
46
47 9
    public function __construct(
48
        string $name,
49
        int $ttl,
50
        string $nameserver,
51
        string $email,
52
        int $serialNumber,
53
        int $refresh,
54
        int $retry,
55
        int $expiry,
56
        int $negativeCachingTime
57
    ) {
58 9
        parent::__construct($name, $ttl);
59 9
        $this->nameserver = $nameserver;
60 9
        $this->email = $email;
61 9
        $this->serialNumber = $serialNumber;
62 9
        $this->refresh = $refresh;
63 9
        $this->retry = $retry;
64 9
        $this->expiry = $expiry;
65 9
        $this->negativeCachingTime = $negativeCachingTime;
66 9
    }
67
68 3
    public function getType(): int
69
    {
70 3
        return ResourceRecord::TYPE_SOA;
71
    }
72
73 6
    public function __toString(): string
74
    {
75 6
        return "{$this->nameserver}"
76 6
            . " {$this->email}"
77 6
            . " {$this->serialNumber}"
78 6
            . " {$this->refresh}"
79 6
            . " {$this->retry}"
80 6
            . " {$this->expiry}"
81 6
            . " {$this->negativeCachingTime}";
82
    }
83
}
84