Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 30, 2020
1 parent e7df086 commit 38aed2f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

All notable changes to `simple-excel` will be documented in this file

## 1.12.0 - 2020-12-30

- add `headersToSnakeCase` and `formatHeadersUsing`

## 1.11.0 - 2020-12-29

- enable disabling BOM on writer (#48)
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ $rows = SimpleExcelReader::create($pathToCsv)

#### Manually formatting headers

You can use a custom formatter to change the headers using the ```formatHeaderUsing``` method and passing a closure.
You can use a custom formatter to change the headers using the `formatHeadersUsing` method and passing a closure.

```csv
email,first_name,last_name
Expand All @@ -158,7 +158,7 @@ [email protected],mary jane,doe

```php
$rows = SimpleExcelReader::create($pathToCsv)
->formatHeaderUsing(fn($header) => "{$header}_simple_excel")
->formatHeadersUsing(fn($header) => "{$header}_simple_excel")
->getRows()
->each(function(array $rowProperties) {
// ['email_simple_excel' => 'john@example', 'first_name_simple_excel' => 'John', 'last_name_simple_excel' => 'doe']
Expand Down
10 changes: 5 additions & 5 deletions src/SimpleExcelReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SimpleExcelReader

protected ?string $trimHeaderCharacters = null;

protected ?Closure $formatHeaderUsing = null;
protected ?Closure $formatHeadersUsing = null;

protected int $skip = 0;

Expand Down Expand Up @@ -82,9 +82,9 @@ public function trimHeaderRow(string $characters = null): self
return $this;
}

public function formatHeaderUsing(callable $callback): self
public function formatHeadersUsing(callable $callback): self
{
$this->formatHeaderUsing = $callback;
$this->formatHeadersUsing = $callback;

return $this;
}
Expand Down Expand Up @@ -169,8 +169,8 @@ protected function processHeaderRow(array $headers): array
$headers = $this->convertHeaders([$this, 'toSnakecase'], $headers);
}

if ($this->formatHeaderUsing) {
$headers = $this->convertHeaders($this->formatHeaderUsing, $headers);
if ($this->formatHeadersUsing) {
$headers = $this->convertHeaders($this->formatHeadersUsing, $headers);
}

return $headers;
Expand Down
2 changes: 1 addition & 1 deletion tests/SimpleExcelReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ public function it_can_convert_headers_to_snake_case()
public function it_can_use_custom_header_row_formatter()
{
$rows = SimpleExcelReader::create($this->getStubPath('header-and-rows.csv'))
->formatHeaderUsing(function ($header) {
->formatHeadersUsing(function ($header) {
return $header . '_suffix';
})
->getRows()
Expand Down

0 comments on commit 38aed2f

Please sign in to comment.