Fix & clean up examples (#78)
This commit is contained in:
parent
32b8b2ea61
commit
8defd9b17f
4 changed files with 136 additions and 397 deletions
|
|
@ -13,17 +13,20 @@ namespace Mcp\Example\DependenciesStdioExample\Service;
|
|||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class InMemoryTaskRepository implements TaskRepositoryInterface
|
||||
/**
|
||||
* @phpstan-import-type Task from TaskRepositoryInterface
|
||||
*/
|
||||
final class InMemoryTaskRepository implements TaskRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @var array<int, Task>
|
||||
*/
|
||||
private array $tasks = [];
|
||||
|
||||
private int $nextTaskId = 1;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(LoggerInterface $logger)
|
||||
{
|
||||
$this->logger = $logger;
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
// Add some initial tasks
|
||||
$this->addTask('user1', 'Buy groceries');
|
||||
$this->addTask('user1', 'Write MCP example');
|
||||
|
|
|
|||
|
|
@ -13,5 +13,8 @@ namespace Mcp\Example\DependenciesStdioExample\Service;
|
|||
|
||||
interface StatsServiceInterface
|
||||
{
|
||||
/**
|
||||
* @return array<string, int>
|
||||
*/
|
||||
public function getSystemStats(): array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,13 +11,11 @@
|
|||
|
||||
namespace Mcp\Example\DependenciesStdioExample\Service;
|
||||
|
||||
class SystemStatsService implements StatsServiceInterface
|
||||
final class SystemStatsService implements StatsServiceInterface
|
||||
{
|
||||
private TaskRepositoryInterface $taskRepository;
|
||||
|
||||
public function __construct(TaskRepositoryInterface $taskRepository)
|
||||
{
|
||||
$this->taskRepository = $taskRepository;
|
||||
public function __construct(
|
||||
private readonly TaskRepositoryInterface $taskRepository,
|
||||
) {
|
||||
}
|
||||
|
||||
public function getSystemStats(): array
|
||||
|
|
|
|||
|
|
@ -11,12 +11,24 @@
|
|||
|
||||
namespace Mcp\Example\DependenciesStdioExample\Service;
|
||||
|
||||
/**
|
||||
* @phpstan-type Task array{id: int, userId: string, description: string, completed: bool, createdAt: string}
|
||||
*/
|
||||
interface TaskRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @return Task
|
||||
*/
|
||||
public function addTask(string $userId, string $description): array;
|
||||
|
||||
/**
|
||||
* @return Task[]
|
||||
*/
|
||||
public function getTasksForUser(string $userId): array;
|
||||
|
||||
/**
|
||||
* @return Task[]
|
||||
*/
|
||||
public function getAllTasks(): array;
|
||||
|
||||
public function completeTask(int $taskId): bool;
|
||||
|
|
|
|||
Loading…
Reference in a new issue