| Total Complexity | 6 |
| Total Lines | 83 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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() |
||
| 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 |
||
| 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
$accountIdthat can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theidproperty of an instance of theAccountclass. 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.