Skip to content

Commit

Permalink
% apply PHPSTAN + RECTOR
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondDantes committed Nov 14, 2024
1 parent b55274a commit f80b060
Show file tree
Hide file tree
Showing 36 changed files with 183 additions and 201 deletions.
210 changes: 106 additions & 104 deletions composer.lock

Large diffs are not rendered by default.

14 changes: 6 additions & 8 deletions src/BaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,17 @@ class BaseException extends \Exception implements BaseExceptionInterface
{
use HelperTrait;
use TemplateHandlerTrait;

/**
* @param \Throwable|null $throwable
* @param int $recursion
*
* @return array<string, scalar|array<string, scalar[]>>|null
*/
public static function serializeToArray(\Throwable|null $throwable = null, int $recursion = 0): array|null
{
if($throwable === null) {
if ($throwable === null) {
return null;
}

if ($recursion > 8) {
return [
'message' => 'Depth of exceptions is greater than 8',
Expand All @@ -64,7 +62,7 @@ public static function serializeToArray(\Throwable|null $throwable = null, int $
'previous' => null,
];
}

if ($throwable instanceof BaseExceptionInterface) {
return $throwable->toArray();
}
Expand Down Expand Up @@ -390,7 +388,7 @@ public function getDebugData(): array
{
return $this->debugData;
}

/**
* The method serialized object to an array.
*/
Expand Down Expand Up @@ -438,7 +436,7 @@ public function toArray(): array
'tags' => $this->getTags(),
'code' => $this->getCode(),
'data' => $this->getExceptionData(),
'previous' => self::serializeToArray($this->getPrevious())
'previous' => self::serializeToArray($this->getPrevious()),
];
}

Expand Down
1 change: 0 additions & 1 deletion src/ClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class ClientException extends BaseException implements ClientAvailableInterface
{
/**
* @param string $template
* @param array<string, scalar|null|scalar[]> $parameters
* @param array<string, scalar|null|scalar[]> $debugData
*/
Expand Down
6 changes: 3 additions & 3 deletions src/ContractNotCorrect.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Traits
* throws that exception).
*/
class ContractNotCorrect extends LoggableException
class ContractNotCorrect extends LoggableException
{
public const string PROPERTY = 'property';

Expand All @@ -19,7 +19,7 @@ class ContractNotCorrect extends LoggableException
public const string METHOD = 'method';

protected string $template = 'Contract is not correctly for {type} in the trait {trait} which used by {object}';

/**
* The Contract is not correct.
*
Expand All @@ -29,7 +29,7 @@ class ContractNotCorrect extends LoggableException
* @param string|null $trait trait name
* @param string $notice extended message
*/
public function __construct(object $object, $type = self::PROPERTY, $value = null, string $trait = null, string $notice = '')
public function __construct(object $object, $type = self::PROPERTY, $value = null, ?string $trait = null, string $notice = '')
{
parent::__construct([
'message' => $notice,
Expand Down
30 changes: 13 additions & 17 deletions src/Errors/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
*/
class Error extends \ErrorException implements BaseExceptionInterface
{

/**
* Conformity between PHP-errors and BaseException
* Conformity between PHP-errors and BaseException.
* @var array<int, int>
*/
protected static array $ERRORS =
Expand All @@ -35,7 +34,7 @@ class Error extends \ErrorException implements BaseExceptionInterface
E_DEPRECATED => self::INFO,
E_USER_DEPRECATED => self::INFO,
];

/**
* @var mixed[]|null
*/
Expand All @@ -50,11 +49,10 @@ class Error extends \ErrorException implements BaseExceptionInterface
* Fatal error flag.
*/
protected bool $isFatal = false;

/**
* @param array<string, scalar>|null $error
*
* @return BaseExceptionInterface|null
*/
public static function createFromLastError(?array $error = null): ?BaseExceptionInterface
{
Expand All @@ -75,7 +73,6 @@ public static function createFromLastError(?array $error = null): ?BaseException
* @param string $file File
* @param int $line Line
*
* @return BaseExceptionInterface
*/
public static function createError(int $severity, string $message, string $file, int $line): BaseExceptionInterface
{
Expand Down Expand Up @@ -117,24 +114,23 @@ public static function createError(int $severity, string $message, string $file,
}
}
}

public function __construct(int $severity = \E_ERROR,
string $message = '',
?string $filename = null,
?int $line = null,
int $code = 0,
?\Throwable $previous = null
)
{
string $message = '',
?string $filename = null,
?int $line = null,
int $code = 0,
?\Throwable $previous = null
) {
parent::__construct($message, $code, $severity, $filename, $line, $previous);
}

#[\Override]
public function getTags(): array
{
return [];
}

#[\Override]
public function isLoggable(): bool
{
Expand Down Expand Up @@ -181,7 +177,7 @@ public function getLevel(): int

return self::$ERRORS[$this->getSeverity()];
}

/**
* @return array{source: string, type: string, function: string}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/HelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final protected static function getSourceFor(\Throwable $e, bool $isString = fal
[
'source' => $res['class'] ?? $res['file'] . ':' . $res['line'],
'type' => $res['type'] ?? '.',
'function' => $res['function'] ?? '{}' // @phpstan-ignore-line
'function' => $res['function'] ?? '{}', // @phpstan-ignore-line
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/InterfaceNotImplemented.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* If class not implemented required interface.
*/
class InterfaceNotImplemented extends LoggableException
class InterfaceNotImplemented extends LoggableException
{
protected string $template = 'Class {class} does not implement interface {interface}';

Expand Down
13 changes: 7 additions & 6 deletions src/MonologProcessor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace IfCastle\Exceptions;
Expand All @@ -11,17 +12,17 @@ final class MonologProcessor implements ProcessorInterface
#[\Override]
public function __invoke(LogRecord $record)
{
if(false === $record->context['exception'] instanceof BaseExceptionInterface) {
if (false === $record->context['exception'] instanceof BaseExceptionInterface) {
return $record;
}

$exception = $record->context['exception'];

$record->extra['exception_template'] = $exception->getTemplate();
$record->extra['exception_data'] = $exception->getExceptionData();
$record->extra['exception_debug'] = $exception->getDebugData();
$record->extra['tags'] = array_merge($record->extra['tags'] ?? [], $exception->getTags());
$record->extra['tags'] = \array_merge($record->extra['tags'] ?? [], $exception->getTags());

return $record;
}
}
}
2 changes: 1 addition & 1 deletion src/RecursionLimitExceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(array|string|int $limit)
if (!\is_scalar($limit)) {
parent::__construct($limit);
} else {
parent::__construct(['limit' => (int)$limit]);
parent::__construct(['limit' => (int) $limit]);
}
}
}
9 changes: 4 additions & 5 deletions src/Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace IfCastle\Exceptions;

use PHPUnit\Event\Code\Throwable;

/**
* Register of exceptions.
*
Expand All @@ -21,7 +19,7 @@ class Registry
* Flag for global handler.
*/
public static bool $isActive = false;

/**
* Options for logger.
* @var array<string, scalar|scalar[]>
Expand Down Expand Up @@ -111,9 +109,10 @@ public static function getExceptionLog(): array
{
if (\is_array(self::$exceptions)) {
return self::$exceptions;
} else {
return self::$exceptions->getStorageExceptions();
}

return self::$exceptions->getStorageExceptions();

}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/RequiredValueEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
class RequiredValueEmpty extends LoggableException
{
protected string $template = 'The Required value {name} is empty ({expected})';

/**
* If required value is empty.
*
* @param string|array<string|scalar|scalar[]> $name Variable name
* or array with parameters.
* @param string|null $expected Excepted type
*/
public function __construct(array|string $name, string $expected = null)
public function __construct(array|string $name, ?string $expected = null)
{
if (!\is_scalar($name)) {
parent::__construct($name);
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileCloseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileCloseError extends ResourceCloseError implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileLockFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileLockFailed extends ResourceLockFailed implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileNotExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileNotExists extends ResourceNotExists implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileNotReadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileNotReadable extends ResourceNotReadable implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileNotWritable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileNotWritable extends ResourceNotWritable implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileOpenError.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileOpenError extends ResourceOpenError implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileReadError.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileReadError extends ResourceReadError implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
3 changes: 1 addition & 2 deletions src/Resource/FileSystem/FileUnLockFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
class FileUnLockFailed extends ResourceUnLockFailed implements FileSystemExceptionInterface
{
protected string $system = self::SYSTEM;

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
1 change: 0 additions & 1 deletion src/Resource/FileSystem/FileWriteError.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class FileWriteError extends ResourceWriteError implements FileSystemExceptionIn

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'file')
{
Expand Down
1 change: 0 additions & 1 deletion src/Resource/ResourceCloseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ResourceCloseError extends ResourceException
{
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
Expand Down
2 changes: 0 additions & 2 deletions src/Resource/ResourceDataWrong.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class ResourceDataWrong extends ResourceException

/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
* @param string $format
*/
public function __construct(mixed $resource, string $type = 'resource', string $format = 'format')
{
Expand Down
Loading

0 comments on commit f80b060

Please sign in to comment.