Skip to content

Commit

Permalink
Use @return $this where applicable (#1828)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas authored Aug 3, 2023
1 parent e239236 commit 9546d94
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/Monolog/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function __construct(
* @param array<int, LogLevel::*>|false $errorLevelMap an array of E_* constant to LogLevel::* constant mapping, or false to disable error handling
* @param array<class-string, LogLevel::*>|false $exceptionLevelMap an array of class name to LogLevel::* constant mapping, or false to disable exception handling
* @param LogLevel::*|null|false $fatalLevel a LogLevel::* constant, null to use the default LogLevel::ALERT or false to disable fatal error handling
* @return ErrorHandler
* @return static
*/
public static function register(LoggerInterface $logger, $errorLevelMap = [], $exceptionLevelMap = [], $fatalLevel = null): self
{
Expand Down Expand Up @@ -126,6 +126,7 @@ public function registerErrorHandler(array $levelMap = [], bool $callPrevious =
/**
* @param LogLevel::*|null $level a LogLevel::* constant, null to use the default LogLevel::ALERT
* @param int $reservedMemorySize Amount of KBs to reserve in memory so that it can be freed when handling fatal errors giving Monolog some room in memory to get its job done
* @return $this
*/
public function registerFatalHandler($level = null, int $reservedMemorySize = 20): self
{
Expand Down
3 changes: 3 additions & 0 deletions src/Monolog/Formatter/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ public function formatBatch(array $records): string
};
}

/**
* @return $this
*/
public function includeStacktraces(bool $include = true): self
{
$this->includeStacktraces = $include;
Expand Down
9 changes: 9 additions & 0 deletions src/Monolog/Formatter/LineFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public function __construct(?string $format = null, ?string $dateFormat = null,
parent::__construct($dateFormat);
}

/**
* @return $this
*/
public function includeStacktraces(bool $include = true, ?Closure $parser = null): self
{
$this->includeStacktraces = $include;
Expand All @@ -60,13 +63,19 @@ public function includeStacktraces(bool $include = true, ?Closure $parser = null
return $this;
}

/**
* @return $this
*/
public function allowInlineLineBreaks(bool $allow = true): self
{
$this->allowInlineLineBreaks = $allow;

return $this;
}

/**
* @return $this
*/
public function ignoreEmptyContextAndExtra(bool $ignore = true): self
{
$this->ignoreEmptyContextAndExtra = $ignore;
Expand Down
6 changes: 6 additions & 0 deletions src/Monolog/Formatter/LogmaticFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@ class LogmaticFormatter extends JsonFormatter

protected string $appName = '';

/**
* @return $this
*/
public function setHostname(string $hostname): self
{
$this->hostname = $hostname;

return $this;
}

/**
* @return $this
*/
public function setAppName(string $appName): self
{
$this->appName = $appName;
Expand Down
1 change: 0 additions & 1 deletion src/Monolog/Formatter/MongoDBFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ private function legacyGetMongoDbDateTime(\DateTimeInterface $value): UTCDateTim
? (int) $milliseconds
: (string) $milliseconds;

// @phpstan-ignore-next-line
return new UTCDateTime($milliseconds);
}
}
17 changes: 17 additions & 0 deletions src/Monolog/Formatter/NormalizerFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public function getDateFormat(): string
return $this->dateFormat;
}

/**
* @return $this
*/
public function setDateFormat(string $dateFormat): self
{
$this->dateFormat = $dateFormat;
Expand All @@ -93,6 +96,9 @@ public function getMaxNormalizeDepth(): int
return $this->maxNormalizeDepth;
}

/**
* @return $this
*/
public function setMaxNormalizeDepth(int $maxNormalizeDepth): self
{
$this->maxNormalizeDepth = $maxNormalizeDepth;
Expand All @@ -108,6 +114,9 @@ public function getMaxNormalizeItemCount(): int
return $this->maxNormalizeItemCount;
}

/**
* @return $this
*/
public function setMaxNormalizeItemCount(int $maxNormalizeItemCount): self
{
$this->maxNormalizeItemCount = $maxNormalizeItemCount;
Expand All @@ -117,6 +126,8 @@ public function setMaxNormalizeItemCount(int $maxNormalizeItemCount): self

/**
* Enables `json_encode` pretty print.
*
* @return $this
*/
public function setJsonPrettyPrint(bool $enable): self
{
Expand Down Expand Up @@ -289,13 +300,19 @@ protected function formatDate(\DateTimeInterface $date): string
return $date->format($this->dateFormat);
}

/**
* @return $this
*/
public function addJsonEncodeOption(int $option): self
{
$this->jsonEncodeOptions |= $option;

return $this;
}

/**
* @return $this
*/
public function removeJsonEncodeOption(int $option): self
{
$this->jsonEncodeOptions &= ~$option;
Expand Down
2 changes: 2 additions & 0 deletions src/Monolog/Handler/AbstractHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function isHandling(LogRecord $record): bool
* Sets minimum logging level at which this handler will be triggered.
*
* @param Level|LogLevel::* $level Level or level name
* @return $this
*
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
*/
Expand All @@ -74,6 +75,7 @@ public function getLevel(): Level
*
* @param bool $bubble true means that this handler allows bubbling.
* false means that bubbling is not permitted.
* @return $this
*/
public function setBubble(bool $bubble): self
{
Expand Down
1 change: 1 addition & 0 deletions src/Monolog/Handler/FilterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function getAcceptedLevels(): array
/**
* @param int|string|Level|LogLevel::*|array<int|string|Level|LogLevel::*> $minLevelOrList A list of levels to accept or a minimum level or level name if maxLevel is provided
* @param int|string|Level|LogLevel::* $maxLevel Maximum level or level name to accept, only used if $minLevelOrList is not an array
* @return $this
*
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::*|array<value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::*> $minLevelOrList
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $maxLevel
Expand Down
2 changes: 2 additions & 0 deletions src/Monolog/Handler/LogglyHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private function loadCurlHandle(string $endpoint): CurlHandle

/**
* @param string[]|string $tag
* @return $this
*/
public function setTag(string|array $tag): self
{
Expand All @@ -103,6 +104,7 @@ public function setTag(string|array $tag): self

/**
* @param string[]|string $tag
* @return $this
*/
public function addTag(string|array $tag): self
{
Expand Down
6 changes: 6 additions & 0 deletions src/Monolog/Handler/NativeMailerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function __construct(string|array $to, string $subject, string $from, int
* Add headers to the message
*
* @param string|string[] $headers Custom added headers
* @return $this
*/
public function addHeader($headers): self
{
Expand All @@ -96,6 +97,7 @@ public function addHeader($headers): self
* Add parameters to the message
*
* @param string|string[] $parameters Custom added parameters
* @return $this
*/
public function addParameter($parameters): self
{
Expand Down Expand Up @@ -142,6 +144,7 @@ public function getEncoding(): string

/**
* @param string $contentType The content type of the email - Defaults to text/plain. Use text/html for HTML messages.
* @return $this
*/
public function setContentType(string $contentType): self
{
Expand All @@ -154,6 +157,9 @@ public function setContentType(string $contentType): self
return $this;
}

/**
* @return $this
*/
public function setEncoding(string $encoding): self
{
if (strpos($encoding, "\n") !== false || strpos($encoding, "\r") !== false) {
Expand Down
4 changes: 4 additions & 0 deletions src/Monolog/Handler/PushoverHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ protected function write(LogRecord $record): void

/**
* @param int|string|Level|LogLevel::* $level
* @return $this
*
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
*/
Expand All @@ -220,6 +221,7 @@ public function setHighPriorityLevel(int|string|Level $level): self

/**
* @param int|string|Level|LogLevel::* $level
* @return $this
*
* @phpstan-param value-of<Level::VALUES>|value-of<Level::NAMES>|Level|LogLevel::* $level
*/
Expand All @@ -232,6 +234,8 @@ public function setEmergencyLevel(int|string|Level $level): self

/**
* Use the formatted message?
*
* @return $this
*/
public function useFormattedMessage(bool $useFormattedMessage): self
{
Expand Down
3 changes: 3 additions & 0 deletions src/Monolog/Handler/RotatingFileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public function reset(): void
}
}

/**
* @return $this
*/
public function setFilenameFormat(string $filenameFormat, string $dateFormat): self
{
$this->setDateFormat($dateFormat);
Expand Down
22 changes: 18 additions & 4 deletions src/Monolog/Handler/Slack/SlackRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ public function stringify(array $fields): string
* Channel used by the bot when posting
*
* @param ?string $channel
*
* @return static
* @return $this
*/
public function setChannel(?string $channel = null): self
{
Expand All @@ -235,8 +234,7 @@ public function setChannel(?string $channel = null): self
* Username used by the bot when posting
*
* @param ?string $username
*
* @return static
* @return $this
*/
public function setUsername(?string $username = null): self
{
Expand All @@ -245,13 +243,19 @@ public function setUsername(?string $username = null): self
return $this;
}

/**
* @return $this
*/
public function useAttachment(bool $useAttachment = true): self
{
$this->useAttachment = $useAttachment;

return $this;
}

/**
* @return $this
*/
public function setUserIcon(?string $userIcon = null): self
{
$this->userIcon = $userIcon;
Expand All @@ -263,13 +267,19 @@ public function setUserIcon(?string $userIcon = null): self
return $this;
}

/**
* @return $this
*/
public function useShortAttachment(bool $useShortAttachment = false): self
{
$this->useShortAttachment = $useShortAttachment;

return $this;
}

/**
* @return $this
*/
public function includeContextAndExtra(bool $includeContextAndExtra = false): self
{
$this->includeContextAndExtra = $includeContextAndExtra;
Expand All @@ -283,6 +293,7 @@ public function includeContextAndExtra(bool $includeContextAndExtra = false): se

/**
* @param string[] $excludeFields
* @return $this
*/
public function excludeFields(array $excludeFields = []): self
{
Expand All @@ -291,6 +302,9 @@ public function excludeFields(array $excludeFields = []): self
return $this;
}

/**
* @return $this
*/
public function setFormatter(?FormatterInterface $formatter = null): self
{
$this->formatter = $formatter;
Expand Down
17 changes: 17 additions & 0 deletions src/Monolog/Handler/SlackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ public function getFormatter(): FormatterInterface

/**
* Channel used by the bot when posting
*
* @return $this
*/
public function setChannel(string $channel): self
{
Expand All @@ -202,6 +204,8 @@ public function setChannel(string $channel): self

/**
* Username used by the bot when posting
*
* @return $this
*/
public function setUsername(string $username): self
{
Expand All @@ -210,27 +214,39 @@ public function setUsername(string $username): self
return $this;
}

/**
* @return $this
*/
public function useAttachment(bool $useAttachment): self
{
$this->slackRecord->useAttachment($useAttachment);

return $this;
}

/**
* @return $this
*/
public function setIconEmoji(string $iconEmoji): self
{
$this->slackRecord->setUserIcon($iconEmoji);

return $this;
}

/**
* @return $this
*/
public function useShortAttachment(bool $useShortAttachment): self
{
$this->slackRecord->useShortAttachment($useShortAttachment);

return $this;
}

/**
* @return $this
*/
public function includeContextAndExtra(bool $includeContextAndExtra): self
{
$this->slackRecord->includeContextAndExtra($includeContextAndExtra);
Expand All @@ -240,6 +256,7 @@ public function includeContextAndExtra(bool $includeContextAndExtra): self

/**
* @param string[] $excludeFields
* @return $this
*/
public function excludeFields(array $excludeFields): self
{
Expand Down
Loading

0 comments on commit 9546d94

Please sign in to comment.