Skip to content

Commit 40bc2e6

Browse files
committed
Changed prefix preserve to include in new methods
1 parent 1fdeafa commit 40bc2e6

File tree

7 files changed

+61
-61
lines changed

7 files changed

+61
-61
lines changed

CHANGELOG.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ All Notable changes to `Csv` will be documented in this file
77
### Added
88

99
- Adding support for controlling empty record presence in `Reader::getRecords` return value.
10-
- `Reader::preserveEmptyRecord`
11-
- `Reader::skipEmptyRecord`
12-
- `Reader::isEmptyRecordSkipped`
10+
- `Reader::includeEmptyRecords`
11+
- `Reader::skipEmptyRecords`
12+
- `Reader::isEmptyRecordsIncluded`
1313

1414
- Adding support for controlling Input BOM usage in the library:
1515
- `AbstractCsv::skipInputBOM`
16-
- `AbstractCsv::preserveInputBOM`
17-
- `AbstractCsv::isInputBOMSkipped`
16+
- `AbstractCsv::includeInputBOM`
17+
- `AbstractCsv::isInputBOMIncluded`
1818

1919
### Deprecated
2020

docs/9.0/connections/bom.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ $bom = $csv->getOutputBOM(); //returns "\xEF\xBB\xBF"
8282

8383
~~~php
8484
AbstractCsv::skipInputBOM(): self;
85-
AbstractCsv::preserveInputBOM(): self;
86-
AbstractCsv::isInputBOMSkipped(): bool;
85+
AbstractCsv::includeInputBOM(): self;
86+
AbstractCsv::isInputBOMIncluded(): bool;
8787
~~~
8888

8989
- `skipInputBOM`: enables skipping the input BOM from your CSV document.
90-
- `preserveInputBOM`: preserves the input BOM from your CSV document while accessing its content.
91-
- `isInputBOMSkipped`: tells whether skipping the input BOM will be done.
90+
- `includeInputBOM`: preserves the input BOM from your CSV document while accessing its content.
91+
- `isInputBOMIncluded`: tells whether skipping or including the input BOM will be done.
9292

9393
<p class="message-notice">By default and to avoid BC Break, the Input BOM is skipped.</p>
9494

@@ -99,7 +99,7 @@ If your document does not contains any BOM sequence you can speed up the CSV ite
9999
$raw_csv = Reader::BOM_UTF8."john,doe,[email protected]\njane,doe,[email protected]\n";
100100
$csv = Reader::createFromString($raw_csv);
101101
$csv->setOutputBOM(Reader::BOM_UTF16_BE);
102-
$csv->preserveInputBOM();
102+
$csv->includeInputBOM();
103103
ob_start();
104104
$csv->output();
105105
$document = ob_get_clean();

