Skip to content

Commit

Permalink
% PHPSTAN refactoring classes
Browse files Browse the repository at this point in the history
  • Loading branch information
EdmondDantes committed Oct 27, 2024
1 parent 57707c3 commit ee4bd28
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ jobs:
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run PHPStan
run: composer run-script analysis

- name: Run test suite
run: composer run-script test
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"phpstan/phpstan": "^1.12"
},
"scripts": {
"test": "vendor/bin/phpunit ./tests"
"test": "vendor/bin/phpunit ./tests",
"analysis": "phpstan"
}
}
2 changes: 1 addition & 1 deletion src/RequiredValueEmpty.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class RequiredValueEmpty extends LoggableException
/**
* If required value is empty.
*
* @param string|array $name Variable name
* @param string|array<string|scalar|scalar[]> $name Variable name
* or array with parameters.
* @param string|null $expected Excepted type
*/
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceCloseError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceCloseError extends ResourceException
{
public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'close');
}
Expand Down
8 changes: 7 additions & 1 deletion src/Resource/ResourceDataWrong.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ class ResourceDataWrong extends ResourceException
{
protected string $template = '{system} error: data is wrong (expected {format}) for resource {resource}';

public function __construct($resource, $type = 'resource', $format = 'format')
/**
* @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')
{
parent::__construct([
'resource' => $resource,
'type' => $type,
'operation' => 'format:' . $format,
'format' => $format,
'system' => $this->system,
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/ResourceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ResourceException extends SystemException
protected string $system = 'undefined';

/**
* @param string|object|resource|array $resource
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $operation
* @param string $type
*/
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceLockFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceLockFailed extends ResourceException
{
public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'lock');
}
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceNotExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ class ResourceNotExists extends ResourceException
{
protected string $template = '{system} error: {type} is not exist. Resource: {resource}, Operation: {operation}';

public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct([
'resource' => $resource,
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceNotReadable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceNotReadable extends ResourceException
{
public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'readable');
}
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceNotWritable.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceNotWritable extends ResourceException
{
public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'is_writable');
}
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceOpenError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceOpenError extends ResourceException
{
public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'open');
}
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceReadError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceReadError extends ResourceException
{
public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'read');
}
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceUnLockFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceUnLockFailed extends ResourceException
{
public function __construct($resource, $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'unlock');
}
Expand Down
6 changes: 5 additions & 1 deletion src/Resource/ResourceWriteError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

class ResourceWriteError extends ResourceException
{
public function __construct($resource, string $type = 'resource')
/**
* @param string|object|resource|array<string, scalar|scalar[]> $resource
* @param string $type
*/
public function __construct(mixed $resource, string $type = 'resource')
{
parent::__construct($resource, $type, 'write');
}
Expand Down
7 changes: 4 additions & 3 deletions src/SaveHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
interface SaveHandlerInterface
{
/**
* Save handler method.
*
*
* @param array<\Throwable> $exceptions
* @param callable $resetLog
* @param array<string, mixed> $loggerOptions
* @param array<string, mixed> $debugOptions
*/
public function saveExceptions(array $exceptions, callable $resetLog, array $loggerOptions = [], array $debugOptions = []): void;
}
12 changes: 6 additions & 6 deletions src/SerializeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SerializeException extends LoggableException
/**
* Object can't be serialized!
*
* @param string|array $reason Reason of error
* @param string|array<string, scalar|scalar[]> $reason Reason of error
* @param object $object The object which must have been serialized
* @param string $type Type of serializing
* @param object $srcObject The object where started the process
Expand All @@ -27,11 +27,11 @@ public function __construct(array|string $reason, $object = null, string $type =
}

parent::__construct([
'message' => 'Serialize Failed',
'reason' => $reason,
'type' => $type,
'object' => $this->typeInfo($object),
'srcObject' => $this->typeInfo($srcObject),
'message' => 'Serialize Failed',
'reason' => $reason,
'type' => $type,
'object' => $this->typeInfo($object),
'srcObject' => $this->typeInfo($srcObject),
]);
}
}
2 changes: 1 addition & 1 deletion src/TemplateHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract protected function toString(mixed $value, bool $isQuoted = false, int $
* Handles the template message.
*
* @param string $template Template
* @param array $data Extended data
* @param mixed[] $data Extended data
* @param string $message Message of exception
* @param int $code Code
* @param ?\Throwable $previous Previous Exception
Expand Down
4 changes: 2 additions & 2 deletions src/UnSerializeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class UnSerializeException extends LoggableException
/**
* Object can't be serialized!
*
* @param string|array $reason Reason of error
* @param string|mixed[] $reason Reason of error
* @param string $type Type of serialize
* @param mixed $node The node which must have been serialized
* @param string|null $node The node which must have been serialized
*/
public function __construct(array|string $reason, string $type = 'phpserialize', string|null $node = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/UnexpectedMethodMode.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UnexpectedMethodMode extends LoggableException
/**
* The method does not support this mode of work.
*
* @param string|array $method The method name
* @param string|mixed[] $method The method name
* or list of parameters for exception
* or another exception for container
* @param string|null $mode Name of mode
Expand Down
2 changes: 1 addition & 1 deletion src/UnexpectedValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UnexpectedValue extends LoggableException
/**
* The variable has an unexpected value!
*
* @param string|array $name Variable name
* @param string|mixed[] $name Variable name
* or list of parameters for exception
* @param mixed $value Value
* @param string|class-string|null $rules Rules description
Expand Down
2 changes: 1 addition & 1 deletion src/UnexpectedValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class UnexpectedValueType extends LoggableException
/**
* Value of variable has unexpected type.
*
* @param string|array $name Variable name
* @param string|mixed[] $name Variable name
* or list of parameters for exception
* @param mixed $value Value
* @param string|class-string|null $expected Excepted type
Expand Down

0 comments on commit ee4bd28

Please sign in to comment.