Code Duplication    Length = 20-21 lines in 3 locations

src/Client.php 3 locations

@@ 73-93 (lines=21) @@
70
    /**
71
     * @inheritdoc
72
     */
73
    public function post($resource, $content)
74
    {
75
        $url = $this->baseUrl . $resource;
76
77
        $headers = array(
78
            'Content-Type' => 'application/json',
79
            'Authorization' => $this->auth->getCredential()
80
        );
81
82
        try {
83
            $response = $this->browser->post($url, $headers, json_encode($content));
84
        } catch (\Buzz\Exception\ClientException $e) {
85
            throw new RequestException($e->getMessage());
86
        }
87
88
        if ($this->browser->getLastResponse()->getStatusCode() > 299) {
89
            throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true));
90
        }
91
92
        return json_decode($response->getContent(), true);
93
    }
94
95
    /**
96
     * @inheritdoc
@@ 98-117 (lines=20) @@
95
    /**
96
     * @inheritdoc
97
     */
98
    public function put($resource, $content = array())
99
    {
100
        $url = $this->baseUrl . $resource;
101
        $headers = array(
102
            'Content-Type' => 'application/json',
103
            'Authorization' => $this->auth->getCredential()
104
        );
105
106
        try {
107
            $response = $this->browser->put($url, $headers, json_encode($content));
108
        } catch (\Buzz\Exception\ClientException $e) {
109
            throw new RequestException($e->getMessage());
110
        }
111
112
        if ($this->browser->getLastResponse()->getStatusCode() > 299) {
113
            throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true));
114
        }
115
116
        return json_decode($response->getContent(), true);
117
    }
118
119
    /**
120
     * @inheritdoc
@@ 122-141 (lines=20) @@
119
    /**
120
     * @inheritdoc
121
     */
122
    public function delete($resource)
123
    {
124
        $url = $this->baseUrl . $resource;
125
126
        $headers = array(
127
            'Authorization' => $this->auth->getCredential()
128
        );
129
130
        try {
131
            $response = $this->browser->delete($url, $headers);
132
        } catch (\Buzz\Exception\ClientException $e) {
133
            throw new RequestException($e->getMessage());
134
        }
135
136
        if ($this->browser->getLastResponse()->getStatusCode() > 299) {
137
            throw new RequestException(json_decode($this->browser->getLastResponse()->getContent(), true));
138
        }
139
140
        return json_decode($response->getContent(), true);
141
    }
142
}
143