1 | <?php |
||
22 | class Writer |
||
23 | { |
||
24 | /** @var Streamable The output stream to write to */ |
||
25 | protected $output; |
||
26 | |||
27 | /** @var Dialect The *dialect* of CSV to write */ |
||
28 | protected $dialect; |
||
29 | |||
30 | /** @var Collection The header row */ |
||
31 | protected $header; |
||
32 | |||
33 | /** |
||
34 | * Writer constructor. |
||
35 | * |
||
36 | * Although this is the constructor, I don't envision it being used much in userland. I think much more common |
||
37 | * methods of creating writers will be available within CSVelte base class such as CSVelte::toSplFileObject, |
||
38 | * CSVelte::toPath(), CSVelte::toOutputBuffer(), etc. |
||
39 | * |
||
40 | * @param Streamable $output The destination streamable being written to |
||
41 | * @param Dialect $dialect The dialect being written |
||
42 | */ |
||
43 | 4 | public function __construct(Streamable $output, Dialect $dialect = null) |
|
51 | |||
52 | /** |
||
53 | * Set the CSV dialect |
||
54 | * |
||
55 | * @param Dialect $dialect The *dialect* of CSV to use |
||
56 | * |
||
57 | * @return self |
||
58 | */ |
||
59 | 4 | public function setDialect(Dialect $dialect) |
|
64 | |||
65 | /** |
||
66 | * Get dialect |
||
67 | * |
||
68 | * @return Dialect |
||
69 | */ |
||
70 | 4 | public function getDialect() |
|
74 | |||
75 | /** |
||
76 | * Set output stream |
||
77 | * |
||
78 | * @param Streamable $stream The output stream to write to |
||
79 | * |
||
80 | * @return self |
||
81 | */ |
||
82 | 4 | protected function setOutputStream(Streamable $stream) |
|
87 | |||
88 | /** |
||
89 | * Insert a single record into CSV output |
||
90 | * |
||
91 | * Returns total bytes written to the output stream. |
||
92 | * |
||
93 | * @param array|Traversable $data A row of data to write to the CSV output |
||
94 | * |
||
95 | * @return false|int |
||
96 | */ |
||
97 | 2 | public function insertRow($data) |
|
135 | |||
136 | /** |
||
137 | * Write multiple rows to CSV output |
||
138 | * |
||
139 | * Returns total bytes written to the output stream. |
||
140 | * |
||
141 | * @param array|Traversable $data An array of rows of data to write to the CSV output |
||
142 | * |
||
143 | * @return int |
||
144 | */ |
||
145 | 1 | public function insertAll($data) |
|
153 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.