Skip to content

Commit

Permalink
Cleanup FlattenException (#80)
Browse files Browse the repository at this point in the history
* Cleanup FlattenException
* Mark FlattenException as final
  • Loading branch information
rustamwin committed Dec 10, 2020
1 parent 37ef795 commit 373aa89
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions src/FlattenException.php
Expand Up @@ -15,41 +15,41 @@
* Basically, this class removes all objects from the trace.
* Ported from Symfony components @link https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Debug/Exception/FlattenException.php
*/
class FlattenException
final class FlattenException
{
/**
* @var string
*/
protected string $message;
private string $message;
/**
* @var int|mixed
*/
protected $code;
private $code;
/**
* @var string
*/
protected string $file;
private string $file;
/**
* @var int
*/
protected int $line;
private int $line;

/**
* @var FlattenException|null
*/
private ?FlattenException $_previous;
private ?FlattenException $previous;
/**
* @var array
*/
private array $_trace;
private array $trace;
/**
* @var string
*/
private string $_toString;
private string $toString;
/**
* @var string
*/
private string $_class;
private string $class;

/**
* FlattenException constructor.
Expand All @@ -75,9 +75,9 @@ public function __construct(Throwable $exception)
/**
* @param string $string the string representation of the thrown object.
*/
protected function setToString($string): void
private function setToString(string $string): void
{
$this->_toString = $string;
$this->toString = $string;
}

/**
Expand All @@ -93,7 +93,7 @@ public function getMessage(): string
/**
* @param string $message the Exception message as a string.
*/
protected function setMessage($message): void
private function setMessage(string $message): void
{
$this->message = $message;
}
Expand All @@ -111,7 +111,7 @@ public function getCode()
/**
* @param int|mixed $code the exception code as integer.
*/
protected function setCode($code): void
private function setCode($code): void
{
$this->code = $code;
}
Expand All @@ -129,7 +129,7 @@ public function getFile(): string
/**
* @param string $file the filename in which the exception was created.
*/
protected function setFile($file): void
private function setFile(string $file): void
{
$this->file = $file;
}
Expand All @@ -147,7 +147,7 @@ public function getLine(): int
/**
* @param int $line the line number where the exception was created.
*/
protected function setLine($line): void
private function setLine(int $line): void
{
$this->line = $line;
}
Expand All @@ -159,15 +159,15 @@ protected function setLine($line): void
*/
public function getTrace(): array
{
return $this->_trace;
return $this->trace;
}

/**
* @param array $trace the Exception stack trace as an array.
*/
protected function setTrace($trace): void
private function setTrace(array $trace): void
{
$this->_trace = [];
$this->trace = [];
foreach ($trace as $entry) {
$class = '';
$namespace = '';
Expand All @@ -177,7 +177,7 @@ protected function setTrace($trace): void
$namespace = implode('\\', $parts);
}

$this->_trace[] = [
$this->trace[] = [
'namespace' => $namespace,
'short_class' => $class,
'class' => $entry['class'] ?? '',
Expand All @@ -197,15 +197,15 @@ protected function setTrace($trace): void
*/
public function getPrevious(): ?self
{
return $this->_previous;
return $this->previous;
}

/**
* @param FlattenException $previous previous Exception.
*/
protected function setPrevious(self $previous): void
private function setPrevious(self $previous): void
{
$this->_previous = $previous;
$this->previous = $previous;
}

/**
Expand All @@ -216,11 +216,11 @@ protected function setPrevious(self $previous): void
public function getTraceAsString(): string
{
$remove = "Stack trace:\n";
$len = strpos($this->_toString, $remove);
$len = strpos($this->toString, $remove);
if ($len === false) {
return '';
}
return substr($this->_toString, $len + strlen($remove));
return substr($this->toString, $len + strlen($remove));
}

/**
Expand All @@ -230,23 +230,23 @@ public function getTraceAsString(): string
*/
public function __toString()
{
return $this->_toString;
return $this->toString;
}

/**
* @return string the name of the class in which the exception was created.
*/
public function getClass(): string
{
return $this->_class;
return $this->class;
}

/**
* @param string $class the name of the class in which the exception was created.
*/
protected function setClass($class): void
private function setClass(string $class): void
{
$this->_class = $class;
$this->class = $class;
}

/**
Expand All @@ -258,7 +258,7 @@ protected function setClass($class): void
*
* @return array arguments tracing.
*/
private function flattenArgs($args, $level = 0, &$count = 0): array
private function flattenArgs(array $args, $level = 0, &$count = 0): array
{
$result = [];
foreach ($args as $key => $value) {
Expand Down

0 comments on commit 373aa89

Please sign in to comment.