Conditions | 1 |
Paths | 1 |
Total Lines | 113 |
Code Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
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 => "NULL", |
||
83 | CsvFormat::OPTION_QUOTE => "'", |
||
84 | CsvFormat::OPTION_NEW_LINE => '---', |
||
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 => 'null', |
||
95 | CsvFormat::OPTION_QUOTE => '', |
||
96 | CsvFormat::OPTION_NEW_LINE => "\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 => '', |
||
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 | new CsvFormat([ |
||
130 | CsvFormat::OPTION_HEADER_ROW => 2, |
||
131 | ]), |
||
132 | ['name' => 'text', 'stuff' => 'things', 'cake' => 'pants'], |
||
133 | '"name","stuff","cake"' . "\n" . |
||
134 | '"text","things","pants"', |
||
135 | 'header row should print the array keys', |
||
136 | ], |
||
137 | [ |
||
138 | new CsvFormat([ |
||
139 | CsvFormat::OPTION_HEADER_ROW => 3, |
||
140 | CsvFormat::OPTION_DATA_START => 6, |
||
141 | ]), |
||
142 | ['name' => 'text', 'stuff' => 'things', 'cake' => 'pants'], |
||
143 | '"name","stuff","cake"' . "\n\n\n" . |
||
144 | '"text","things","pants"', |
||
145 | 'having a sparse start should add spaces before and after the header row', |
||
146 | ], |
||
147 | [ |
||
148 | new CsvFormat([ |
||
149 | CsvFormat::OPTION_HEADER_ROW => 1, |
||
150 | ]), |
||
151 | ['text', 'things,', '"here"'], |
||
152 | '"0","1","2"' . "\n" . '"text","things\,","\"here\""', |
||
153 | 'should out put numbers when no keys are provided', |
||
154 | ], |
||
155 | ]; |
||
156 | } |
||
157 | |||
223 |