Completed
Push — master ( fef923...c0df34 )
by Rafael
03:03
created

Array2ObjectContext::prependParser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
3
/**
4
 * LICENSE: This file is subject to the terms and conditions defined in
5
 * file 'LICENSE', which is part of this source code package.
6
 *
7
 * @copyright 2016 Copyright(c) - All rights reserved.
8
 */
9
10
namespace Rafrsr\LibArray2Object;
11
12
use Rafrsr\LibArray2Object\Parser\ValueParserInterface;
13
use Rafrsr\LibArray2Object\Matcher\PropertyMatcherInterface;
14
use Rafrsr\LibArray2Object\Writer\PropertyWriterInterface;
15
16
/**
17
 * Class Array2ObjectContext
18
 */
19
class Array2ObjectContext
20
{
21
    /**
22
     * @var array|ValueParserInterface[]
23
     */
24
    private $parsers = [];
25
26
    /**
27
     * @var PropertyMatcherInterface
28
     */
29
    private $matcher;
30
31
    /**
32
     * @var PropertyWriterInterface
33
     */
34
    private $writer;
35
36
    /**
37
     * @return array|Parser\ValueParserInterface[]
38
     */
39
    public function getParsers()
40
    {
41
        return $this->parsers;
42
    }
43
44
    /**
45
     * @param array|Parser\ValueParserInterface[] $parsers
46
     *
47
     * @return $this
48
     */
49 View Code Duplication
    public function setParsers($parsers)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $this->parsers = [];
52
        foreach ($parsers as $parser) {
53
            if ($parser instanceof ValueParserInterface) {
54
                $this->parsers[$parser->getName()] = $parser;
55
            }
56
        }
57
58
        return $this;
59
    }
60
61
    /**
62
     * Append parser to the list of parsers, LOW priority
63
     *
64
     * @param ValueParserInterface $parser
65
     *
66
     * @return $this
67
     */
68
    public function appendParser(ValueParserInterface $parser)
69
    {
70
        $this->parsers[$parser->getName()] = $parser;
71
72
        return $this;
73
    }
74
75
    /**
76
     * Prepend parser to list of parsers, HIGH priority
77
     *
78
     * @param ValueParserInterface $parser
79
     *
80
     * @return $this
81
     */
82
    public function prependParser(ValueParserInterface $parser)
83
    {
84
        $parsers = $this->parsers;
85
        if (array_key_exists($parser->getName(), $parsers)) {
86
            unset($parsers[$parser->getName()]);
87
        }
88
89
        $this->parsers = [$parser->getName() => $parser] + $parsers;
90
91
        return $this;
92
    }
93
94
    /**
95
     * @return PropertyMatcherInterface
96
     */
97
    public function getMatcher()
98
    {
99
        return $this->matcher;
100
    }
101
102
    /**
103
     * @param PropertyMatcherInterface $matcher
104
     *
105
     * @return $this
106
     */
107
    public function setMatcher($matcher)
108
    {
109
        $this->matcher = $matcher;
110
111
        return $this;
112
    }
113
114
    /**
115
     * @return PropertyWriterInterface
116
     */
117
    public function getWriter()
118
    {
119
        return $this->writer;
120
    }
121
122
    /**
123
     * @param PropertyWriterInterface $writer
124
     *
125
     * @return $this
126
     */
127
    public function setWriter($writer)
128
    {
129
        $this->writer = $writer;
130
131
        return $this;
132
    }
133
}