Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Dec 31, 2024
1 parent c2be8ec commit 21f28ad
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 21 deletions.
5 changes: 2 additions & 3 deletions src/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@

class Document
{
/** @var string */
private $content;
private string $content;

/** @var array<string, mixed> */
private $data;
private array $data;

/**
* @param array<string, mixed> $data
Expand Down
2 changes: 1 addition & 1 deletion src/FrontMatterChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

final class FrontMatterChain implements FrontMatterInterface
{
/** @var FrontMatterInterface[] */
/** @var list<FrontMatterInterface> */
private array $adapters = [];

public function __construct(iterable $adapters)
Expand Down
7 changes: 3 additions & 4 deletions src/Markdown/FrontMatterLeagueCommonMarkExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Webuni\FrontMatter\Markdown;

use Dflydev\DotAccessData\Data;
use Dflydev\DotAccessData\DataInterface;
use League\CommonMark\Environment\EnvironmentBuilderInterface;
use League\CommonMark\Event\DocumentPreParsedEvent;
use League\CommonMark\Extension\ExtensionInterface;
Expand All @@ -21,8 +21,7 @@

class FrontMatterLeagueCommonMarkExtension implements ExtensionInterface
{
/** @var FrontMatterInterface */
private $frontMatter;
private FrontMatterInterface $frontMatter;

public function __construct(FrontMatterInterface $frontMatter)
{
Expand All @@ -40,7 +39,7 @@ public function parse(DocumentPreParsedEvent $event): void
$document = $this->frontMatter->parse($content);
$data = $event->getDocument()->data;

$data->import($document->getData(), Data::MERGE);
$data->import($document->getData(), DataInterface::MERGE);
$event->replaceMarkdown(new MarkdownInput($document->getContent()));
}
}
4 changes: 2 additions & 2 deletions src/Processor/JsonWithoutBracesProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ final class JsonWithoutBracesProcessor implements ProcessorInterface
{
public function parse(string $string): array
{
if (false !== strpos($string, '":')) {
if (str_contains($string, '":')) {
$string = '{'.$string.'}';
}

Expand All @@ -31,7 +31,7 @@ public function dump(array $data): string

$result = (string) json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);

if ('{' === substr($result, 0, 1) && '}' === substr($result, -1)) {
if (str_starts_with($result, '{') && str_ends_with($result, '}')) {
$result = substr($result, 1, -1);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Twig/DataToTwigConvertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ public static function var(string $name, bool $force = true): self

/**
* @psalm-suppress MixedAssignment
*
* @param mixed $value
*/
protected static function valueToTwig($value): string
protected static function valueToTwig(mixed $value): string
{
if ($value instanceof \DateTimeInterface) {
return '('.$value->getTimestamp()."|date_modify('0sec'))";
Expand Down
11 changes: 3 additions & 8 deletions src/Twig/FrontMatterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,9 @@

class FrontMatterLoader implements LoaderInterface
{
/** @var LoaderInterface */
private $loader;

/** @var FrontMatterInterface */
private $parser;

/** @var DataToTwigConvertor */
private $convertor;
private LoaderInterface $loader;
private FrontMatterInterface $parser;
private DataToTwigConvertor $convertor;

public function __construct(
FrontMatterInterface $parser,
Expand Down

0 comments on commit 21f28ad

Please sign in to comment.