-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added features to State and Comparison
- Loading branch information
Showing
19 changed files
with
695 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Henzeb\Enumhancer\Concerns; | ||
|
||
use Henzeb\Enumhancer\Helpers\EnumMagicCalls; | ||
|
||
trait MagicCalls | ||
{ | ||
public static function __callStatic(string $name, array $arguments = []) | ||
{ | ||
return EnumMagicCalls::static(self::class, $name); | ||
} | ||
|
||
public function __call(string $name, array $arguments = []) | ||
{ | ||
return EnumMagicCalls::call($this, $name, $arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace Henzeb\Enumhancer\Helpers; | ||
|
||
use BadMethodCallException; | ||
use UnitEnum; | ||
|
||
abstract class EnumMagicCalls | ||
{ | ||
public static function call(UnitEnum $enum, string $name, array $arguments): mixed | ||
{ | ||
EnumCheck::check($enum::class); | ||
|
||
if (EnumCompare::isValidCall($enum::class, $name, $arguments)) { | ||
return EnumCompare::call($enum, $name); | ||
} | ||
|
||
if (EnumState::isValidCall($enum::class, $name)) { | ||
return EnumState::call($enum, $name, $arguments); | ||
} | ||
|
||
return self::static($enum::class, $name); | ||
} | ||
|
||
public static function static(string $class, string $name): mixed | ||
{ | ||
EnumCheck::check($class); | ||
|
||
if (EnumImplements::constructor($class)) { | ||
return EnumGetters::tryGet($class, $name, true) ?? self::throwException($class, $name); | ||
} | ||
|
||
self::throwException($class, $name); | ||
} | ||
|
||
public static function throwException($class, $name): never | ||
{ | ||
throw new BadMethodCallException(sprintf('Call to undefined method %s::%s(...)', $class, $name)); | ||
} | ||
} |
Oops, something went wrong.