| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 44 | public function getFormattingData() |
||
| 45 | { |
||
| 46 | $format = new CsvFormat(); |
||
| 47 | |||
| 48 | $date = new DateTime(); |
||
| 49 | |||
| 50 | $object = m::mock(); |
||
| 51 | $object->shouldReceive('__toString') |
||
| 52 | ->andReturn('object'); |
||
| 53 | |||
| 54 | return [ |
||
| 55 | [ |
||
| 56 | $format, |
||
| 57 | [ |
||
| 58 | 'text', |
||
| 59 | 1, |
||
| 60 | 2.5, |
||
| 61 | null, |
||
| 62 | true, |
||
| 63 | "string wit '", |
||
| 64 | 'string with "', |
||
| 65 | 'string with \\', |
||
| 66 | 'string with ,', |
||
| 67 | "multi line \n string", |
||
| 68 | $object, |
||
| 69 | ], |
||
| 70 | '"text","1","2.5",\\N,"1","string wit \'","string with \"","string with \\\\","string with \\,","multi line \\' . "\n" . ' string","object"', |
||
| 71 | 'basic formatting failed', |
||
| 72 | ], |
||
| 73 | [ |
||
| 74 | $format, |
||
| 75 | [$date], |
||
| 76 | sprintf('"%s"', $date->format('Y-m-d H:i:s')), |
||
| 77 | 'date formatting failed', |
||
| 78 | ], |
||
| 79 | [ |
||
| 80 | new CsvFormat([ |
||
| 81 | CsvFormat::OPTION_DELIMITER => '|', |
||
| 82 | CsvFormat::OPTION_NULL_OUTPUT => "NULL", |
||
| 83 | CsvFormat::OPTION_QUOTE_CHARACTER => "'", |
||
| 84 | CsvFormat::OPTION_LINE_TERMINATOR => '---', |
||
| 85 | CsvFormat::OPTION_ESCAPE => '"', |
||
| 86 | ]), |
||
| 87 | ['text', 1, 2.5, false, null, '|-', "'", '"'], |
||
| 88 | "'text'|'1'|'2.5'|'0'|NULL|'\"|-'|'\"''|'\"\"'", |
||
| 89 | 'different options failed', |
||
| 90 | ], |
||
| 91 | [ |
||
| 92 | new CsvFormat([ |
||
| 93 | CsvFormat::OPTION_DELIMITER => "\t", |
||
| 94 | CsvFormat::OPTION_NULL_OUTPUT => 'null', |
||
| 95 | CsvFormat::OPTION_QUOTE_CHARACTER => '', |
||
| 96 | CsvFormat::OPTION_LINE_TERMINATOR => "\n", |
||
| 97 | ]), |
||
| 98 | ['text', 1, 2.5, false, null, "\t a", ",", "\n"], |
||
| 99 | "text\t1\t2.5\t0\tnull\t" . '\\' . "\t a\t,\t" . '\\' . "\n", |
||
| 100 | 'tab separated options failed', |
||
| 101 | ], |
||
| 102 | [ |
||
| 103 | new CsvFormat([ |
||
| 104 | CsvFormat::OPTION_DOUBLE_QUOTE => true, |
||
| 105 | ]), |
||
| 106 | ['text"', 1, 2.5, false, null, "\n \r a", "\t", '""foo""'], |
||
| 107 | '"text""","1","2.5","0",\\N,"\\' . "\n" . ' \\' . "\r" . ' a","\\' . "\t" . '","""""foo"""""', |
||
| 108 | 'double quotes failed', |
||
| 109 | ], |
||
| 110 | [ |
||
| 111 | new CsvFormat([ |
||
| 112 | CsvFormat::OPTION_ESCAPE => '', |
||
| 113 | CsvFormat::OPTION_DOUBLE_QUOTE => true, |
||
| 114 | ]), |
||
| 115 | ['text', '"test', ','], |
||
| 116 | '"text","""test",","', |
||
| 117 | 'no escape failed', |
||
| 118 | ], |
||
| 119 | [ |
||
| 120 | new CsvFormat([ |
||
| 121 | CsvFormat::OPTION_QUOTE_CHARACTER => '', |
||
| 122 | CsvFormat::OPTION_DOUBLE_QUOTE => true, |
||
| 123 | ]), |
||
| 124 | ['text', 'things,', '"here"'], |
||
| 125 | 'text,things\,,"here"', |
||
| 126 | 'blank quote character failed and double quote should do nothing', |
||
| 127 | ], |
||
| 128 | ]; |
||
| 129 | } |
||
| 130 | |||
| 178 |