Conditions | 1 |
Paths | 1 |
Total Lines | 82 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 1 | Features | 2 |
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 |
||
95 | public function testSettingProperties() |
||
96 | { |
||
97 | $definition = new CsvFormat(); |
||
98 | |||
99 | static::assertSame($definition, $definition->setDelimiter("\t"), "SetDelimiter should be fluent"); |
||
100 | static::assertEquals("\t", $definition->getDelimiter(), "Delimiter should be set to '\\t' (tab)"); |
||
101 | |||
102 | static::assertSame($definition, $definition->setQuote(''), "setQuoteCharacter should be fluent"); |
||
103 | static::assertEquals('', $definition->getQuote(), "Quote character should be blank"); |
||
104 | static::assertFalse($definition->hasQuote(), "Quoting should be off"); |
||
105 | |||
106 | static::assertSame($definition, $definition->setNullValue(''), "setNullOutput should be fluent"); |
||
107 | static::assertEquals('', $definition->getNullValue(), "Null character should be '' (blank)'"); |
||
108 | |||
109 | static::assertSame($definition, $definition->setHeaderRow(1), "setHeaders should be fluent"); |
||
110 | static::assertTrue($definition->hasHeaderRow(), "Headers should be on"); |
||
111 | static::assertEquals(1, $definition->getHeaderRow(), "Headers should be set to 1"); |
||
112 | |||
113 | static::assertSame($definition, $definition->setDataStart(2), "setDataStart should be fluent"); |
||
114 | static::assertEquals(2, $definition->getDataStart(), "Data Start should be 2"); |
||
115 | |||
116 | static::assertSame($definition, $definition->setNewLine('----'), "setLineTerminator should be fluent"); |
||
117 | static::assertEquals("----", $definition->getNewLine(), "Line terminator should be '----'"); |
||
118 | static::assertEquals(["----"], $definition->getNewLines(), "Line terminator should be '----'"); |
||
119 | |||
120 | static::assertSame($definition, $definition->setNewLine(['----', '+++']), "setLineTerminator should be fluent"); |
||
121 | static::assertEquals("----", $definition->getNewLine(), "Line terminator should be '----'"); |
||
122 | static::assertEquals(["----", "+++"], $definition->getNewLines(), "Line terminator should be ['----','+++']"); |
||
123 | |||
124 | static::assertSame($definition, $definition->setEscape('"'), "Set escape character should be fluent"); |
||
125 | static::assertEquals('"', $definition->getEscape(), "Escape character should be modified"); |
||
126 | static::assertTrue($definition->hasEscape(), "Format should have an escape character"); |
||
127 | |||
128 | static::assertSame($definition, $definition->setEscape(''), "Set escape character should be fluent"); |
||
129 | static::assertEquals('', $definition->getEscape(), "Escape character should be modified"); |
||
130 | static::assertFalse($definition->hasEscape(), "Format should not have an escape character"); |
||
131 | |||
132 | static::assertSame($definition, $definition->setLimit(3), "setLimit should be fluent"); |
||
133 | static::assertEquals(3, $definition->getLimit(), "Limit should be modified"); |
||
134 | |||
135 | static::assertSame($definition, $definition->setDoubleQuote(true), 'setDoubleQuote should be fluent'); |
||
136 | static::assertTrue($definition->useDoubleQuotes(), 'isDoubleQuote should be true'); |
||
137 | |||
138 | static::assertSame($definition, $definition->setBom(Bom::BOM_UTF32_BE), 'setBom should be fluent'); |
||
139 | static::assertEquals(Bom::BOM_UTF32_BE, $definition->getBom(), 'Bom should be set to the UTF32BE BOM'); |
||
140 | static::assertEquals([Bom::BOM_UTF32_BE], $definition->getBoms(), 'Bom should be set to the UTF32BE BOM'); |
||
141 | static::assertEquals( |
||
142 | 'UTF-32BE', |
||
143 | $definition->getEncoding(), |
||
144 | 'getEncoding should be modified after setting the BOM' |
||
145 | ); |
||
146 | |||
147 | static::assertSame($definition, $definition->setBom([Bom::BOM_UTF16_BE, Bom::BOM_UTF16_LE])); |
||
148 | static::assertEquals(Bom::BOM_UTF16_BE, $definition->getBom(), 'Bom should be set to UTF16BE for writing'); |
||
149 | static::assertEquals( |
||
150 | [Bom::BOM_UTF16_BE, Bom::BOM_UTF16_LE], |
||
151 | $definition->getBoms(), |
||
152 | 'Boms should be set to both UTF16 BOMs' |
||
153 | ); |
||
154 | static::assertEquals( |
||
155 | 'UTF-16BE', |
||
156 | $definition->getEncoding(), |
||
157 | 'getEncoding should be modified after setting the BOM as an array' |
||
158 | ); |
||
159 | |||
160 | // reset |
||
161 | $definition->setBom(null); |
||
162 | static::assertEquals(null, $definition->getBom(), 'Bom should be reset to null'); |
||
163 | static::assertEquals( |
||
164 | [Bom::BOM_UTF8, Bom::BOM_UTF16_BE, Bom::BOM_UTF16_LE, Bom::BOM_UTF32_BE, Bom::BOM_UTF32_LE], |
||
165 | $definition->getBoms(), |
||
166 | 'Bom should be reset to null' |
||
167 | ); |
||
168 | static::assertEquals( |
||
169 | 'UTF-8', |
||
170 | $definition->getEncoding(), |
||
171 | 'The encoding should be reset when no BOM is present' |
||
172 | ); |
||
173 | |||
174 | static::assertSame($definition, $definition->setEncoding('UTF-16'), 'setEncoding should be fluent'); |
||
175 | static::assertEquals('UTF-16', $definition->getEncoding(), 'The encoding should be set to UTF-16'); |
||
176 | } |
||
177 | |||
210 |