Skip to content

Commit

Permalink
refactor: apply phpstan rules
Browse files Browse the repository at this point in the history
  • Loading branch information
lefuturiste committed Feb 12, 2024
1 parent c1f95f9 commit 754beb1
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ To run the example, you need:

- `composer install`
- `cp .env.example .env`
- `composer test`, be aware: tests are a little specials, they are requiring env vars
- ~~`composer test`~~, for now we don't have unit tests.
- run `vendor/bin/phpstan analyse src -l 6` to run the static analyzer.

#### TODO

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
},
"require-dev": {
"phpunit/phpunit": "^8.2",
"vlucas/phpdotenv": "^3.4"
"vlucas/phpdotenv": "^3.4",
"phpstan/phpstan": "^1.10"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 5 additions & 8 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Config

protected int $maxMessageLength = 255;

/** @var string[] **/
protected array $webHooks = [];

protected string $template = "**[{datetime}]** {name}.{subName}.__{levelName}__: {message}";
Expand All @@ -33,10 +34,6 @@ class Config
*/
public function getClient(): Client
{
if (!$this->client) {
$this->client = new Client();
}

return $this->client;
}

Expand Down Expand Up @@ -122,7 +119,7 @@ public function isMultiMsg(): bool
* @see isMultiMsg()
* @see setMaxMessageLength()
*/
public function setMultiMsg(int $multiMsg): self
public function setMultiMsg(bool $multiMsg): self
{
$this->multiMsg = $multiMsg;

Expand All @@ -136,7 +133,7 @@ public function setMultiMsg(int $multiMsg): self
*
* @see getMaxMessageLength()
*/
public function setMaxMessageLength(int $maxMessageLength): self
public function setMaxMessageLength(int|null $maxMessageLength): self
{
if (!is_null($maxMessageLength)) {
if (!is_int($maxMessageLength)) {
Expand Down Expand Up @@ -182,15 +179,15 @@ public function getWebHooks(): array
}

/**
* @param string|string[] $webHooks
* @param string[] $webHooks
*
* @return Config
*
* @see getWebHooks()
*/
public function setWebHooks(array $webHooks): self
{
$this->webHooks = (array)$webHooks;
$this->webHooks = $webHooks;

return $this;
}
Expand Down
7 changes: 4 additions & 3 deletions src/DiscordHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DiscordHandler extends AbstractProcessingHandler
/**
* DiscordHandler constructor.
*
* @param array|string $webHooks
* @param string[]|string $webHook
* @param string $name
* @param string $subName
* @param Level $level
Expand Down Expand Up @@ -59,7 +59,7 @@ public function setConfig(Config $config): self
}

/**
* @param array $record
* @param LogRecord $record
*
* @throws GuzzleException
* @return void
Expand Down Expand Up @@ -131,10 +131,11 @@ protected function splitMessage(string $content): array

/**
* @param string $webHook
* @param string $json
* @param array $json
*
* @throws GuzzleException
*/
/** @phpstan-ignore-next-line */
protected function send(string $webHook, array $json): void
{
$this->config->getClient()->request('POST', $webHook, [
Expand Down

0 comments on commit 754beb1

Please sign in to comment.