MarioBlazek /
Toggable
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Marek\Toggable\Http\Manager; |
||
| 4 | |||
| 5 | use Marek\Toggable\API\Http\Response\Response; |
||
| 6 | use InvalidArgumentException; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Class NativeRequestManager |
||
| 10 | * @package Marek\Toggable\Http\Manager |
||
| 11 | */ |
||
| 12 | class NativeRequestManager implements RequestManagerInterface |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var \Marek\Toggable\Http\Client\HttpClientInterface |
||
| 16 | */ |
||
| 17 | private $client; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var \Marek\Toggable\API\Security\TokenInterface |
||
| 21 | */ |
||
| 22 | private $token; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $uri; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * NativeRequestManager constructor. |
||
| 31 | * |
||
| 32 | * @param \Marek\Toggable\Http\Client\HttpClientInterface $client |
||
| 33 | * @param \Marek\Toggable\API\Security\TokenInterface $token |
||
| 34 | * @param string $uri |
||
| 35 | */ |
||
| 36 | 14 | public function __construct( |
|
| 37 | \Marek\Toggable\Http\Client\HttpClientInterface $client, |
||
| 38 | \Marek\Toggable\API\Security\TokenInterface $token, |
||
| 39 | $uri |
||
| 40 | ) |
||
| 41 | { |
||
| 42 | 14 | $this->client = $client; |
|
| 43 | 14 | $this->token = $token; |
|
| 44 | |||
| 45 | 14 | if (empty($uri) || !is_string($uri)) { |
|
| 46 | throw new InvalidArgumentException( |
||
| 47 | sprintf('Please provide valid ur in %s', get_class($this)) |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | 14 | $this->uri = $uri; |
|
| 51 | 14 | } |
|
| 52 | |||
| 53 | /** |
||
| 54 | * {@inheritdoc} |
||
| 55 | */ |
||
| 56 | public function request(\Marek\Toggable\API\Http\Request\Request $request) |
||
| 57 | { |
||
| 58 | $opts = array( |
||
| 59 | 'http' => array( |
||
| 60 | 'method' => $request->getMethod(), |
||
| 61 | 'header' => array( |
||
| 62 | 'Content-type: application/json', |
||
| 63 | ), |
||
| 64 | ), |
||
| 65 | ); |
||
| 66 | |||
| 67 | $auth = $this->token->getAuthentication(); |
||
| 68 | $auth = $auth[0] . ':' . $auth[1]; |
||
| 69 | $auth = base64_encode($auth); |
||
| 70 | $opts['http']['header'][] = 'Authorization: Basic ' . $auth; |
||
| 71 | |||
| 72 | if (!empty($request->getData())) { |
||
| 73 | $opts['http']['content'] = json_encode($request); |
||
| 74 | } |
||
| 75 | |||
| 76 | $uri = $this->uri . '/' . $request->getUri(); |
||
| 77 | |||
| 78 | $data = $this->client->send($uri, $opts); |
||
| 79 | |||
| 80 | var_dump(json_decode($data['data'], true));die; |
||
|
0 ignored issues
–
show
Security
Debugging Code
introduced
by
Loading history...
The method
request() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an Loading history...
|
|||
| 81 | if (empty($data)) { |
||
|
0 ignored issues
–
show
if (empty($data)) { throw new \Exception(); } does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last Loading history...
The variable
$data seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.
This check marks calls to This is likely the result of code being shifted around. Consider removing these calls. Loading history...
|
|||
| 82 | throw new \Exception; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($data['data'] === false) { |
||
| 86 | throw new \Exception; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 |