Skip to content

Commit

Permalink
Update ProviderData.php
Browse files Browse the repository at this point in the history
  • Loading branch information
miguilimzero authored Mar 29, 2024
1 parent ac8b8c9 commit 1f3d46c
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Data/ProviderData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use JoelButcher\Socialstream\Enums\ProviderEnum;
use JoelButcher\Socialstream\Providers;
use Webmozart\Assert\Assert;

/**
* @internal
Expand All @@ -16,15 +15,23 @@ private function __construct(
public readonly string $name,
public readonly ?string $buttonLabel = null,
) {
Assert::stringNotEmpty($id);
Assert::stringNotEmpty($name);
if ($id === '') {
throw new \InvalidArgumentException('Expected a different value than \'\'');
}
if ($name === '') {
throw new \InvalidArgumentException('Expected a different value than \'\'');
}
}

public static function from(ProviderEnum|string|array $provider): self
{
if (is_array($provider)) {
Assert::keyExists($provider, 'id');
Assert::keyExists($provider, 'name');
if (! array_key_exists('id', $provider)) {
throw new \InvalidArgumentException('Expected the key \'id\' to exist');
}
if (! array_key_exists('name', $provider)) {
throw new \InvalidArgumentException('Expected the key \'name\' to exist');
}
}

return match (true) {
Expand Down

0 comments on commit 1f3d46c

Please sign in to comment.