These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Access a delimited string content from a HTTP server and iterate it. |
||
4 | * |
||
5 | * The string have the format: |
||
6 | * COLUMN1;COLUMN2;COLUMN3|COLUMN1;COLUMN2;COLUMN3|COLUMN1;COLUMN2;COLUMN3 |
||
7 | * |
||
8 | * You can customize the field and row separators. |
||
9 | */ |
||
10 | |||
11 | namespace ByJG\AnyDataset\Repository; |
||
12 | |||
13 | use ByJG\AnyDataset\Exception\DatasetException; |
||
14 | |||
15 | class SocketDataSet |
||
16 | { |
||
17 | |||
18 | private $_server = null; |
||
19 | private $_colsep = null; |
||
20 | private $_rowsep = null; |
||
21 | private $_fields = null; //Array |
||
22 | private $_port = null; |
||
23 | private $_path = null; |
||
24 | |||
25 | /** |
||
26 | * SocketDataSet constructor. |
||
27 | * @param string $server |
||
28 | * @param string $path |
||
29 | * @param string $rowsep |
||
30 | * @param string $colsep |
||
31 | * @param string $fieldnames |
||
32 | * @param int $port |
||
33 | */ |
||
34 | public function __construct($server, $path, $rowsep, $colsep, $fieldnames, $port = 80) |
||
35 | { |
||
36 | $this->_server = $server; |
||
37 | $this->_rowsep = $rowsep; |
||
38 | $this->_colsep = $colsep; |
||
39 | $this->_fields = $fieldnames; |
||
40 | $this->_port = $port; |
||
41 | $this->_path = $path; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @return SocketIterator |
||
46 | * @throws DatasetException |
||
47 | */ |
||
48 | public function getIterator() |
||
49 | { |
||
50 | $errno = null; |
||
51 | $errstr = null; |
||
52 | $handle = fsockopen($this->_server, $this->_port, $errno, $errstr, 30); |
||
53 | if (!$handle) { |
||
54 | throw new DatasetException("Socket error: $errstr ($errno)"); |
||
55 | } else { |
||
56 | $out = "GET " . $this->_path . " HTTP/1.1\r\n"; |
||
57 | $out .= "Host: " . $this->_server . "\r\n"; |
||
58 | $out .= "Connection: Close\r\n\r\n"; |
||
59 | |||
60 | fwrite($handle, $out); |
||
61 | |||
62 | $it = new SocketIterator($handle, $this->_fields, $this->_rowsep, $this->_colsep); |
||
0 ignored issues
–
show
|
|||
63 | return $it; |
||
64 | } |
||
65 | } |
||
66 | } |
||
67 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: