Parameter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A fromString() 0 8 2
A getValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\Http\Header\Value\ContentDisposition;
6
7
use Stadly\Http\Utilities\Rfc6266;
8
9
/**
10
 * Class for handling content disposition parameters.
11
 *
12
 * Specification: https://tools.ietf.org/html/rfc6266#section-4.1
13
 */
14
abstract class Parameter
15
{
16
    /**
17
     * @var string Name.
18
     */
19
    protected $name;
20
21
    /**
22
     * @var string Value.
23
     */
24
    protected $value;
25
26
    /**
27
     * Construct parameter from string.
28
     *
29
     * @param string $parameter Parameter string.
30
     * @return self Parameter generated based on the string.
31
     */
32 2
    public static function fromString(string $parameter): self
33
    {
34 2
        $regEx = '{^' . Rfc6266::DISPOSITION_PARM_EXTENDED . '$}';
35 2
        if (preg_match($regEx, $parameter) === 1) {
36 1
            return ExtendedParameter::fromString($parameter);
37
        }
38
39 1
        return RegularParameter::fromString($parameter);
40
    }
41
42
    /**
43
     * @return string String representation of the parameter.
44
     */
45
    abstract public function __toString(): string;
46
47
    /**
48
     * @return string Name.
49
     */
50 2
    public function getName(): string
51
    {
52 2
        return $this->name;
53
    }
54
55
    /**
56
     * @param string $name Name.
57
     */
58
    abstract public function setName(string $name): void;
59
60
    /**
61
     * @return string Value.
62
     */
63 2
    public function getValue(): string
64
    {
65 2
        return $this->value;
66
    }
67
68
    /**
69
     * @param string $value Value.
70
     */
71
    abstract public function setValue(string $value): void;
72
}
73