Passed
Pull Request — master (#315)
by Théo
02:34
created

AbstractConvert   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 8
dl 0
loc 42
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Annotation\Convert;
16
17
use KevinGH\Box\Annotation\Tokens;
18
19
/**
20
 * Manages the basic tasks for converters.
21
 *
22
 * @author Kevin Herrera <[email protected]>
23
 */
24
abstract class AbstractConvert implements ConvertInterface
25
{
26
    /**
27
     * The conversion result.
28
     *
29
     * @var mixed
30
     */
31
    protected $result;
32
33
    /**
34
     * The list of tokens.
35
     *
36
     * @var Tokens
37
     */
38
    protected $tokens;
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function convert(Tokens $tokens)
44
    {
45
        $this->reset($tokens);
46
47
        while ($tokens->valid()) {
48
            $this->handle();
49
            $tokens->next();
50
        }
51
52
        return $this->result;
53
    }
54
55
    /**
56
     * Handles the conversion of the current token.
57
     */
58
    abstract protected function handle(): void;
59
60
    /**
61
     * Resets the state of the converter.
62
     *
63
     * @param Tokens $tokens the new list of tokens
64
     */
65
    abstract protected function reset(Tokens $tokens): void;
66
}
67