| Conditions | 4 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 10 |
| CRAP Score | 4.0119 |
| Changes | 1 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 7 | 4 | public static function write(\CsvParser\Parser $parser, \CsvParser\Csv $csv) |
|
| 8 | { |
||
| 9 | 4 | $data = $csv->getData(); |
|
| 10 | |||
| 11 | 4 | if ($data && !empty($data)) { |
|
|
|
|||
| 12 | $output = array( |
||
| 13 | implode($parser->fieldDelimiter, array_map(function ($value) use ($parser) { |
||
| 14 | 4 | return $parser->fieldEnclosure . str_replace($parser->fieldEnclosure, $parser->fieldEnclosure.$parser->fieldEnclosure, $value) . $parser->fieldEnclosure; |
|
| 15 | 4 | }, array_keys(current($data)))) |
|
| 16 | ); |
||
| 17 | |||
| 18 | 4 | foreach ($data as $line) { |
|
| 19 | 4 | $output[] = implode($parser->fieldDelimiter, array_map(function ($value) use ($parser) { |
|
| 20 | 4 | return $parser->fieldEnclosure . str_replace($parser->fieldEnclosure, $parser->fieldEnclosure.$parser->fieldEnclosure, $value) . $parser->fieldEnclosure; |
|
| 21 | 4 | }, $line)); |
|
| 22 | } |
||
| 23 | |||
| 24 | 4 | return implode($parser->lineDelimiter, $output); |
|
| 25 | } else { |
||
| 26 | return ''; |
||
| 27 | } |
||
| 28 | } |
||
| 29 | } |
||
| 30 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.