Skip to content

Commit 1575567

Browse files
- Use constructor property promotion
- Add Exception if no endpoint is set for socket
1 parent 804d0eb commit 1575567

File tree

7 files changed

+46
-250
lines changed

7 files changed

+46
-250
lines changed

Handler/ConsoleHandler.php

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,11 @@
1515

1616
class ConsoleHandler implements MagentoHandlerInterface
1717
{
18-
/**
19-
* @var string
20-
*/
21-
private $isEnabled;
22-
23-
/**
24-
* @var ScopeConfigInterface
25-
*/
26-
private $scopeConfig;
27-
28-
/**
29-
* @var string
30-
*/
31-
private $levelPath;
32-
3318
public function __construct(
34-
ScopeConfigInterface $scopeConfig,
35-
string $isEnabled,
36-
string $levelPath
19+
private ScopeConfigInterface $scopeConfig,
20+
private string $isEnabled,
21+
private string $levelPath
3722
) {
38-
$this->scopeConfig = $scopeConfig;
39-
$this->isEnabled = $isEnabled;
40-
$this->levelPath = $levelPath;
4123
}
4224

4325
/**

Handler/GelfHandler.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,12 @@
1515

1616
class GelfHandler implements MagentoHandlerInterface
1717
{
18-
/**
19-
* @var PublisherInterface
20-
*/
21-
private $publisher;
22-
23-
/**
24-
* @var string
25-
*/
26-
private $isEnabled;
27-
28-
/**
29-
* @var string
30-
*/
31-
private $levelPath;
32-
33-
/**
34-
* @var ScopeConfigInterface
35-
*/
36-
private $scopeConfig;
37-
3818
public function __construct(
39-
PublisherInterface $publisher,
40-
ScopeConfigInterface $scopeConfig,
41-
string $isEnabled,
42-
string $levelPath
19+
private PublisherInterface $publisher,
20+
private ScopeConfigInterface $scopeConfig,
21+
private string $isEnabled,
22+
private string $levelPath
4323
) {
44-
$this->publisher = $publisher;
45-
$this->isEnabled = $isEnabled;
46-
$this->levelPath = $levelPath;
47-
$this->scopeConfig = $scopeConfig;
4824
}
4925

5026
public function getInstance(): HandlerInterface

Handler/MailHandler.php

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,50 +14,14 @@
1414

1515
class MailHandler implements MagentoHandlerInterface
1616
{
17-
/**
18-
* @var ScopeConfigInterface
19-
*/
20-
private $scopeConfig;
21-
22-
/**
23-
* @var string
24-
*/
25-
private $isEnabled;
26-
27-
/**
28-
* @var string
29-
*/
30-
private $toPath;
31-
32-
/**
33-
* @var string
34-
*/
35-
private $subjectPath;
36-
37-
/**
38-
* @var string
39-
*/
40-
private $fromPath;
41-
42-
/**
43-
* @var string
44-
*/
45-
private $levelPath;
46-
4717
public function __construct(
48-
ScopeConfigInterface $scopeConfig,
49-
string $isEnabled,
50-
string $toPath,
51-
string $subjectPath,
52-
string $fromPath,
53-
string $levelPath
18+
private ScopeConfigInterface $scopeConfig,
19+
private string $isEnabled,
20+
private string $toPath,
21+
private string $subjectPath,
22+
private string $fromPath,
23+
private string $levelPath
5424
) {
55-
$this->scopeConfig = $scopeConfig;
56-
$this->isEnabled = $isEnabled;
57-
$this->toPath = $toPath;
58-
$this->subjectPath = $subjectPath;
59-
$this->fromPath = $fromPath;
60-
$this->levelPath = $levelPath;
6125
}
6226

6327
public function getInstance(): HandlerInterface

Handler/RotatingFileHandler.php

Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,50 +15,14 @@
1515

1616
class RotatingFileHandler implements MagentoHandlerInterface
1717
{
18-
/**
19-
* @var ScopeConfigInterface
20-
*/
21-
private $scopeConfig;
22-
23-
/**
24-
* @var DirectoryList
25-
*/
26-
private $directoryList;
27-
28-
/**
29-
* @var string
30-
*/
31-
private $isEnabled;
32-
33-
/**
34-
* @var string
35-
*/
36-
private $levelPath;
37-
38-
/**
39-
* @var string
40-
*/
41-
private $filenamePath;
42-
43-
/**
44-
* @var string
45-
*/
46-
private $maxFilesPath;
47-
4818
public function __construct(
49-
ScopeConfigInterface $scopeConfig,
50-
DirectoryList $directoryList,
51-
string $isEnabled,
52-
string $levelPath,
53-
string $filenamePath,
54-
string $maxFilesPath
19+
private ScopeConfigInterface $scopeConfig,
20+
private DirectoryList $directoryList,
21+
private string $isEnabled,
22+
private string $levelPath,
23+
private string $filenamePath,
24+
private string $maxFilesPath
5525
) {
56-
$this->scopeConfig = $scopeConfig;
57-
$this->directoryList = $directoryList;
58-
$this->isEnabled = $isEnabled;
59-
$this->levelPath = $levelPath;
60-
$this->filenamePath = $filenamePath;
61-
$this->maxFilesPath = $maxFilesPath;
6226
}
6327

6428
/**

Handler/SlackHandler.php

Lines changed: 11 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -15,85 +15,19 @@
1515

1616
class SlackHandler implements MagentoHandlerInterface
1717
{
18-
/**
19-
* @var ScopeConfigInterface
20-
*/
21-
private $scopeConfig;
22-
23-
/**
24-
* @var string
25-
*/
26-
private $isEnabled;
27-
28-
/**
29-
* @var string
30-
*/
31-
private $levelPath;
32-
33-
/**
34-
* @var string
35-
*/
36-
private $tokenPath;
37-
38-
/**
39-
* @var string
40-
*/
41-
private $channelPath;
42-
43-
/**
44-
* @var string
45-
*/
46-
private $usernamePath;
47-
48-
/**
49-
* @var string
50-
*/
51-
private $useAttachmentPath;
52-
53-
/**
54-
* @var string
55-
*/
56-
private $iconEmojiPath;
57-
58-
/**
59-
* @var string
60-
*/
61-
private $bubblePath;
62-
63-
/**
64-
* @var string
65-
*/
66-
private $useShortAttachmentPath;
67-
68-
/**
69-
* @var string
70-
*/
71-
private $includeContextAndExtraPath;
72-
7318
public function __construct(
74-
ScopeConfigInterface $scopeConfig,
75-
string $isEnabled,
76-
string $levelPath,
77-
string $tokenPath,
78-
string $channelPath,
79-
string $usernamePath,
80-
string $useAttachmentPath,
81-
string $iconEmojiPath,
82-
string $bubblePath,
83-
string $useShortAttachmentPath,
84-
string $includeContextAndExtraPath
19+
private ScopeConfigInterface $scopeConfig,
20+
private string $isEnabled,
21+
private string $levelPath,
22+
private string $tokenPath,
23+
private string $channelPath,
24+
private string $usernamePath,
25+
private string $useAttachmentPath,
26+
private string $iconEmojiPath,
27+
private string $bubblePath,
28+
private string $useShortAttachmentPath,
29+
private string $includeContextAndExtraPath
8530
) {
86-
$this->scopeConfig = $scopeConfig;
87-
$this->isEnabled = $isEnabled;
88-
$this->levelPath = $levelPath;
89-
$this->tokenPath = $tokenPath;
90-
$this->channelPath = $channelPath;
91-
$this->usernamePath = $usernamePath;
92-
$this->useAttachmentPath = $useAttachmentPath;
93-
$this->iconEmojiPath = $iconEmojiPath;
94-
$this->bubblePath = $bubblePath;
95-
$this->useShortAttachmentPath = $useShortAttachmentPath;
96-
$this->includeContextAndExtraPath = $includeContextAndExtraPath;
9731
}
9832

9933
/**

Handler/SocketHandler.php

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,50 +13,32 @@
1313
use Monolog\Handler\HandlerInterface;
1414
use Monolog\Handler\SocketHandler as MonologSocketHandler;
1515
use Monolog\Formatter\JsonFormatter;
16+
use RuntimeException;
1617

1718
class SocketHandler implements MagentoHandlerInterface
1819
{
19-
/**
20-
* @var string
21-
*/
22-
private $isEnabled;
23-
24-
/**
25-
* @var ScopeConfigInterface
26-
*/
27-
private $scopeConfig;
28-
29-
/**
30-
* @var string
31-
*/
32-
private $levelPath;
33-
34-
/**
35-
* @var string
36-
*/
37-
private $endpoint;
38-
3920
public function __construct(
40-
ScopeConfigInterface $scopeConfig,
41-
string $isEnabled,
42-
string $levelPath,
43-
string $endpoint
21+
private ScopeConfigInterface $scopeConfig,
22+
private string $isEnabled,
23+
private string $levelPath,
24+
private string $endpoint
4425
) {
45-
$this->scopeConfig = $scopeConfig;
46-
$this->isEnabled = $isEnabled;
47-
$this->levelPath = $levelPath;
48-
$this->endpoint = $endpoint;
4926
}
5027

5128
/**
52-
* @throws Exception
29+
* @throws RuntimeException
5330
*/
5431
public function getInstance(): HandlerInterface
5532
{
56-
$handler = new MonologSocketHandler(
57-
$this->scopeConfig->getValue($this->endpoint),
58-
$this->scopeConfig->getValue($this->levelPath)
59-
);
33+
$endpointUrl = trim((string) $this->scopeConfig->getValue($this->endpoint));
34+
if ($endpointUrl === '') {
35+
throw new RuntimeException(sprintf(
36+
'Config key "%s" is missing or empty.',
37+
$this->endpoint
38+
));
39+
}
40+
41+
$handler = new MonologSocketHandler($endpointUrl, $this->scopeConfig->getValue($this->levelPath));
6042
$handler->setFormatter(new JsonFormatter(JsonFormatter::BATCH_MODE_NEWLINES));
6143

6244
return $handler;

Plugin/MonologPlugin.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,11 @@
1313

1414
class MonologPlugin
1515
{
16-
/**
17-
* @var MagentoHandlerInterface[]
18-
*/
19-
private $magentoHandlers;
20-
2116
/**
2217
* @param MagentoHandlerInterface[] $magentoHandlers
2318
*/
24-
public function __construct(array $magentoHandlers)
19+
public function __construct(private array $magentoHandlers)
2520
{
26-
$this->magentoHandlers = $magentoHandlers;
2721
}
2822

2923
/**

0 commit comments

Comments
 (0)