Completed
Push — 1.x ( c997cb...ce72f9 )
by Akihito
20s queued 14s
created

Request::__get()   B

Complexity

Conditions 6
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 7
nc 3
nop 1
crap 6
1
<?php
2
/**
3
 * This file is part of the BEAR.Resource package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Resource;
8
9
/**
10
 * @property $this lazy
11
 * @property $this eager
12
 */
13
final class Request extends AbstractRequest
14
{
15
    const GET = 'get';
16
    const POST = 'post';
17
    const PUT = 'put';
18
    const PATCH = 'patch';
19
    const DELETE = 'delete';
20
    const HEAD = 'head';
21
    const OPTIONS = 'options';
22
23
    /**
24
     * @param string $name
25
     *
26
     * @return $this
27
     */
28 23
    public function __get($name)
29
    {
30 23
        if ($name === 'eager' || $name === 'lazy') {
31 19
            $this->in = $name;
32
33 19
            return $this;
34
        }
35 4
        if ($name === 'code' || $name === 'headers' || $name === 'body') {
36 3
            return parent::__get($name);
37
        }
38
39 1
        throw new \OutOfRangeException($name);
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45 21
    public function withQuery(array $query)
46
    {
47 21
        $this->query = $query;
48
49 21
        return $this;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 7
    public function addQuery(array $query)
56
    {
57 7
        $this->query = array_merge($this->query, $query);
58
59 7
        return $this;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65 7
    public function toUriWithMethod()
66
    {
67 7
        $uri = $this->toUri();
68
69 7
        return "{$this->method} {$uri}";
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 10
    public function toUri()
76
    {
77 10
        $this->resourceObject->uri->query = $this->query;
78
79 10
        return (string) $this->resourceObject->uri;
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85 1
    public function linkSelf($linkKey)
86
    {
87 1
        $this->links[] = new LinkType($linkKey, LinkType::SELF_LINK);
88
89 1
        return $this;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 1
    public function linkNew($linkKey)
96
    {
97 1
        $this->links[] = new LinkType($linkKey, LinkType::NEW_LINK);
98
99 1
        return $this;
100
    }
101
102
    /**
103
     * {@inheritdoc}
104
     */
105 1
    public function linkCrawl($linkKey)
106
    {
107 1
        $this->links[] = new LinkType($linkKey, LinkType::CRAWL_LINK);
108
109 1
        return $this;
110
    }
111
}
112