Skip to content

Commit a65589e

Browse files
committed
Code cleanup
1 parent ba11cb8 commit a65589e

13 files changed

+68
-167
lines changed

Block/Adminhtml/System/Config/Form/Field/Type.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212

1313
class Type extends AbstractFieldArray
1414
{
15-
protected function _construct()
15+
protected function _prepareToRender(): void
1616
{
1717
$this->addColumn('custom_logger_key', ['label' => __('Logger key')]);
1818
$this->addColumn('custom_logger_value', ['label' => __('Logger value')]);
1919
$this->_addAfter = false;
2020
$this->_addButtonLabel = __('Add');
21-
parent::_construct();
2221
}
2322
}

Config/Config.php

-17
This file was deleted.

Config/CustomConfiguration.php

-48
This file was deleted.

Handler/ConsoleHandler.php

+2-5
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ public function __construct(
4545
*/
4646
public function getInstance(): HandlerInterface
4747
{
48-
return new StreamHandler(
49-
'php://stdout',
50-
$this->scopeConfig->getValue($this->levelPath)
51-
);
48+
return new StreamHandler('php://stdout', $this->scopeConfig->getValue($this->levelPath));
5249
}
5350

5451
public function isEnabled(): bool
5552
{
56-
return (bool)$this->scopeConfig->getValue($this->isEnabled);
53+
return $this->scopeConfig->isSetFlag($this->isEnabled);
5754
}
5855
}

Handler/GelfHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ public function getInstance(): HandlerInterface
5757

5858
public function isEnabled(): bool
5959
{
60-
return (bool)$this->scopeConfig->getValue($this->isEnabled);
60+
return $this->scopeConfig->isSetFlag($this->isEnabled);
6161
}
6262
}

Handler/MailHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ public function getInstance(): HandlerInterface
7272

7373
public function isEnabled(): bool
7474
{
75-
return (bool)$this->scopeConfig->getValue($this->isEnabled);
75+
return $this->scopeConfig->isSetFlag($this->isEnabled);
7676
}
7777
}

Handler/RotatingFileHandler.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ public function getInstance(): HandlerInterface
7979

8080
public function isEnabled(): bool
8181
{
82-
return (bool)$this->scopeConfig->getValue($this->isEnabled);
82+
return $this->scopeConfig->isSetFlag($this->isEnabled);
8383
}
84-
}
84+
}

Handler/SlackHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,6 @@ public function getInstance(): HandlerInterface
116116

117117
public function isEnabled(): bool
118118
{
119-
return (bool)$this->scopeConfig->getValue($this->isEnabled);
119+
return $this->scopeConfig->isSetFlag($this->isEnabled);
120120
}
121121
}

Plugin/MonologPlugin.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* See COPYING.txt for license details.
55
*/
66

7+
declare(strict_types=1);
8+
79
namespace Opengento\Logger\Plugin;
810

911
use Magento\Framework\Logger\Monolog;
@@ -18,8 +20,7 @@ public function aroundSetHandlers(Monolog $subject, callable $proceed, array $ha
1820
foreach ($handlers as $handler) {
1921
if ($handler instanceof MagentoHandlerInterface && $handler->isEnabled()) {
2022
$magentoHandlers[] = $handler->getInstance();
21-
}
22-
if ($handler instanceof HandlerInterface) {
23+
} elseif ($handler instanceof HandlerInterface) {
2324
$magentoHandlers[] = $handler;
2425
}
2526
}

Processor/CustomContextProcessor.php

+21-13
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,42 @@
88

99
namespace Opengento\Logger\Processor;
1010

11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Serialize\Serializer\Json;
13+
use Magento\Store\Model\ScopeInterface;
1114
use Monolog\Processor\ProcessorInterface;
12-
use Opengento\Logger\Config\Config;
13-
use Opengento\Logger\Config\CustomConfiguration;
1415

1516
class CustomContextProcessor implements ProcessorInterface
1617
{
1718
/**
18-
* @var CustomConfiguration
19+
* @var ScopeConfigInterface
1920
*/
20-
private $customConfiguration;
21+
private $scopeConfig;
2122

22-
public function __construct(CustomConfiguration $customConfiguration)
23+
/**
24+
* @var Json
25+
*/
26+
private $serializer;
27+
28+
public function __construct(ScopeConfigInterface $scopeConfig, Json $serializer)
2329
{
24-
$this->customConfiguration = $customConfiguration;
30+
$this->scopeConfig = $scopeConfig;
31+
$this->serializer = $serializer;
2532
}
2633

2734
public function __invoke(array $records): array
2835
{
29-
$customConfiguration = $this->customConfiguration->getUnserializedConfigValue(Config::CONFIG_LOGGER_CUSTOM_CONFIGURATION);
30-
31-
if (!$customConfiguration) {
32-
return $records;
33-
}
34-
35-
foreach ($customConfiguration as $value) {
36+
foreach ($this->resolveTypesLogger() as $value) {
3637
$records['context'][$value['custom_logger_key']] = $value['custom_logger_value'];
3738
}
3839

3940
return $records;
4041
}
42+
43+
private function resolveTypesLogger(?string $store = null): array
44+
{
45+
return $this->serializer->unserialize(
46+
$this->scopeConfig->getValue('loggin/context/types_logger', ScopeInterface::SCOPE_STORE, $store) ?: '{}'
47+
);
48+
}
4149
}

Transport/UdpTransportWrapper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function send(Message $message): int
115115

116116
private function createTransporter(): UdpTransport
117117
{
118-
return $this->transporter = $this->transportFactory->create([
118+
return $this->transportFactory->create([
119119
'host' => $this->scopeConfig->getValue($this->hostPath),
120120
'port' => $this->scopeConfig->getValue($this->portPath),
121121
'chunkSize' => $this->chunkSize

0 commit comments

Comments
 (0)