JsonDriver   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 4
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A doSendRequest() 0 24 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Pavel
5
 * Date: 2015-05-12
6
 * Time: 22:43
7
 */
8
9
namespace ScayTrase\WebSMS\Driver;
10
11
use Buzz\Client\FileGetContents;
12
use Buzz\Message\Form\FormRequest;
13
use Buzz\Message\Request;
14
use Buzz\Message\Response;
15
use ScayTrase\WebSMS\Exception\InvalidResponseException;
16
17
class JsonDriver implements DriverInterface
18
{
19
    const HTTP_AccessPoint_Send = 'http://cab.websms.ru/json_in5.asp';
20
    const Error_Message         = 'error';
21
    const Error_Code            = 'err_num';
22
23
    public function doSendRequest(array $options)
24
    {
25
        $request = new FormRequest(Request::METHOD_POST);
26
        $request->fromUrl(static::HTTP_AccessPoint_Send);
27
        $request->setFields(array('json' => json_encode($options)));
28
29
        $response = new Response();
30
        $client   = new FileGetContents();
31
32
        $client->send($request, $response);
0 ignored issues
show
Deprecated Code introduced by
The method Buzz\Client\FileGetContents::send() has been deprecated with message: Will be removed in 1.0. Use sendRequest instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
33
34
        $json   = $response->getContent();
35
        $status = json_decode($json, true);
36
37
        if (!isset($status[static::Error_Code])) {
38
            throw new InvalidResponseException('JSON response does not contain response code');
39
        }
40
41
        $normalized_status = $status;
42
        $normalized_status[self::NORMALIZED_MESSAGE] = $status[self::Error_Message];
43
        $normalized_status[self::NORMALIZED_CODE]    = $status[self::Error_Code];
44
45
        return $normalized_status;
46
    }
47
}
48