[PR #801] [MERGED] Add fluent setters for parameters in the slack handler #1356

Closed
opened 2026-03-04 03:10:37 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Seldaek/monolog/pull/801
Author: @EspadaV8
Created: 5/31/2016
Status: Merged
Merged: 7/6/2019
Merged by: @Seldaek

Base: masterHead: add-fluent-setters-for-slack-handler


📝 Commits (1)

  • c9d15bb Add fluent setters for parameters in the slack handler

📊 Changes

2 files changed (+210 additions, -17 deletions)

View changed files

📝 src/Monolog/Handler/Slack/SlackRecord.php (+122 -17)
📝 src/Monolog/Handler/SlackHandler.php (+88 -0)

📄 Description

The current slack handler has way too many constructor parameters and no clear order as to their position. This makes it confusing to work out what is actually trying to be set when constructing a new class, e.g,

$slack = new SlackHandler(
    'xoxp-0000000000-1111111111-22222222222-3333333333',
    '#general',
    'Monolog',
    false,
    null,
    Logger::ERROR,
    true,
    false,
    true
);

This PR makes things a bit easier by adding some fluent setters into the class.

$slack = new SlackHandler(
        'xoxp-0000000000-1111111111-22222222222-3333333333',
        '#general',
        'Monolog'
    )
    ->setErrorLevel(Logger::ERROR)
    ->useAttachment(false)
    ->includeContextAndExtra(true);

It would be nice to cut back the number of constructor parameters and reorder them to make a bit more sense

// Current
public function __construct(
    $token,
    $channel,
    $username = 'Monolog',
    $useAttachment = true,
    $iconEmoji = null,
    $level = Logger::CRITICAL,
    $bubble = true,
    $useShortAttachment = false,
    $includeContextAndExtra = false
)

// Proposed
public function __construct(
    $token,
    $channel,
    $username = 'Monolog',
    $level = Logger::CRITICAL,
    $bubble = true
)

Since that would be a fairly major breaking change though I've not included it in this PR. If it would be okay to do in another PR I'll open one up for it.

I've included scalar type hints for the methods because the file include the declare(strict_types=1); which is only valid for PHP7 so I assume that is okay. If not then I can easily remove them.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Seldaek/monolog/pull/801 **Author:** [@EspadaV8](https://github.com/EspadaV8) **Created:** 5/31/2016 **Status:** ✅ Merged **Merged:** 7/6/2019 **Merged by:** [@Seldaek](https://github.com/Seldaek) **Base:** `master` ← **Head:** `add-fluent-setters-for-slack-handler` --- ### 📝 Commits (1) - [`c9d15bb`](https://github.com/Seldaek/monolog/commit/c9d15bb8086fcde0a537cf6352072c9d5cdc5d74) Add fluent setters for parameters in the slack handler ### 📊 Changes **2 files changed** (+210 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `src/Monolog/Handler/Slack/SlackRecord.php` (+122 -17) 📝 `src/Monolog/Handler/SlackHandler.php` (+88 -0) </details> ### 📄 Description The current slack handler has way too many constructor parameters and no clear order as to their position. This makes it confusing to work out what is actually trying to be set when constructing a new class, e.g, ``` php $slack = new SlackHandler( 'xoxp-0000000000-1111111111-22222222222-3333333333', '#general', 'Monolog', false, null, Logger::ERROR, true, false, true ); ``` This PR makes things a bit easier by adding some fluent setters into the class. ``` php $slack = new SlackHandler( 'xoxp-0000000000-1111111111-22222222222-3333333333', '#general', 'Monolog' ) ->setErrorLevel(Logger::ERROR) ->useAttachment(false) ->includeContextAndExtra(true); ``` It would be nice to cut back the number of constructor parameters and reorder them to make a bit more sense ``` php // Current public function __construct( $token, $channel, $username = 'Monolog', $useAttachment = true, $iconEmoji = null, $level = Logger::CRITICAL, $bubble = true, $useShortAttachment = false, $includeContextAndExtra = false ) // Proposed public function __construct( $token, $channel, $username = 'Monolog', $level = Logger::CRITICAL, $bubble = true ) ``` Since that would be a fairly major breaking change though I've not included it in this PR. If it would be okay to do in another PR I'll open one up for it. I've included scalar type hints for the methods because the file include the `declare(strict_types=1);` which is only valid for PHP7 so I assume that is okay. If not then I can easily remove them. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 03:10:37 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#1356
No description provided.