Skip to content

Commit

Permalink
Add a helper for getting the since value.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbillion committed Sep 8, 2024
1 parent 407b652 commit 39a7667
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Doc.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ public function getParams(): array {
return $this->tags->getParams();
}

public function getSince(): string {
return $this->tags->getSince();
}

public function getReturnTypeString(): ?string {
return $this->tags->getReturnTypeString();
}
Expand Down
16 changes: 16 additions & 0 deletions src/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ public function getParams(): array {
return $this->getByType( 'param' );
}

public function getSince(): string {
foreach ( $this->tags as $tag ) {
if ( $tag->getName() === 'since' ) {
$since = $tag->getContent();

if ( strpos( $since, 'MU' ) !== false ) {
$since = '3.0.0';
}

return $since;
}
}

return '';
}

/**
* @return array<int, Tag>
* @phpstan-return list<Tag>
Expand Down
9 changes: 9 additions & 0 deletions tests/phpunit/HooksTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ public function testCanCountParams(): void {
self::assertSame( 2, $count );
}

public function testCanGetSince(): void {
$hooks = $this->getFilters();
$hook = $hooks->find( 'wp_tag_cloud' );

$since = $hook->getDoc()->getSince();

Check failure on line 98 in tests/phpunit/HooksTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Cannot call method getDoc() on WPHooks\Hook|null.

Check failure on line 98 in tests/phpunit/HooksTest.php

View workflow job for this annotation

GitHub Actions / PHP 7.4

Cannot call method getDoc() on WPHooks\Hook|null.

self::assertSame( '2.3.0', $since );
}

/**
* @return array<string, array<int, string>>
* @phpstan-return array{
Expand Down

0 comments on commit 39a7667

Please sign in to comment.