Skip to content

Commit

Permalink
添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
何平 committed Jan 22, 2024
1 parent e7307a8 commit 5317055
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
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-param ContainerInterface $container
* @phpstan-return LoggerInterface|void
* @return LoggerInterface|void
* @throws ContainerExceptionInterface
Expand Down
15 changes: 15 additions & 0 deletions cloud-admin/Log/SwowSocketHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@

final class SwowSocketHandler extends AbstractProcessingHandler
{
/**
* @phpstan-var Socket Socket
*/
protected Socket $output;

/**
* @phpstan-var Buffer Buffer
*/
protected Buffer $buffer;

/**
* @phpstan-var Style $style
*/
protected Style $style;

/**
* @phpstan-param int|Level|string $level
* @phpstan-param bool $bubble
* @phpstan-param bool $useLocking
*/
public function __construct(
int|Level|string $level = Level::Debug,
bool $bubble = true,
Expand All @@ -55,6 +69,7 @@ protected function write(LogRecord $record): void
}

/**
* @phpstan-param LogRecord $record
* @phpstan-return Color
*/
protected function getColorFromLevel(string $level = LogLevel::DEBUG): Color
Expand Down
13 changes: 13 additions & 0 deletions cloud-admin/Middleware/ProfilerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@

final class ProfilerMiddleware implements MiddlewareInterface
{
/**
* @phpstan-param ContainerInterface $container
* @phpstan-param ConfigInterface $config
*/
public function __construct(protected readonly ContainerInterface $container, protected readonly ConfigInterface $config) {}

/**
* @phpstan-param ServerRequestInterface $request
* @phpstan-param RequestHandlerInterface $handler
* @phpstan-return ResponseInterface
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$time = microtime();
Expand All @@ -60,6 +69,10 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @phpstan-param string $startTime
* @phpstan-param ServerRequestInterface|null $request
* @phpstan-param ResponseInterface|null $response
* @phpstan-return bool
*/
private function logAndSave(string $startTime, ?ServerRequestInterface $request, ?ResponseInterface $response): bool
{
Expand Down
30 changes: 30 additions & 0 deletions cloud-admin/Model/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class Model extends BaseModel

protected ?string $dateFormat = 'Y-m-d H:i:s';

/**
* @phpstan-param array $condition
* @phpstan-param array $field
* @phpstan-param bool $forUpdate
* @phpstan-return Builder|HyperfModel|null
*/
public static function findOne(array $condition, array $field = ['*'], bool $forUpdate = false): null|Builder|HyperfModel
{
$query = self::buildByCondition($condition);
Expand All @@ -40,11 +46,20 @@ public static function findOne(array $condition, array $field = ['*'], bool $for
return $query->first($field);
}

/**
* @phpstan-param int $id
* @phpstan-param array $field
* @phpstan-return Builder|HyperfModel|null
*/
public static function one(int $id, array $field = ['*']): null|Builder|HyperfModel
{
return self::findOne(['id' => $id], $field);
}

/**
* @phpstan-param array $condition
* @phpstan-return Builder
*/
public static function buildByCondition(array $condition): Builder
{
$query = self::query();
Expand All @@ -62,18 +77,33 @@ public static function buildByCondition(array $condition): Builder
return $query;
}

/**
* @phpstan-param array $condition
* @phpstan-param array $data
* @phpstan-return int
*/
public static function updateCondition(array $condition, array $data): int
{
$query = self::buildByCondition($condition);
return $query->update($data);
}

/**
* @phpstan-param array $condition
* @phpstan-return int
*/
public static function countCondition(array $condition): int
{
$query = self::buildByCondition($condition);
return $query->count();
}

/**
* @phpstan-param Builder $model
* @phpstan-param string $field
* @phpstan-param array $createTime
* @phpstan-return void
*/
public static function betweenTime(Builder $model, string $field, array $createTime): void
{
$model->where(function (Builder $builder) use ($field, $createTime) {
Expand Down
14 changes: 14 additions & 0 deletions cloud-admin/RateLimit/TokenBucket.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ final class TokenBucket

private readonly Channel $channel;

/**
* @phpstan-param int $capacity
* @phpstan-param int $tokenRate
*/
public function __construct(private readonly int $capacity, private int $tokenRate)
{
$this->tokens = $capacity;
Expand All @@ -56,6 +60,9 @@ public function acquireToken(): void
}
}

/**
* @phpstan-return void
*/
private function runTicker(): void
{
if (! $this->tickerRunning) {
Expand All @@ -72,11 +79,18 @@ private function runTicker(): void
}
}

/**
* @phpstan-param int $tokenRate
* @phpstan-return void
*/
private function setTokenRate(int $tokenRate): void
{
$this->tokenRate = $tokenRate;
}

/**
* @phpstan-return void
*/
private function addTokens(): void
{
$now = microtime(true);
Expand Down

0 comments on commit 5317055

Please sign in to comment.