Skip to content

Commit cd3b585

Browse files
author
fureev
committed
feat: add trait UseStorage.
1 parent e233170 commit cd3b585

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+615
-938
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ The format is based on [Keep a Changelog][keepachangelog] and this project adher
99
### Added
1010

1111
- Add `PHP 8.4` support
12+
- Add `UseStorage` trait. Trait `ArrayStorage` is deprecated now
13+
- Add `UseConfigurabeStorage` trait. Trait `ArrayStorageConfigurableTrait` is deprecated now
14+
15+
### Removed
16+
17+
- Remove Trait `ArrayStorage`. Use `UseStorage` instead
18+
- Remove Trait `ArrayStorageConfigurableTrait`. Use `UseConfigurabeStorage` instead
1219

1320
## v4.28.0
1421

src/Enums/WithEnhances.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Php\Support\Enums;
66

77
/**
8+
* @template TValue
89
* @mixin \UnitEnum
910
*/
1011
trait WithEnhances
@@ -18,13 +19,16 @@ public static function casesToString(callable $decorator, string $delimiter = ',
1819
}
1920

2021
/**
21-
* @return mixed[]
22+
* @return TValue[]
2223
*/
2324
public static function values(): array
2425
{
2526
return array_map(static fn(self $enumItem) => $enumItem->value, self::cases());
2627
}
2728

29+
/**
30+
* @return string[]
31+
*/
2832
public static function names(): array
2933
{
3034
return array_map(static fn(self $enumItem) => $enumItem->name, self::cases());
@@ -35,16 +39,22 @@ public static function hasName(string $value): bool
3539
return in_array($value, static::names(), true);
3640
}
3741

42+
/**
43+
* @return array<string, TValue>
44+
*/
3845
public static function toKeyValueArray(): array
3946
{
4047
$list = [];
4148
foreach (self::cases() as $case) {
42-
$list[$case->value] = $case->name;
49+
$list[$case->name] = $case->value;
4350
}
4451

4552
return $list;
4653
}
4754

55+
/**
56+
* @return array<string, string>
57+
*/
4858
public static function toValueKeyArray(): array
4959
{
5060
$list = [];

src/Exceptions/ConfigException.php

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,15 @@
66

77
/**
88
* Class ConfigException
9-
*
10-
* @package Php\Support\Exceptions
119
*/
1210
class ConfigException extends Exception
1311
{
1412
/**
15-
* ConfigException constructor.
16-
*
17-
* @param ?array $config
1813
* @param string $message
14+
* @param array<string, mixed> $config
1915
*/
20-
public function __construct(string $message = 'Config Exception', protected ?array $config = null)
16+
public function __construct(string $message = 'Config Exception', protected(set) array $config = [])
2117
{
2218
parent::__construct($message);
2319
}
24-
25-
/**
26-
* @return array|null
27-
*/
28-
public function getConfig(): ?array
29-
{
30-
return $this->config;
31-
}
3220
}

src/Exceptions/Exception.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
/**
1212
* Class Exception
13-
*
14-
* @package Php\Support\Exceptions
1513
*/
1614
class Exception extends \Exception
1715
{

src/Exceptions/InvalidArgumentException.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@
88

99
/**
1010
* Class InvalidArgumentException
11-
*
12-
* @package Php\Support\Exceptions
1311
*/
1412
class InvalidArgumentException extends \InvalidArgumentException
1513
{
16-
/**
17-
* Exception constructor.
18-
*
19-
* @param ?string $message
20-
* @param int $code
21-
* @param ?Throwable $previous
22-
*/
2314
public function __construct(?string $message = null, int $code = 0, ?Throwable $previous = null)
2415
{
2516
parent::__construct($message ?? $this->getName(), $code, $previous);

src/Exceptions/InvalidCallException.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88

99
/**
1010
* Class InvalidCallException
11-
* @package Php\Support\Exceptions
1211
*/
1312
class InvalidCallException extends BadMethodCallException
1413
{
15-
/**
16-
* @return string
17-
*/
1814
public function getName(): string
1915
{
2016
return 'Invalid Call';

src/Exceptions/InvalidConfigException.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,10 @@
66

77
/**
88
* Class InvalidConfigException
9-
*
10-
* @package Php\Support\Exceptions
119
*/
1210
class InvalidConfigException extends ConfigException
1311
{
14-
/**
15-
* InvalidConfigException constructor.
16-
*
17-
* @param ?array $config
18-
* @param string $message
19-
*/
20-
public function __construct(?array $config = null, $message = 'Invalid Configuration')
12+
public function __construct(array $config = [], string $message = 'Invalid Configuration')
2113
{
2214
parent::__construct($message, $config);
2315
}

src/Exceptions/InvalidParamException.php

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,17 @@
66

77
use LogicException;
88

9-
/**
10-
* Class InvalidParamException
11-
*
12-
* @package Php\Support\Exceptions
13-
*/
149
class InvalidParamException extends LogicException
1510
{
16-
/** @var string|null */
17-
protected $param;
18-
19-
/**
20-
* InvalidParamException constructor.
21-
*
22-
* @param null|string $param
23-
* @param null|string $message
24-
*/
25-
public function __construct(?string $message = null, ?string $param = null)
11+
public function __construct(?string $message = null, public private(set) readonly ?string $name = null)
2612
{
27-
$this->param = $param;
28-
parent::__construct($message ?? sprintf('Invalid Parameter' . ($this->param ? ': %s' : ''), $this->param));
13+
parent::__construct(
14+
$message ?? sprintf('Invalid Parameter' . ($this->name ? ': %s' : ''), $this->name)
15+
);
2916
}
3017

31-
/**
32-
* @return string
33-
*/
3418
public function getName(): string
3519
{
3620
return 'Invalid Parameter';
3721
}
38-
39-
/**
40-
* @return null|string
41-
*/
42-
public function getParam(): ?string
43-
{
44-
return $this->param;
45-
}
4622
}

src/Exceptions/InvalidValueException.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88

99
/**
1010
* Class InvalidValueException
11-
* @package Php\Support\Exceptions
1211
*/
1312
class InvalidValueException extends UnexpectedValueException
1413
{
15-
/**
16-
* @return string
17-
*/
1814
public function getName(): string
1915
{
2016
return 'Invalid Return Value';

src/Exceptions/MethodNotAllowedException.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,10 @@
66

77
/**
88
* Class MethodNotAllowedException
9-
*
10-
* @package Php\Support\Exceptions
119
*/
1210
class MethodNotAllowedException extends Exception
1311
{
14-
/** @var string */
15-
protected $reason;
16-
17-
/**
18-
* MethodNotAllowedException constructor.
19-
*
20-
* @param string $reason
21-
* @param string $message
22-
*/
23-
public function __construct(string $reason, $message = 'Method Not Allowed')
12+
public function __construct(protected string $reason, string $message = 'Method Not Allowed')
2413
{
2514
$this->reason = $reason;
2615

0 commit comments

Comments
 (0)