Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare(strict_types = 1);
passthru(
escapeshellarg(__DIR__ . '/../vendor/bin/phpcs')
. ' ' . escapeshellarg('--standard=' . __DIR__ . '/../tools/cs/ruleset.xml')
. ' --parallel=1 --extensions=php,phpt --encoding=utf-8 --tab-width=4 --colors -sp'
. ' --parallel=1 --extensions=php,phpt --encoding=utf-8 --tab-width=4 --colors -sp --runtime-set php_version 080100'
. ' '
. __DIR__ . '/../src'
. ' '
Expand Down
1 change: 1 addition & 0 deletions src/CountryCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* ISO-3166-1 Alpha 2 country code enum
*
* @see https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
* @extends \SmartEmailing\Types\Enum<string>
*/
final class CountryCode extends Enum implements ToStringInterface
{
Expand Down
2 changes: 2 additions & 0 deletions src/CurrencyCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* ISO-4217 three-letter ("Alpha-3")
*
* @extends \SmartEmailing\Types\Enum<string>
*/
final class CurrencyCode extends Enum implements ToStringInterface
{
Expand Down
24 changes: 18 additions & 6 deletions src/Enum.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
use ReflectionClass;
use ReflectionClassConstant;

/**
* @template T
*/
abstract class Enum
{

/**
* @var mixed
* @var T
*/
private $value;

Expand All @@ -22,7 +25,7 @@ abstract class Enum
private static array $instances = [];

/**
* @var array<string, mixed>
* @var array<string, array<T>>
*/
private static array $availableValues = [];

Expand Down Expand Up @@ -52,11 +55,17 @@ final public static function get(
return self::$instances[$index];
}

public function getValue(): mixed
/**
* @return T
*/
public function getValue()
{
return $this->value;
}

/**
* @param self<T> $that
*/
public function equals(
self $that
): bool
Expand Down Expand Up @@ -93,7 +102,7 @@ public static function checkValue(
}

/**
* @return array<mixed>
* @return array<T>
*/
public static function getAvailableValues(): array
{
Expand Down Expand Up @@ -130,6 +139,9 @@ public static function isValidValue(
return \in_array($value, self::getAvailableValues(), true);
}

/**
* @param self<T> $that
*/
protected function checkSameEnum(
self $that
): void
Expand All @@ -140,7 +152,7 @@ protected function checkSameEnum(
}

/**
* @param array<mixed> $availableValues
* @param array<T> $availableValues
*/
protected static function checkAvailableValues(
array $availableValues
Expand Down Expand Up @@ -218,7 +230,7 @@ private static function getValueIndex(
}

/**
* @return array<string, mixed>
* @return array<string, T>
*/
private static function getEnumConstants(): array
{
Expand Down
3 changes: 3 additions & 0 deletions src/FieldOfApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use SmartEmailing\Types\ExtractableTraits\EnumExtractableTrait;

/**
* @extends \SmartEmailing\Types\Enum<string>
*/
final class FieldOfApplication extends Enum
{

Expand Down
2 changes: 1 addition & 1 deletion src/Guid.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static function fromHex32(
return self::from(
\sprintf(
'%s%s-%s-%s-%s-%s%s%s',
...$parts
...$parts // phpcs:disable SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking.UnpackingUsed
)
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/HttpMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace SmartEmailing\Types;

use SmartEmailing\Types\Comparable\ComparableInterface;
use SmartEmailing\Types\Comparable\StringComparableTrait;
use SmartEmailing\Types\ExtractableTraits\EnumExtractableTrait;

final class HttpMethod extends Enum implements ToStringInterface, ComparableInterface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jen, proč se zrušila tan comparable traita?

Copy link
Collaborator Author

@aleswita aleswita Apr 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\SmartEmailing\Types\Enum ma svoji vlastni metodu equals a HttpMethod byl jediny Enum, ktery neco takoveho obsahoval a ta traita ji prepisovala.
Koukam do historie a daval jsi to tam ty, melo to tehda nejaky vetsi umysl?
U toho kde se to tehda vsude pridavalo mi to pripada jako neumyslne pridani do tohoto enumu.

/**
* @extends \SmartEmailing\Types\Enum<string>
*/
final class HttpMethod extends Enum implements ToStringInterface
{

use EnumExtractableTrait;
use ToStringTrait;
use StringComparableTrait;

public const GET = 'GET';

Expand Down
1 change: 1 addition & 0 deletions src/LawfulBasisForProcessing.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*
* @package SmartEmailing\Types
* @see https://ico.org.uk/for-organisations/guide-to-the-general-data-protection-regulation-gdpr/lawful-basis-for-processing/
* @extends \SmartEmailing\Types\Enum<string>
*/
final class LawfulBasisForProcessing extends Enum
{
Expand Down
3 changes: 3 additions & 0 deletions src/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use SmartEmailing\Types\ExtractableTraits\EnumExtractableTrait;

/**
* @extends \SmartEmailing\Types\Enum<string>
*/
final class Relation extends Enum
{

Expand Down
3 changes: 3 additions & 0 deletions src/TimeUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use SmartEmailing\Types\ExtractableTraits\EnumExtractableTrait;

/**
* @extends \SmartEmailing\Types\Enum<string>
*/
final class TimeUnit extends Enum implements ToStringInterface
{

Expand Down
3 changes: 3 additions & 0 deletions tests/EnumTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use Tester\TestCase;

require __DIR__ . '/bootstrap.php';

/**
* @extends \SmartEmailing\Types\Enum<string>
*/
final class SimpleEnum extends Enum
{

Expand Down