Skip to content

Commit

Permalink
Prepare next release
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Sep 26, 2023
1 parent ea07f8a commit 556a8a1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All Notable changes to `bakame/html-table` will be documented in this file.

## [Next](https://github.com/bakame-php/http-structured-fields/compare/0.1.0...master) - TBD
## [0.2.0](https://github.com/bakame-php/html-table/compare/0.1.0...0.2.0) - 2023-09-26

### Added

Expand All @@ -14,6 +14,7 @@ All Notable changes to `bakame/html-table` will be documented in this file.

- Add support for table `rowspan` attribute
- Renamed `Section` enum values. The Enum is no longer a backed enum.
- Renamed `Parser::parseHTML` into `Parser::parseHtml` for consistency

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use Bakame\HtmlTable\Parser;

$parser = Parser::new();

$table = $parser->parseHTML('<table>...</table>');
$table = $parser->parseHtml('<table>...</table>');
$table = $parser->parseFile('path/to/html/file.html');
```

Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
"require": {
"php": "^8.1.2",
"ext-dom": "*",
"ext-libxml": "*",
"ext-simplexml": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"league/csv": "^9.6.0"
},
"require-dev": {
"ext-xdebug": "*",
"friendsofphp/php-cs-fixer": "^v3.22.0",
"phpstan/phpstan": "^1.10.26",
"phpstan/phpstan-deprecation-rules": "^1.1.3",
"phpstan/phpstan-phpunit": "^1.3.13",
"friendsofphp/php-cs-fixer": "^v3.28.0",
"phpstan/phpstan": "^1.10.35",
"phpstan/phpstan-deprecation-rules": "^1.1.4",
"phpstan/phpstan-phpunit": "^1.3.14",
"phpstan/phpstan-strict-rules": "^1.5.1",
"phpunit/phpunit": "^10.3.1",
"symfony/var-dumper": "^6.3.3"
"phpunit/phpunit": "^10.3.5",
"symfony/var-dumper": "^6.3.4"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 3 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function withoutFormatter(): self
public function parseFile(mixed $filenameOrStream, $filenameContext = null): TabularDataReader
{
if (is_resource($filenameOrStream)) {
return $this->parseHTML($this->streamToString($filenameOrStream));
return $this->parseHtml($this->streamToString($filenameOrStream));
}

set_error_handler(fn (int $errno, string $errstr, string $errfile, int $errline) => true);
Expand All @@ -332,14 +332,14 @@ public function parseFile(mixed $filenameOrStream, $filenameContext = null): Tab
$html = $this->streamToString($resource);
fclose($resource);

return $this->parseHTML($html);
return $this->parseHtml($html);
}

/**
* @throws ParserError
* @throws SyntaxError
*/
public function parseHTML(DOMDocument|DOMElement|SimpleXMLElement|Stringable|string $source): TabularDataReader
public function parseHtml(DOMDocument|DOMElement|SimpleXMLElement|Stringable|string $source): TabularDataReader
{
/** @var DOMNodeList<DOMElement> $query */
$query = (new DOMXPath($this->sourceToDomDocument($source)))->query($this->expression);
Expand Down
28 changes: 14 additions & 14 deletions src/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function it_will_throw_if_the_table_header_row_offset_is_negative(): void
#[Test]
public function it_can_load_the_first_html_table_found_by_default(): void
{
$table = Parser::new()->parseHTML(self::HTML);
$table = Parser::new()->parseHtml(self::HTML);

self::assertSame(['prenoms', 'nombre', 'sexe', 'annee'], $table->getHeader());
self::assertCount(4, $table);
Expand All @@ -115,7 +115,7 @@ public function it_can_load_the_first_html_table_found_by_default(): void
#[Test]
public function it_can_load_the_first_html_table_found_by_default_without_the_header(): void
{
$table = Parser::new()->ignoreTableHeader()->parseHTML(self::HTML);
$table = Parser::new()->ignoreTableHeader()->parseHtml(self::HTML);

self::assertSame([], $table->getHeader());
self::assertCount(4, $table);
Expand Down Expand Up @@ -197,7 +197,7 @@ public function it_uses_the_table_first_tr_in_the_first_tbody_to_search_for_the_

$table = Parser::new()
->tableHeaderPosition(Section::tbody)
->parseHTML($html);
->parseHtml($html);

self::assertSame(['prenoms', 'nombre', 'sexe', 'annee'], $table->getHeader());
self::assertCount(5, $table);
Expand All @@ -214,15 +214,15 @@ public function it_will_throw_if_the_html_is_malformed(): void
{
$this->expectExceptionObject(new ParserError('The HTML table could not be found in the submitted html.'));

Parser::new()->parseHTML('vasdfadadf');
Parser::new()->parseHtml('vasdfadadf');
}

#[Test]
public function it_will_throw_if_no_table_is_found(): void
{
$this->expectExceptionObject(new ParserError('The HTML table could not be found in the submitted html.'));

Parser::new()->parseHTML('<ol><li>foo</li></ol>');
Parser::new()->parseHtml('<ol><li>foo</li></ol>');
}

#[Test]
Expand All @@ -231,7 +231,7 @@ public function it_will_use_the_submitted_headers(): void
$parser = Parser::new()
->tableHeader(['firstname', 'count', 'gender', 'year']);

$table = $parser->parseHTML(self::HTML);
$table = $parser->parseHtml(self::HTML);

self::assertSame(['firstname', 'count', 'gender', 'year'], $table->getHeader());
self::assertSame($this->getNthRecord($table), [
Expand All @@ -256,7 +256,7 @@ public function it_will_duplicate_colspan_data(): void
</table>
TABLE;

$table = Parser::new()->parseHTML($html);
$table = Parser::new()->parseHtml($html);

self::assertSame($this->getNthRecord($table, 1), ['Abdoulaye', 'Abdoulaye', 'Abdoulaye', '2004']);
self::assertSame($this->getNthRecord($table), ['prenoms', 'nombre', 'sexe', 'annee']);
Expand All @@ -279,7 +279,7 @@ public function it_will_ignore_the_malformed_header_by_deault(): void
$dom = new DOMDocument();
$dom->loadHTML($html);

$table = Parser::new()->parseHTML($dom);
$table = Parser::new()->parseHtml($dom);

self::assertSame([], $table->getHeader());
self::assertSame($this->getNthRecord($table), ['Abdoulaye', 'Abdoulaye', 'Abdoulaye', '2004']);
Expand All @@ -297,15 +297,15 @@ public function it_will_fails_on_malformed_html(): void

Parser::new()
->failOnXmlErrors()
->parseHTML($html);
->parseHtml($html);
}

#[Test]
public function it_will_fail_to_load_other_html_tag(): void
{
$this->expectException(ParserError::class);

Parser::new()->parseHTML(new DOMElement('p', 'I know who you are'));
Parser::new()->parseHtml(new DOMElement('p', 'I know who you are'));
}

#[Test]
Expand All @@ -323,7 +323,7 @@ public function it_will_found_no_header(): void

$table = Parser::new()
->tableHeaderPosition(Section::tbody)
->parseHTML($simpleXML);
->parseHtml($simpleXML);

self::assertSame([], $table->getHeader());
}
Expand All @@ -342,7 +342,7 @@ public function it_will_found_no_header_in_any_section(): void

$table = Parser::new()
->tableHeaderPosition(Section::none)
->parseHTML($html);
->parseHtml($html);

self::assertSame([], $table->getHeader());
}
Expand All @@ -365,7 +365,7 @@ public function it_will_use_the_table_footer(): void

$table = Parser::new()
->excludeTableFooter()
->parseHTML($html);
->parseHtml($html);

self::assertSame([], $table->getHeader());
self::assertSame([], $this->getNthRecord($table));
Expand Down Expand Up @@ -448,7 +448,7 @@ public function it_can_handle_rowspan_and_colspan(): void
TABLE;

$reducer = fn (TabularDataReader $reader, string $value): int => array_reduce([...$reader], fn (int $carry, array $record): int => $carry + (array_count_values($record)[$value] ?? 0), 0);
$table = Parser::new()->parseHTML($table);
$table = Parser::new()->parseHtml($table);

self::assertSame(2, $reducer($table, 'colspan'));
self::assertSame(2, $reducer($table, 'rowspan'));
Expand Down

0 comments on commit 556a8a1

Please sign in to comment.