AbstractParser   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 69
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 4 1
A __get() 0 6 2
parse() 0 1 ?
A request() 0 4 1
A input() 0 4 1
A toArray() 0 4 1
1
<?php
2
3
namespace Inbounder\Parsers;
4
5
use Illuminate\Contracts\Support\Arrayable;
6
use Illuminate\Http\Request;
7
use Inbounder\Parsers\Contracts\ParserInterface;
8
9
abstract class AbstractParser implements ParserInterface, Arrayable
10
{
11
    /**
12
     * Request.
13
     */
14
    protected $request;
15
16
    /**
17
     * Attributes.
18
     */
19
    protected $attributes;
20
21
22
    public function __set($name, $value)
23
    {
24
        $this->attributes[$name] = $value;
25
    }
26
27
    /**
28
     * Getter.
29
     */
30
    public function __get($name)
31
    {
32
        if (array_key_exists($name, $this->attributes)) {
33
            return $this->attributes[$name];
34
        }
35
    }
36
37
    /**
38
     * Parse the request and return itself.
39
     *
40
     * @return ParserInterface
41
     */
42
    abstract public function parse() : ParserInterface;
43
44
    /**
45
     * Set the request that will be parsed.
46
     *
47
     * @param Request $request
48
     *
49
     * @return void
50
     */
51
    public function request(Request $request)
0 ignored issues
show
Bug introduced by
You have injected the Request via parameter $request. This is generally not recommended as there might be multiple instances during a request cycle (f.e. when using sub-requests). Instead, it is recommended to inject the RequestStack and retrieve the current request each time you need it via getCurrentRequest().
Loading history...
52
    {
53
        $this->request = $request;
54
    }
55
56
    /**
57
     * Retrieve an input from the request.
58
     *
59
     * @param string $name
60
     *
61
     * @return mixed
62
     */
63
    public function input($name)
64
    {
65
        return $this->request->input($name);
66
    }
67
68
    /**
69
     * Get the instance as an array.
70
     *
71
     * @return array
72
     */
73
    public function toArray()
74
    {
75
        return $this->attributes;
76
    }
77
}
78