Skip to content

Commit

Permalink
添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
何平 committed Jan 4, 2024
1 parent d6afca8 commit 6109006
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 10 deletions.
5 changes: 4 additions & 1 deletion cloud-admin/Annotation/EnumMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#[Attribute(Attribute::TARGET_CLASS_CONSTANT)]
final class EnumMessage extends AbstractAnnotation
{
/** @noinspection PhpMissingParentConstructorInspection */
/**
* @param string $message
* @phpstan-param string $message
*/
public function __construct(public readonly string $message = '') {}
}
5 changes: 4 additions & 1 deletion cloud-admin/Annotation/HttpCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
#[Attribute(Attribute::TARGET_CLASS_CONSTANT)]
final class HttpCode extends AbstractAnnotation
{
/** @noinspection PhpMissingParentConstructorInspection */
/**
* @param int $code
* @phpstan-param int $code
*/
public function __construct(public readonly int $code = Status::OK) {}
}
12 changes: 12 additions & 0 deletions cloud-admin/Context/Coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,33 @@
use Hyperf\Context\Context;
use Hyperf\Contract\StdoutLoggerInterface;
use Hyperf\Engine\Coroutine as Co;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerInterface;
use Throwable;

final class Coroutine
{
/**
* @var LoggerInterface|StdoutLoggerInterface|mixed $logger
*/
private readonly LoggerInterface $logger;

/**
* @param ContainerInterface $container
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function __construct(protected ContainerInterface $container)
{
$this->logger = $container->get(StdoutLoggerInterface::class);
}

/**
* @phpstan-return int
* @phpstan-param callable $callable
* @return int Returns the coroutine ID of the coroutine just created.
* Returns -1 when coroutine create failed.
*/
Expand Down
12 changes: 10 additions & 2 deletions cloud-admin/Interfaces/LockInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@

interface LockInterface
{
public function lock();
/**
* @return mixed
* @phpstan-return mixed
*/
public function lock():mixed;

public function unlock();
/**
* @return bool
* @phpstan-return bool
*/
public function unlock():bool;
}
11 changes: 6 additions & 5 deletions cloud-admin/Interfaces/RedisLockInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface RedisLockInterface
* get lock,This method will return fasle directly after the lock is failed.
*
* @param string $key lock unique identifier
*
* @phpstan-return bool
* @throws Throwable
*/
public function tryLock(string $key, int $ttl = 3): bool;
Expand All @@ -30,7 +30,7 @@ public function tryLock(string $key, int $ttl = 3): bool;
* @param string $key lock unique identifier
*
* @param int $retries number of retries
*
* @phpstan-return bool
* @throws Throwable
*/
public function lock(
Expand All @@ -42,26 +42,27 @@ public function lock(

/**
* release lock.
*
* @phpstan-return bool
* @throws Throwable
*/
public function unLock(): bool;

/**
* get lock life ttl.
* @phpstan-return int
*/
public function lockTtl(): int;

/**
* Let the lock last for N seconds, the default N is 3.
*
* @phpstan-return bool
* @throws Throwable
*/
public function keepAlive(int $ttl = 3): bool;

/**
* check if the lock is valid.
*
* @phpstan-return bool
* @throws Throwable
*/
public function isAlive(): bool;
Expand Down
2 changes: 1 addition & 1 deletion cloud-admin/Interfaces/WatchDogInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface WatchDogInterface
/**
* watchdog sentinel automatic renewal mechanism
* Return true if the task completed successfully.
*
* @phpstan-return bool
* @throws Throwable
*/
public function sentinel(RedisLockInterface $lock, int $time = 60): bool;
Expand Down
1 change: 1 addition & 0 deletions cloud-admin/Log/LoggerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
final class LoggerFactory
{
/**
* @phpstan-return LoggerInterface|void
* @return LoggerInterface|void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
Expand Down
19 changes: 19 additions & 0 deletions cloud-admin/Log/SwowSocketHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,23 @@ public function __construct(
$this->style = new Style();
}

/**
* @param LogRecord $record
* @return void
* @phpstan-param LogRecord $record
*/
protected function write(LogRecord $record): void
{
$this->buffer->append($this->formatStdoutLogText($record));
$this->output->send($this->buffer->toString());
$this->buffer->clear();
}

/**
* @param string $level
* @return Color
* @phpstan-return Color
*/
protected function getColorFromLevel(string $level = LogLevel::DEBUG): Color
{
return match ($level) {
Expand All @@ -63,6 +73,12 @@ protected function getColorFromLevel(string $level = LogLevel::DEBUG): Color
};
}

/**
* @param LogRecord $record
* @return string
* @phpstan-param LogRecord $record
* @phpstan-return string
*/
protected function formatStdoutLogText(LogRecord $record): string
{
$message = '';
Expand Down Expand Up @@ -99,6 +115,9 @@ protected function formatStdoutLogText(LogRecord $record): string
'datetime' => 'int',
'extra' => 'int',
])]
/**
* @phpstan-return array<string, int>
*/
protected function toPsrLogRecordColor(): array
{
return [
Expand Down

0 comments on commit 6109006

Please sign in to comment.