Conditions | 1 |
Paths | 1 |
Total Lines | 68 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
43 | public function getFormattingData() |
||
44 | { |
||
45 | $format = new CsvFormat(); |
||
46 | |||
47 | $date = new DateTime(); |
||
48 | |||
49 | $object = m::mock(); |
||
50 | $object->shouldReceive('__toString') |
||
51 | ->andReturn('object'); |
||
52 | |||
53 | return [ |
||
54 | [ |
||
55 | $format, |
||
56 | [ |
||
57 | 'text', |
||
58 | 1, |
||
59 | 2.5, |
||
60 | null, |
||
61 | true, |
||
62 | "string wit '", |
||
63 | 'string with "', |
||
64 | 'string with \\', |
||
65 | 'string with ,', |
||
66 | "multi line \n string", |
||
67 | $object, |
||
68 | ], |
||
69 | '"text","1","2.5",\\N,"1","string wit \'","string with \"","string with \\\\","string with \\,","multi line \\' . "\n" . ' string","object"', |
||
70 | 'basic formatting failed', |
||
71 | ], |
||
72 | [ |
||
73 | $format, |
||
74 | [$date], |
||
75 | sprintf('"%s"', $date->format('Y-m-d H:i:s')), |
||
76 | 'date formatting failed', |
||
77 | ], |
||
78 | [ |
||
79 | new CsvFormat([ |
||
80 | CsvFormat::OPTION_DELIMITER => '|', |
||
81 | CsvFormat::OPTION_NULL_OUTPUT => "NULL", |
||
82 | CsvFormat::OPTION_QUOTE_CHARACTER => "'", |
||
83 | CsvFormat::OPTION_LINE_TERMINATOR => '---', |
||
84 | CsvFormat::OPTION_ESCAPE => '"', |
||
85 | ]), |
||
86 | ['text', 1, 2.5, false, null, '|-', "'", '"'], |
||
87 | "'text'|'1'|'2.5'|'0'|NULL|'\"|-'|'\"''|'\"\"'", |
||
88 | 'different options failed', |
||
89 | ], |
||
90 | [ |
||
91 | new CsvFormat([ |
||
92 | CsvFormat::OPTION_DELIMITER => "\t", |
||
93 | CsvFormat::OPTION_NULL_OUTPUT => 'null', |
||
94 | CsvFormat::OPTION_QUOTE_CHARACTER => '', |
||
95 | CsvFormat::OPTION_LINE_TERMINATOR => "\n", |
||
96 | ]), |
||
97 | ['text', 1, 2.5, false, null, "\t a", ",", "\n"], |
||
98 | "text\t1\t2.5\t0\tnull\t" . '\\' . "\t a\t,\t" . '\\' . "\n", |
||
99 | 'tab separated options failed', |
||
100 | ], |
||
101 | [ |
||
102 | new CsvFormat([ |
||
103 | CsvFormat::OPTION_DOUBLE_QUOTE => true, |
||
104 | ]), |
||
105 | ['text"', 1, 2.5, false, null, "\n \r a", "\t", '""foo""'], |
||
106 | '"text""","1","2.5","0",\\N,"\\' . "\n" . ' \\' . "\r" . ' a","\\' . "\t" . '","""""foo"""""', |
||
107 | 'double quotes failed', |
||
108 | ], |
||
109 | ]; |
||
110 | } |
||
111 | |||
149 |