1 | <?php |
||
2 | |||
3 | namespace DoctrineDatatable; |
||
4 | |||
5 | use Doctrine\ORM\Query; |
||
6 | |||
7 | class Export |
||
8 | { |
||
9 | /** |
||
10 | * @var Datatable |
||
11 | */ |
||
12 | private $datatable; |
||
13 | |||
14 | /** |
||
15 | * @var resource |
||
16 | */ |
||
17 | private $resource; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $delimiter; |
||
23 | |||
24 | public function __construct() |
||
25 | { |
||
26 | $this->setDelimiter("\t"); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * PRIVATE METHODS. |
||
31 | */ |
||
32 | |||
33 | /** |
||
34 | * @author Mathieu Petrini <[email protected]> |
||
35 | */ |
||
36 | private function data(): void |
||
37 | { |
||
38 | foreach ($this->datatable->createFinalQuery(array( |
||
39 | 'start' => 0, |
||
40 | 'limit' => INF, ))->getQuery()->iterate(null, Query::HYDRATE_SCALAR) as $row) { |
||
41 | $line = $row[0]; |
||
42 | fwrite($this->resource, implode($this->delimiter, $line)); |
||
43 | } |
||
44 | rewind($this->resource); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * PUBLIC METHODS. |
||
49 | */ |
||
50 | |||
51 | /** |
||
52 | * @author Mathieu Petrini <[email protected]> |
||
53 | * |
||
54 | * @return resource |
||
55 | */ |
||
56 | public function export() |
||
57 | { |
||
58 | $this->resource = tmpfile(); |
||
0 ignored issues
–
show
|
|||
59 | $this->data(); |
||
60 | |||
61 | return $this->resource; |
||
0 ignored issues
–
show
The expression
return $this->resource could also return false which is incompatible with the documented return type resource . Did you maybe forget to handle an error condition?
If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled. ![]() |
|||
62 | } |
||
63 | |||
64 | /** |
||
65 | * GETTERS / SETTERS. |
||
66 | */ |
||
67 | |||
68 | /** |
||
69 | * @param Datatable $datatable |
||
70 | * |
||
71 | * @return Export |
||
72 | */ |
||
73 | public function setDatatable(Datatable $datatable): self |
||
74 | { |
||
75 | $this->datatable = $datatable; |
||
76 | |||
77 | return $this; |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param string $delimiter |
||
82 | * |
||
83 | * @return Export |
||
84 | */ |
||
85 | public function setDelimiter(string $delimiter): self |
||
86 | { |
||
87 | $this->delimiter = $delimiter; |
||
88 | |||
89 | return $this; |
||
90 | } |
||
91 | } |
||
92 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.