| Conditions | 4 |
| Paths | 4 |
| Total Lines | 28 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 20 |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 17 | public function send($uri, $options) |
||
| 18 | { |
||
| 19 | $context = stream_context_create($options); |
||
| 20 | |||
| 21 | $stream = @fopen($uri, 'r', false, $context); |
||
| 22 | |||
| 23 | if ($stream == false) { |
||
| 24 | return array(); |
||
| 25 | } |
||
| 26 | |||
| 27 | $data = stream_get_contents($stream); |
||
| 28 | |||
| 29 | if (empty($data)) { |
||
| 30 | throw new NetworkException('Toggl server is unreachable'); |
||
| 31 | } |
||
| 32 | |||
| 33 | if ($data['data'] === false) { |
||
| 34 | throw new ServerException('Toggl server did not return any data'); |
||
| 35 | } |
||
| 36 | |||
| 37 | $metadata = stream_get_meta_data($stream); |
||
| 38 | fclose($stream); |
||
| 39 | |||
| 40 | return array( |
||
| 41 | 'data' => $data, |
||
| 42 | 'metadata' => $metadata, |
||
| 43 | ); |
||
| 44 | } |
||
| 45 | } |
||
| 46 |