Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Markdown helper #179

Merged
merged 20 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"illuminate/testing": "^10.34.0|^11.0.0",
"illuminate/translation": "^10.34.0|^11.0.0",
"illuminate/validation": "^10.34.0|^11.0.0",
"league/commonmark": "^2.4",
"league/commonmark": "^2.5.1",
"league/config": "^1.1.1",
"mockery/mockery": "^1.6.5",
"nikic/php-parser": "^4.18|^5.0",
"nuwave/lighthouse": "^6.5.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/documentator/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
},
"require": {
"php": "^8.2|^8.3",
"ext-filter": "*",
"ext-mbstring": "*",
"composer/semver": "^3.2",
"illuminate/contracts": "^10.34.0|^11.0.0",
"illuminate/console": "^10.34.0|^11.0.0",
"illuminate/process": "^10.34.0|^11.0.0",
"illuminate/support": "^10.34.0|^11.0.0",
"league/commonmark": "^2.4",
"league/commonmark": "^2.5.1",
"league/config": "^1.1.1",
"nikic/php-parser": "^4.18|^5.0",
"phpstan/phpdoc-parser": "^1.25",
"symfony/console": "^6.3.0|^7.0.0",
Expand Down
49 changes: 49 additions & 0 deletions packages/documentator/src/Markdown/Data/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Documentator\Markdown\Data;

use League\CommonMark\Node\Node;

use function is_a;
use function is_object;

/**
* @internal
*/
class Data {
/**
* @template T
*
* @param class-string<Value<T>> $data
*
* @return ?T
*/
public static function get(Node $node, string $data): mixed {
$value = $node->data->get($data, null);
$value = is_object($value) && is_a($value, $data, true)
? $value->get()
: null;

return $value;
}

/**
* @template T
*
* @param Value<T> $value
*
* @return T
*/
public static function set(Node $node, mixed $value): mixed {
$node->data->set($value::class, $value);

return $value->get();
}

/**
* @param class-string<Value<*>> $data
*/
public static function remove(Node $node, string $data): void {
$node->data->remove($data);
}
}
37 changes: 37 additions & 0 deletions packages/documentator/src/Markdown/Data/Lines.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Documentator\Markdown\Data;

use League\CommonMark\Input\MarkdownInputInterface;
use Override;

use function iterator_to_array;

/**
* @implements Value<array<array-key, string>>
* @internal
*/
class Lines implements Value {
/**
* @var array<array-key, string>|null
*/
private ?array $lines = null;

public function __construct(
private readonly MarkdownInputInterface $input,
) {
// empty
}

/**
* @inheritDoc
*/
#[Override]
public function get(): array {
if ($this->lines === null) {
$this->lines = iterator_to_array($this->input->getLines());
}

return $this->lines;
}
}
23 changes: 23 additions & 0 deletions packages/documentator/src/Markdown/Data/Location.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Documentator\Markdown\Data;

use LastDragon_ru\LaraASP\Documentator\Markdown\Location\Location as LocationContract;
use Override;

/**
* @internal
* @implements Value<LocationContract>
*/
readonly class Location implements Value {
public function __construct(
private LocationContract $location,
) {
// empty
}

#[Override]
public function get(): mixed {
return $this->location;
}
}
22 changes: 22 additions & 0 deletions packages/documentator/src/Markdown/Data/Offset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Documentator\Markdown\Data;

use Override;

/**
* @internal
* @implements Value<int>
*/
readonly class Offset implements Value {
public function __construct(
private int $value,
) {
// empty
}

#[Override]
public function get(): mixed {
return $this->value;
}
}
22 changes: 22 additions & 0 deletions packages/documentator/src/Markdown/Data/Padding.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Documentator\Markdown\Data;

use Override;

/**
* @internal
* @implements Value<int>
*/
readonly class Padding implements Value {
public function __construct(
private int $value,
) {
// empty
}

#[Override]
public function get(): mixed {
return $this->value;
}
}
14 changes: 14 additions & 0 deletions packages/documentator/src/Markdown/Data/Value.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php declare(strict_types = 1);

namespace LastDragon_ru\LaraASP\Documentator\Markdown\Data;

/**
* @template TValue
* @internal
*/
interface Value {
/**
* @return TValue
*/
public function get(): mixed;
}
Loading
Loading