Skip to content

Commit

Permalink
Fix: Rename ParsedContent to Parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Jul 4, 2023
1 parent c6d4869 commit 7c8c666
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 89 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Expand Up @@ -14,7 +14,6 @@ For a full diff see [`2.1.0...main`][2.1.0...main].
- Renamed `Parsed::fromFrontMatterAndContent()` to `Parsed::create()` ([#397]), by [@localheinz]
- Renamed `Content` to `BodyMatter` and `Parsed::content()` to `Parsed::bodyMatter()` ([#398]), by [@localheinz]
- Extracted `Content` as a value object ([#399]), by [@localheinz]
- Renamed `Parsed` to `ParsedContent` ([#400]), by [@localheinz]
- Renamed `Content` to `UnparsedContent` ([#407]), by [@localheinz]

## [`2.1.0`][2.1.0]
Expand Down
10 changes: 5 additions & 5 deletions README.md
Expand Up @@ -71,8 +71,8 @@ $parser = new FrontMatter\YamlParser();

$unparsedContentWithoutFrontMatter = FrontMatter\UnparsedContent::fromString('Hello, how are you today?');

/** @var FrontMatter\ParsedContent $parsedContentWithoutFrontMatter */
$parsedContentWithoutFrontMatter = $parser->parse($unparsedContentWithoutFrontMatter);
/** @var FrontMatter\Parsed $parsedWithoutFrontMatter */
$parsedWithoutFrontMatter = $parser->parse($unparsedContentWithoutFrontMatter);

$unparsedContentWithFrontMatter = FrontMatter\UnparsedContent::fromString(
<<<TXT
Expand All @@ -84,13 +84,13 @@ page:
TXT
);

/** @var FrontMatter\ParsedContent $parsedContentWithFrontMatter */
$parsedContentWithFrontMatter = $parser->parse($unparsedContentWithoutFrontMatter);
/** @var FrontMatter\Parsed $parsedWithFrontMatter */
$parsedWithFrontMatter = $parser->parse($unparsedContentWithoutFrontMatter);
```

:exclamation: The `YamlParser` will throw an [`Ergebnis\FrontMatter\Exception\FrontMatterCanNotBeParsed`](src/Exception/FrontMatterCanNotBeParsed.php) exception when the front matter is invalid YAML and an [`Ergebnis\FrontMatter\Exception\FrontMatterIsNotAnObject`](src/Exception/FrontMatterIsNotAnObject.php) exception when the front matter does not describe an object.

:bulb: The `YamlParser` returns an [`Ergebnis\FrontMatter\Parsed`](src/ParsedContent.php) value object on success, regardless of whether the value has front matter or not.
:bulb: The `YamlParser` returns an [`Ergebnis\FrontMatter\Parsed`](src/Parsed.php) value object on success, regardless of whether the value has front matter or not.

## Changelog

Expand Down
2 changes: 1 addition & 1 deletion src/ParsedContent.php → src/Parsed.php
Expand Up @@ -16,7 +16,7 @@
/**
* @psalm-immutable
*/
final class ParsedContent
final class Parsed
{
private function __construct(
private readonly FrontMatter $frontMatter,
Expand Down
2 changes: 1 addition & 1 deletion src/Parser.php
Expand Up @@ -21,5 +21,5 @@ public function hasFrontMatter(UnparsedContent $content): bool;
* @throws Exception\FrontMatterIsNotAnObject
* @throws Exception\FrontMatterCanNotBeParsed
*/
public function parse(UnparsedContent $unparsedContent): ParsedContent;
public function parse(UnparsedContent $unparsedContent): Parsed;
}
8 changes: 4 additions & 4 deletions src/YamlParser.php
Expand Up @@ -25,10 +25,10 @@ public function hasFrontMatter(UnparsedContent $content): bool
return 1 === \preg_match(self::PATTERN, $content->toString());
}

public function parse(UnparsedContent $unparsedContent): ParsedContent
public function parse(UnparsedContent $unparsedContent): Parsed
{
if (1 !== \preg_match(self::PATTERN, $unparsedContent->toString(), $matches)) {
return ParsedContent::create(
return Parsed::create(
FrontMatter::empty(),
BodyMatter::fromString($unparsedContent->toString()),
);
Expand All @@ -39,7 +39,7 @@ public function parse(UnparsedContent $unparsedContent): ParsedContent
$rawFrontMatter = $matches['frontMatter'];

if ('' === $rawFrontMatter) {
return ParsedContent::create(
return Parsed::create(
FrontMatter::empty(),
$bodyMatter,
);
Expand All @@ -61,7 +61,7 @@ public function parse(UnparsedContent $unparsedContent): ParsedContent
throw Exception\FrontMatterIsNotAnObject::create();
}

return ParsedContent::create(
return Parsed::create(
$frontMatter,
$bodyMatter,
);
Expand Down
14 changes: 7 additions & 7 deletions test/Unit/ParsedContentTest.php → test/Unit/ParsedTest.php
Expand Up @@ -15,18 +15,18 @@

use Ergebnis\FrontMatter\BodyMatter;
use Ergebnis\FrontMatter\FrontMatter;
use Ergebnis\FrontMatter\ParsedContent;
use Ergebnis\FrontMatter\Parsed;
use Ergebnis\FrontMatter\Test;
use PHPUnit\Framework;

#[Framework\Attributes\CoversClass(ParsedContent::class)]
#[Framework\Attributes\CoversClass(Parsed::class)]
#[Framework\Attributes\UsesClass(BodyMatter::class)]
#[Framework\Attributes\UsesClass(FrontMatter::class)]
final class ParsedContentTest extends Framework\TestCase
final class ParsedTest extends Framework\TestCase
{
use Test\Util\Helper;

public function testCreateReturnsParsedContent(): void
public function testCreateReturnsParsed(): void
{
$faker = self::faker();

Expand All @@ -38,12 +38,12 @@ public function testCreateReturnsParsedContent(): void

$bodyMatter = BodyMatter::fromString($faker->realText());

$parsedContent = ParsedContent::create(
$parsed = Parsed::create(
$frontMatter,
$bodyMatter,
);

self::assertSame($frontMatter, $parsedContent->frontMatter());
self::assertSame($bodyMatter, $parsedContent->bodyMatter());
self::assertSame($frontMatter, $parsed->frontMatter());
self::assertSame($bodyMatter, $parsed->bodyMatter());
}
}

0 comments on commit 7c8c666

Please sign in to comment.