ParseException   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getLineNumber() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Badcow DNS Library.
7
 *
8
 * (c) Samuel Williams <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Badcow\DNS\Parser;
15
16
class ParseException extends \Exception
17
{
18
    /**
19
     * @var StringIterator
20
     */
21
    private $stringIterator;
22
23
    /**
24
     * ParseException constructor.
25
     */
26 7
    public function __construct(string $message = '', StringIterator $stringIterator = null, \Throwable $previous = null)
27
    {
28 7
        if (null !== $stringIterator) {
29 1
            $this->stringIterator = $stringIterator;
30 1
            $message .= sprintf(' [Line no: %d]', $this->getLineNumber());
31
        }
32
33 7
        parent::__construct($message, 0, $previous);
34 7
    }
35
36
    /**
37
     * Get line number of current entry on the StringIterator.
38
     */
39 1
    private function getLineNumber(): int
40
    {
41 1
        $pos = $this->stringIterator->key();
42 1
        $this->stringIterator->rewind();
43 1
        $lineNo = 1;
44
45 1
        while ($this->stringIterator->key() < $pos) {
46 1
            if ($this->stringIterator->is(Tokens::LINE_FEED)) {
47 1
                ++$lineNo;
48
            }
49 1
            $this->stringIterator->next();
50
        }
51
52 1
        return $lineNo;
53
    }
54
}
55