Skip to content

Commit

Permalink
phpstan changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Kientzler committed Aug 10, 2020
1 parent a9a63ed commit 5569dc8
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 16 deletions.
4 changes: 2 additions & 2 deletions SKien/XLogger/ChromePHPLogger.php
Expand Up @@ -42,7 +42,7 @@ public function __construct(string $level = LogLevel::DEBUG)
* @return void
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, $message, array $context = array())
public function log($level, $message, array $context = array()) : void
{
// check, if requested level should be logged
// causes InvalidArgumentException in case of unknown level.
Expand Down Expand Up @@ -70,7 +70,7 @@ public function log($level, $message, array $context = array())
ChromePhp::log($strMessage);
break;
}
if (count($context) >0) {
if (count($context) > 0) {
ChromePhp::group();
foreach ($context as $key => $value) {
// only add, if not included as placeholder in the mesage
Expand Down
8 changes: 4 additions & 4 deletions SKien/XLogger/FileLogger.php
Expand Up @@ -29,7 +29,7 @@
*/
class FileLogger extends XLogger
{
/** @var resource file handle of the opened logfile */
/** @var resource|bool file handle of the opened logfile */
protected $logfile = false;
/** @var string separator */
protected string $strSep = '';
Expand Down Expand Up @@ -62,14 +62,14 @@ public function __destruct()
* @return void
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, $message, array $context = array())
public function log($level, $message, array $context = array()) : void
{
// check, if requested level should be logged
// causes InvalidArgumentException in case of unknown level.
if ($this->logLevel($level)) {
// Open file if not opened so far, dependend on the file extension the separator is set.
$this->openLogfile();
if (!$this->logfile) {
if ($this->logfile === false) {
return;
}

Expand Down Expand Up @@ -114,7 +114,7 @@ public function log($level, $message, array $context = array())
*/
protected function openLogfile() : void
{
if (!$this->logfile) {
if ($this->logfile === false) {
$strFullPath = $this->getFullpath();
switch (strtolower(pathinfo($strFullPath, PATHINFO_EXTENSION))) {
case 'csv':
Expand Down
6 changes: 2 additions & 4 deletions SKien/XLogger/FirePHPLogger.php
Expand Up @@ -52,7 +52,7 @@ public function __construct(string $level = LogLevel::DEBUG)
* @return void
* @throws \Psr\Log\InvalidArgumentException
*/
public function log($level, $message, array $context = array())
public function log($level, $message, array $context = array()) : void
{
// check, if requested level should be logged
// causes InvalidArgumentException in case of unknown level.
Expand Down Expand Up @@ -80,15 +80,13 @@ public function log($level, $message, array $context = array())
$this->fb->log($strMessage);
break;
}
if (count($context) >0) {
// $this->fb->group('context');
if (count($context) > 0) {
foreach ($context as $key => $value) {
// only add, if not included as placeholder in the mesage
if (strpos($message, '{' . $key . '}') === false) {
$this->fb->log($value, $key);
}
}
// $this->fb->groupEnd();
}
}
}
6 changes: 4 additions & 2 deletions SKien/XLogger/XLogger.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace SKien\XLogger;

use Psr\Log\AbstractLogger;
Expand Down Expand Up @@ -59,9 +61,9 @@ public function __construct(string $level = LogLevel::DEBUG)
* @param string $strLogLevel
* @return void
*/
public function setLogLevel(string $level) : void
public function setLogLevel(string $strLogLevel) : void
{
$this->iLogLevel = $this->getIntLevel($level);
$this->iLogLevel = $this->getIntLevel($strLogLevel);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions TestClass.php
Expand Up @@ -38,12 +38,12 @@ public function causeException()
try {
$this->throwException();
} catch (Exception $e) {
$this->logger->error('Catch Exception', ['exception' => $e]);
$this->logger->error($e->getMessage(), ['exception' => $e]);
}
}

protected function throwException()
{
throw new Exception('Caused any Exception');
throw new LogicException('Caused any Exception');
}
}
26 changes: 24 additions & 2 deletions XMLLogger.xsl
Expand Up @@ -61,16 +61,38 @@
<body style="font-family:Arial;font-size:8pt;background-color:#EEEEEE">
<table width="100%"><tbody>
<xsl:for-each select="log/item">
<tr class="{level}">
<xsl:variable name="rowclass"><xsl:value-of select="level"/></xsl:variable>
<tr class="{$rowclass}">
<td><xsl:value-of select="timestamp"/></td>
<td><xsl:value-of select="user"/></td>
<td class="caller"><xsl:value-of select="caller"/></td>
<td class="ua"><xsl:value-of select="useragent"/></td>
</tr>
<tr class="{level}">
<td><xsl:value-of select="level"/></td>
<td><xsl:value-of select="$rowclass"/></td>
<td colspan="3"><xsl:value-of select="message"/></td>
</tr>
<xsl:for-each select=".//context">
<tr class="{$rowclass}">
<td></td>
<td><xsl:value-of select="key"/></td>
<td colspan="2"><xsl:value-of select="value"/></td>
</tr>
</xsl:for-each>
<xsl:if test="exception">
<tr class="{$rowclass}">
<td></td>
<td colspan="3"><xsl:value-of select="exception/class"/> trace:</td>
</tr>
</xsl:if>
<xsl:for-each select=".//exception/trace">
<tr class="{$rowclass}">
<td></td>
<td><xsl:value-of select="class"/></td>
<td><xsl:value-of select="function"/></td>
<td><xsl:value-of select="file"/> (<xsl:value-of select="line"/>)</td>
</tr>
</xsl:for-each>
</xsl:for-each>
</tbody></table>
</body>
Expand Down
9 changes: 9 additions & 0 deletions phpstan.neon
@@ -0,0 +1,9 @@
parameters:
level: 6
checkMissingIterableValueType: false
paths:
- SKien/XLogger
scanDirectories:
- CCampbell
- FirePHP
- Psr

0 comments on commit 5569dc8

Please sign in to comment.