Skip to content

Commit

Permalink
Merge pull request #4 from flotzilla/tests-fix
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
flotzilla authored Apr 16, 2020
2 parents 82d6e48 + f4d3e76 commit d55c5ac
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/Channel/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
string $minLogLevel = null
)
{
if (!$channelName){
if (!$channelName) {
throw new InvalidChannelNameException();
}

Expand Down Expand Up @@ -82,7 +82,7 @@ public function __construct(
private function setHandlers(array $handlers): void
{
foreach ($handlers as $handler) {
if (!$handler instanceof HandlerInterface){
if (!$handler instanceof HandlerInterface) {
throw new InvalidConfigurationException('Array arguments should be instance of HandlerInterface');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Handler/ConsoleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function handle(
{
$formattedMessage = $this->formatter->format($message, $context, $level, $date);

echo $formattedMessage;
echo $formattedMessage . PHP_EOL;

return true;
}
Expand Down
7 changes: 3 additions & 4 deletions src/Handler/FileHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function handle(
): bool
{
$formattedMessage = $this->formatter->format($message, $context, $level, $date);
if (!$isSuccess = $this->appendLog($formattedMessage . PHP_EOL)){
if (!$isSuccess = $this->appendLog($formattedMessage . PHP_EOL)) {
throw new HandlerException('Error during witting log message to file', $message, $context, $level, $date);
}

Expand Down Expand Up @@ -127,12 +127,11 @@ private function appendLog(string $log): bool
return $result;
}

if ($file = fopen($this->fileName, 'a')) {
if ($file = fopen($this->fileName, 'w')) {
$result = fwrite($file, $log) !== false;
fclose($file);
}

fclose($file);

return $result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Helper/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Helper
*/
public static function isTimeFormatValid(string $format): bool
{
return \DateTime::createFromFormat($format , date($format)) != false;
return \DateTime::createFromFormat($format, date($format)) != false;
}

/**
Expand Down
15 changes: 6 additions & 9 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,12 @@ public function getChannels(): array
*/
public function setChannels(array $channels): void
{
foreach ($channels as $channel)
{
if (!$channel instanceof ChannelInterface){
foreach ($channels as $channel) {
if (!$channel instanceof ChannelInterface) {
throw new InvalidConfigurationException('Array arguments should be instance of ChannelInterface');
}

$this->addChannel($channel);;
$this->addChannel($channel);
}
}

Expand All @@ -121,11 +120,9 @@ public function setChannels(array $channels): void
*/
public function addChannel(ChannelInterface $channel): void
{
if (array_key_exists($channel->getChannelName(), $this->channels))
{
if (array_key_exists($channel->getChannelName(), $this->channels)) {
throw new InvalidConfigurationException(
"Channel with name {$channel->getChannelName()} already exist in runtime")
;
"Channel with name {$channel->getChannelName()} already exist in runtime");
}

$this->channels[$channel->getChannelName()] = $channel;
Expand All @@ -137,7 +134,7 @@ public function addChannel(ChannelInterface $channel): void
*/
public function getChannel(string $name): ?ChannelInterface
{
return array_key_exists($name, $this->channels)? $this->channels[$name]: new NullChannel;
return array_key_exists($name, $this->channels) ? $this->channels[$name] : new NullChannel;
}

/**
Expand Down

0 comments on commit d55c5ac

Please sign in to comment.