1 | <?php |
||
5 | class CsvFileObject extends \SplFileObject |
||
6 | { |
||
7 | protected $bytesWritten = 0; |
||
8 | protected $lineEnding = "\r\n"; |
||
9 | |||
10 | public function fwriteCsv(array $row, $delimiter = null, $enclosure = null) |
||
11 | { |
||
12 | $bytes = $this->fwrite($this->getCsvString($row, $delimiter, $enclosure)); |
||
13 | |||
14 | if ($bytes === false) { |
||
15 | return false; |
||
16 | } |
||
17 | |||
18 | $this->bytesWritten += $bytes; |
||
19 | |||
20 | return $bytes; |
||
21 | } |
||
22 | |||
23 | public function __destruct() |
||
27 | |||
28 | /** |
||
29 | * Returns a string representation of a row to be written |
||
30 | * as a line in a CSV file. |
||
31 | * |
||
32 | * @param array $row |
||
33 | * |
||
34 | * @param $delimiter |
||
35 | * @param $enclosure |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | protected function getCsvString(array $row, $delimiter, $enclosure) |
||
54 | |||
55 | /** |
||
56 | * @return int |
||
57 | */ |
||
58 | public function getBytesWritten() |
||
62 | |||
63 | /** |
||
64 | * @return string |
||
65 | */ |
||
66 | public function getLineEnding() |
||
70 | |||
71 | /** |
||
72 | * @param string $lineEnding |
||
73 | * |
||
74 | * @return CsvFileObject |
||
75 | */ |
||
76 | public function setLineEnding($lineEnding) |
||
82 | |||
83 | public function getSize() |
||
93 | |||
94 | /** |
||
95 | * Trims the line ending delimiter from the end of the CSV file. |
||
96 | * RFC-4180 states CSV files should not contain a trailing new line. |
||
97 | */ |
||
98 | public function trimFinalLineEnding() |
||
111 | |||
112 | /** |
||
113 | * Escapes the enclosure character recursively. |
||
114 | * RFC-4180 states the enclosure character (usually double quotes) should be |
||
115 | * escaped by itself, so " becomes "". |
||
116 | * |
||
117 | * @param mixed $data Array or string of data to escape. |
||
118 | * |
||
119 | * @param $enclosure |
||
120 | * |
||
121 | * @return mixed Escaped data |
||
122 | */ |
||
123 | protected static function escapeEnclosure($data, $enclosure) |
||
135 | } |
||
136 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.