Skip to content

Commit

Permalink
improve api
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Jan 8, 2025
1 parent 5c108ec commit fe3328b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/ControllerName.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ControllerName implements ControllerNameInterface
{
use ControllerNameTrait;

private function interface(): string
public static function interface(): string
{
return ControllerInterface::class;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/ControllerNameTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(
/** @var class-string */
private string $name
) {
if ($this->isSubclassOf($this->interface())) {
if ($this->isSubclassOf($this::interface())) {
return;
}

Expand All @@ -45,5 +45,5 @@ public function isSubclassOf(string $class): bool
return is_subclass_of($this->name, $class, true);
}

abstract private function interface(): string;
abstract public static function interface(): string;
}
7 changes: 7 additions & 0 deletions tests/ControllerNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
namespace Chevere\Tests;

use Chevere\Action\ControllerName;
use Chevere\Action\Interfaces\ControllerInterface;
use Chevere\Tests\src\ControllerNameTestController;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;

final class ControllerNameTest extends TestCase
{
public function testInterface(): void
{
$interface = ControllerName::interface();
$this->assertSame(ControllerInterface::class, $interface);
}

public function testWrongInterface(): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down

0 comments on commit fe3328b

Please sign in to comment.