Completed
Push — master ( dc2855...0a5beb )
by z38
03:37
created

GeneralAccount::format()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Z38\SwissPayment;
4
5
use DOMDocument;
6
use InvalidArgumentException;
7
8
/**
9
 * GeneralAccount holds details about an account which is not covered by any of the other classes
10
 */
11
class GeneralAccount implements AccountInterface
12
{
13
    const MAX_LENGTH = 34;
14
15
    /**
16
     * @var string
17
     */
18
    protected $id;
19
20
    /**
21
     * Constructor
22
     *
23
     * @param string $id
24
     *
25
     * @throws InvalidArgumentException When the account identification exceeds the maximum length.
26
     */
27 4
    public function __construct($id)
28
    {
29 4
        $stringId = (string) $id;
30 4
        if (strlen($stringId) > self::MAX_LENGTH) {
31 1
            throw new InvalidArgumentException('The account identifcation is too long.');
32
        }
33
34 3
        $this->id = $stringId;
35 3
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 3
    public function format()
41
    {
42 3
        return $this->id;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function asDom(DOMDocument $doc)
49
    {
50 2
        $root = $doc->createElement('Id');
51 2
        $other = $doc->createElement('Othr');
52 2
        $other->appendChild($doc->createElement('Id', $this->format()));
53 2
        $root->appendChild($other);
54
55 2
        return $root;
56
    }
57
}
58