docs/9.0/reader/index.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,14 @@ foreach ($records as $offset => $record) {
212212
By default the CSV document normalization removes empty records. But you can control the presence of such records using the following methods:
213213

214214
~~~php
215-
Reader::skipEmptyRecord(): self;
216-
Reader::preserveEmptyRecord(): self;
217-
Reader::isEmptyRecordSkipped(): bool;
215+
Reader::skipEmptyRecords(): self;
216+
Reader::includeEmptyRecords(): self;
217+
Reader::isEmptyRecordsIncluded(): bool;
218218
~~~
219219

220-
- Calling `Reader::preserveEmptyRecord` will ensure empty records are left in the `Iterator` returned by `Reader::getRecords`,
221-
conversely `Reader::skipEmptyRecord` will ensure empty records are skipped.
222-
- At any given time you can ask you Reader instance if empty records will be stripped using the `Reader::isEmptyRecordSkipped` method.
220+
- Calling `Reader::includeEmptyRecords` will ensure empty records are left in the `Iterator` returned by `Reader::getRecords`,
221+
conversely `Reader::skipEmptyRecords` will ensure empty records are skipped.
222+
- At any given time you can ask you Reader instance if empty records will be stripped or included using the `Reader::isEmptyRecordsIncluded` method.
223223
- If no header offset is specified, the empty record will be represented by a empty `array`, conversely,
224224
for consistency, an empty record will be represented by an array filled with `null` values as expected from header presence normalization.
225225

@@ -237,15 +237,15 @@ $source = <<<EOF
237237
EOF;
238238

239239
$reader = Reader::createFromString($source);
240-
$reader->isEmptyRecordSkipped(); // return true;
240+
$reader->isEmptyRecordsIncluded(); // return true;
241241
iterator_to_array($reader, true);
242242
// [
243243
// 0 => ['parent name', 'child name', 'title'],
244244
// 3 => ['parentA', 'childA', 'titleA'],
245245
// ];
246246

247-
$reader->preserveEmptyRecord();
248-
$reader->isEmptyRecordSkipped(); // return false;
247+
$reader->includeEmptyRecords();
248+
$reader->isEmptyRecordsIncluded(); // return false;
249249
iterator_to_array($reader, true);
250250
// [
251251
// 0 => ['parent name', 'child name', 'title'],
@@ -262,8 +262,8 @@ iterator_to_array($reader, true);
262262
// 3 => ['parent name' => 'parentA', 'child name' => 'childA', 'title' => 'titleA'],
263263
// ];
264264

265-
$reader->skipEmptyRecord();
266-
$reader->isEmptyRecordSkipped(); // return true;
265+
$reader->skipEmptyRecords();
266+
$reader->isEmptyRecordsIncluded(); // return false;
267267
$res = iterator_to_array($reader, true);
268268
// [
269269
// 3 => ['parent name' => 'parentA', 'child name' => 'childA', 'title' => 'titleA'],
@@ -300,11 +300,11 @@ If empty record are to be preserved, the number of records will be affected.
300300
use League\Csv\Reader;
301301

302302
$reader = Reader::createFromPath('/path/to/my/file-with-two-empty-records.csv', 'r');
303-
$reader->isEmptyRecordSkipped(); //returns true
303+
$reader->isEmptyRecordsIncluded(); //returns false
304304
count($records); // returns 2
305305

306-
$reader->preserveEmptyRecords();
307-
$reader->isEmptyRecordSkipped(); //returns false
306+
$reader->includeEmptyRecordss();
307+
$reader->isEmptyRecordsIncluded(); //returns true
308308
count($records); // returns 4
309309
~~~
310310

src/AbstractCsv.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ abstract class AbstractCsv implements ByteSequence
8989
protected $document;
9090

9191
/**
92-
* Tells whether the Input BOM must be stripped.
92+
* Tells whether the Input BOM must be included or skipped.
9393
*
9494
* @var bool
9595
*/
96-
protected $is_input_bom_skipped = true;
96+
protected $is_input_bom_included = false;
9797

9898
/**
9999
* New instance.
@@ -257,9 +257,9 @@ public function hasStreamFilter(string $filtername): bool
257257
/**
258258
* Tells whether the BOM can be stripped if presents.
259259
*/
260-
public function isInputBOMSkipped(): bool
260+
public function isInputBOMIncluded(): bool
261261
{
262-
return $this->is_input_bom_skipped;
262+
return $this->is_input_bom_included;
263263
}
264264

265265
/**
@@ -327,7 +327,7 @@ public function output(string $filename = null): int
327327
}
328328

329329
$this->document->rewind();
330-
if ($this->is_input_bom_skipped) {
330+
if (!$this->is_input_bom_included) {
331331
$this->document->fseek(strlen($this->getInputBOM()));
332332
}
333333

@@ -445,7 +445,7 @@ public function setEscape(string $escape): self
445445
*/
446446
public function skipInputBOM(): self
447447
{
448-
$this->is_input_bom_skipped = true;
448+
$this->is_input_bom_included = false;
449449

450450
return $this;
451451
}
@@ -455,9 +455,9 @@ public function skipInputBOM(): self
455455
*
456456
* @return static
457457
*/
458-
public function preserveInputBOM(): self
458+
public function includeInputBOM(): self
459459
{
460-
$this->is_input_bom_skipped = false;
460+
$this->is_input_bom_included = true;
461461

462462
return $this;
463463
}

src/Reader.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Reader extends AbstractCsv implements Countable, IteratorAggregate, JsonSe
7979
/**
8080
* @var bool
8181
*/
82-
protected $is_empty_records_skipped = true;
82+
protected $is_empty_records_included = false;
8383

8484
/**
8585
* {@inheritdoc}
@@ -270,11 +270,11 @@ public function getRecords(array $header = []): Iterator
270270
{
271271
$header = $this->computeHeader($header);
272272
$normalized = function ($record): bool {
273-
return is_array($record) && (!$this->is_empty_records_skipped || $record != [null]);
273+
return is_array($record) && ($this->is_empty_records_included || $record != [null]);
274274
};
275275

276276
$bom = '';
277-
if ($this->is_input_bom_skipped) {
277+
if (!$this->is_input_bom_included) {
278278
$bom = $this->getInputBOM();
279279
}
280280

@@ -286,7 +286,7 @@ public function getRecords(array $header = []): Iterator
286286
});
287287
}
288288

289-
if (!$this->is_empty_records_skipped) {
289+
if ($this->is_empty_records_included) {
290290
$normalized_empty_records = static function (array $record): array {
291291
if ([null] === $record) {
292292
return [];
@@ -402,10 +402,10 @@ public function setHeaderOffset($offset): self
402402
/**
403403
* Enable skipping empty records.
404404
*/
405-
public function skipEmptyRecord(): self
405+
public function skipEmptyRecords(): self
406406
{
407-
if (!$this->is_empty_records_skipped) {
408-
$this->is_empty_records_skipped = true;
407+
if ($this->is_empty_records_included) {
408+
$this->is_empty_records_included = false;
409409
$this->nb_records = -1;
410410
}
411411

@@ -415,10 +415,10 @@ public function skipEmptyRecord(): self
415415
/**
416416
* Disable skipping empty records.
417417
*/
418-
public function preserveEmptyRecord(): self
418+
public function includeEmptyRecords(): self
419419
{
420-
if ($this->is_empty_records_skipped) {
421-
$this->is_empty_records_skipped = false;
420+
if (!$this->is_empty_records_included) {
421+
$this->is_empty_records_included = true;
422422
$this->nb_records = -1;
423423
}
424424

@@ -428,8 +428,8 @@ public function preserveEmptyRecord(): self
428428
/**
429429
* Tells whether empty records are skipped by the instance.
430430
*/
431-
public function isEmptyRecordSkipped(): bool
431+
public function isEmptyRecordsIncluded(): bool
432432
{
433-
return $this->is_empty_records_skipped;
433+
return $this->is_empty_records_included;
434434
}
435435
}

tests/CsvTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -461,18 +461,18 @@ public function testGetPathnameWithTempFile()
461461
}
462462

463463
/**
464-
* @covers ::isInputBOMSkipped
465-
* @covers ::preserveInputBOM
464+
* @covers ::isInputBOMIncluded
465+
* @covers ::includeInputBOM
466466
* @covers ::skipInputBOM
467467
*/
468468
public function testBOMStripping()
469469
{
470470
$reader = Reader::createFromString();
471-
self::assertTrue($reader->isInputBOMSkipped());
472-
$reader->preserveInputBOM();
473-
self::assertFalse($reader->isInputBOMSkipped());
471+
self::assertFalse($reader->isInputBOMIncluded());
472+
$reader->includeInputBOM();
473+
self::assertTrue($reader->isInputBOMIncluded());
474474
$reader->skipInputBOM();
475-
self::assertTrue($reader->isInputBOMSkipped());
475+
self::assertFalse($reader->isInputBOMIncluded());
476476
}
477477

478478
/**
@@ -490,7 +490,7 @@ public function testOutputDoesNotStripBOM()
490490
self::assertNotContains(Reader::BOM_UTF8, $result);
491491
self::assertContains(Reader::BOM_UTF16_BE, $result);
492492

493-
$csv->preserveInputBOM();
493+
$csv->includeInputBOM();
494494
ob_start();
495495
$csv->output();
496496
$result = ob_get_clean();

tests/ReaderTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public function testDisablingBOMStripping()
334334
$fp = fopen('php://temp', 'r+');
335335
fputcsv($fp, $expected_record);
336336
$csv = Reader::createFromStream($fp);
337-
$csv->preserveInputBOM();
337+
$csv->includeInputBOM();
338338
self::assertSame(Reader::BOM_UTF16_LE, $csv->getInputBOM());
339339
foreach ($csv as $offset => $record) {
340340
self::assertSame($expected_record, $record);
@@ -476,9 +476,9 @@ public function testCreateFromPath()
476476

477477
/**
478478
* @dataProvider sourceProvider
479-
* @covers ::preserveEmptyRecord
480-
* @covers ::skipEmptyRecord
481-
* @covers ::isEmptyRecordSkipped
479+
* @covers ::includeEmptyRecords
480+
* @covers ::skipEmptyRecords
481+
* @covers ::isEmptyRecordsIncluded
482482
* @covers ::getRecords
483483
*/
484484
public function testSkippingEmptyRecords(
@@ -488,28 +488,28 @@ public function testSkippingEmptyRecords(
488488
array $expected_with_skipping_with_header,
489489
array $expected_with_preserving_with_header
490490
) {
491-
self::assertTrue($reader->isEmptyRecordSkipped());
491+
self::assertFalse($reader->isEmptyRecordsIncluded());
492492
self::assertSame(count($expected_with_skipping), count($reader));
493493
foreach ($reader as $offset => $record) {
494494
self::assertSame($expected_with_skipping[$offset], $record);
495495
}
496496

497-
$reader->preserveEmptyRecord();
498-
self::assertFalse($reader->isEmptyRecordSkipped());
497+
$reader->includeEmptyRecords();
498+
self::assertTrue($reader->isEmptyRecordsIncluded());
499499
self::assertSame(count($expected_with_preserving), count($reader));
500500
foreach ($reader as $offset => $record) {
501501
self::assertSame($expected_with_preserving[$offset], $record);
502502
}
503503

504504
$reader->setHeaderOffset(0);
505-
self::assertFalse($reader->isEmptyRecordSkipped());
505+
self::assertTrue($reader->isEmptyRecordsIncluded());
506506
self::assertSame(count($expected_with_preserving_with_header), count($reader));
507507
foreach ($reader as $offset => $record) {
508508
self::assertSame($expected_with_preserving_with_header[$offset], $record);
509509
}
510510

511-
$reader->skipEmptyRecord();
512-
self::assertTrue($reader->isEmptyRecordSkipped());
511+
$reader->skipEmptyRecords();
512+
self::assertFalse($reader->isEmptyRecordsIncluded());
513513
self::assertSame(count($expected_with_skipping_with_header), count($reader));
514514
foreach ($reader as $offset => $record) {
515515
self::assertSame($expected_with_skipping_with_header[$offset], $record);

0 commit comments

Comments
 (0)