Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for the canBeUsedXTimes method #43

Merged
merged 2 commits into from
Jan 28, 2024
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
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ To get started with Laravel Invite Codes, use Composer to add the package to you
composer require mateusjunges/laravel-invite-codes
```

Or add this line in your composer.json, inside of the require section:
Or add this line in your composer.json, inside the `require` section:
```bash
{
"require": {
"mateusjunges/laravel-invite-codes": "^1.6",
"mateusjunges/laravel-invite-codes": "^2.0",
}
}
```
Expand Down Expand Up @@ -196,14 +196,6 @@ To restrict the usage of an invite code you can use the `restrictUsageTo()` meth
If you want that your invite code be used a limited amount of times, you can set the max usages limit with the `maxUsages()` method, and pass an integer with the amount
of allowed usages.

Also, you can use the declarative syntax, and use the `canBeUsedXTimes()` method, where `X` is the amount of times your invite code will be usable.
For example:

- `->canBeUsed10Times()`: This invite code can be used 10 times.
- `->canBeUsed50Times()`: This invite code can be used 50 times.

> You can use any integer number you want with this method.

## Create multiple invite codes

If you want to create more than one invite code with the same configs, you can use the `make()` method.
Expand Down
17 changes: 0 additions & 17 deletions src/InviteCodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,6 @@ class InviteCodes implements InviteCodesContract
protected ?CarbonInterface $expires_at;
protected bool $dispatch_events = true;

/**
* @param $arguments
*
* @throws BadMethodCallException
* @throws InviteMustBeAbleToBeRedeemedException
*/
public function __call(string $name, $arguments): self
{
if (method_exists($this, $name)) {
$this->{$name}($arguments);
} elseif (preg_match('/^canBeUsed(\d+)Times$/', $name, $max_usages)) {
return $this->maxUsages($max_usages[1]);
}

throw new BadMethodCallException('Invalid method called');
}

/** If used, no events will be dispatched. */
public function withoutEvents(): self
{
Expand Down
31 changes: 0 additions & 31 deletions tests/InviteModelMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,35 +88,4 @@ public function test_sold_out_scope()

$this->assertCount(1, Invite::soldOut()->get());
}

public function test_can_be_used_n_times()
{
$invite = InviteCodes::create()
->canBeUsed2Times()
->save();

InviteCodes::redeem($invite->code);
InviteCodes::redeem($invite->code);
$this->assertTrue(true);
}

public function test_cant_be_used_more_than_n_times()
{
$invite = InviteCodes::create()
->canBeUsed2Times()
->save();

$this->expectException(SoldOutException::class);
InviteCodes::redeem($invite->code);
InviteCodes::redeem($invite->code);
InviteCodes::redeem($invite->code);
}

public function test_can_be_used_0_times_is_invalid()
{
$this->expectException(InviteMustBeAbleToBeRedeemedException::class);
InviteCodes::create()
->canBeUsed0Times()
->save();
}
}
Loading