Skip to content
Open
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: 0 additions & 2 deletions database/factories/PoliticianFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use Illuminate\Database\Eloquent\Factories\Factory;
use LaravelQuadraticVoting\Models\Politician;



class PoliticianFactory extends Factory
{
protected $model = Politician::class;
Expand Down
1 change: 0 additions & 1 deletion database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class UserFactory extends Factory
{

protected $model = User::class;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function up()
$table->integer('quantity')->nullable();
$table->timestamps();
});

}

/**
Expand Down
1 change: 0 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,4 @@
$rectorConfig->rule(JoinStringConcatRector::class);
$rectorConfig->rule(LogicalToBooleanRector::class);
$rectorConfig->rule(NarrowUnionTypeDocRector::class);

};
1 change: 0 additions & 1 deletion src/Interfaces/IsVotableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ public function voters(): BelongsToMany;
public function getCountVotes(): int;

public function getVoters(): \Illuminate\Support\Collection;

}
3 changes: 1 addition & 2 deletions src/Interfaces/VoterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,5 @@ public function giveVoteCredits(int $vote_credits = 1): VoteCredit;

public function getVoteCredits(): int;

static function massiveVoteCredits(Collection $voters, int $credits): Collection;

public static function massiveVoteCredits(Collection $voters, int $credits): Collection;
}
1 change: 0 additions & 1 deletion src/Models/Idea.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LaravelQuadraticVoting\Models;


use Database\Factories\IdeaFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand Down
1 change: 0 additions & 1 deletion src/Models/Politician.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LaravelQuadraticVoting\Models;


use Database\Factories\IdeaFactory;
use Database\Factories\PoliticianFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down
3 changes: 0 additions & 3 deletions src/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace LaravelQuadraticVoting\Models;


use Database\Factories\UserFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -14,7 +13,6 @@
*/
class User extends Model implements VoterInterface
{

use VoterTrait;
use HasFactory;

Expand All @@ -24,5 +22,4 @@ protected static function newFactory()
{
return UserFactory::new();
}

}
1 change: 0 additions & 1 deletion src/Models/VoteCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,4 @@ public function voter(): BelongsTo
{
return $this->belongsTo(VoterInterface::class, 'voter_id');
}

}
4 changes: 0 additions & 4 deletions src/Providers/LaravelQuadraticVotingServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


namespace LaravelQuadraticVoting\Providers;

use Illuminate\Support\ServiceProvider;
Expand Down Expand Up @@ -29,8 +28,6 @@ public function boot()
);

$this->registerModelBindings();


}

/**
Expand All @@ -53,5 +50,4 @@ private function registerModelBindings()
$this->app->bind(VoterInterface::class, $config['voter']);
$this->app->bind(IsVotableInterface::class, $config['vote_credit']);
}

}
2 changes: 0 additions & 2 deletions src/Services/QuadraticVoteService.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,4 @@ public function getCostOfVoteNumber(int $vote): int
{
return $vote * $vote;
}


}
9 changes: 3 additions & 6 deletions src/Traits/VoterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

namespace LaravelQuadraticVoting\Traits;


use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
Expand Down Expand Up @@ -63,7 +62,6 @@ public function voteOn(Model $model, int $vote_credits = 1): int
$this->spendCredits($vote_credits);

return $votes_quantity;

}

/**
Expand Down Expand Up @@ -94,7 +92,6 @@ public function downVote(Model $model): int
$this->giveVoteCredits($cost_of_last_vote);

return $cost_of_last_vote;

}

public function hasCredits(int $wanna_spend): bool
Expand Down Expand Up @@ -126,7 +123,8 @@ public function ideas(): BelongsToMany
config('laravel_quadratic.models.is_votable'), // Idea::class,
"votes",
config('laravel_quadratic.column_names.voter_key'), // "voter_id",
"votable_id")
"votable_id"
)
->withPivot([
"votable_type",
"votable_id",
Expand Down Expand Up @@ -164,7 +162,7 @@ public function getVoteCredits(): int
return (int)optional($this->voteCredits()->first())->credits;
}

static function massiveVoteCredits(Collection $voters, int $credits): Collection
public static function massiveVoteCredits(Collection $voters, int $credits): Collection
{
$voters->each(function ($voter) use ($credits) {
$voter->giveVoteCredits($credits);
Expand All @@ -180,7 +178,6 @@ public function getVotesAlreadyEmittedOverall(): int

public function getVotesAlreadyEmittedOnIdea(Model $is_votable_model): int
{

$tablename_keyname_id = $is_votable_model->getTable() . '.' . $is_votable_model->getKeyName();

return $this->ideas()
Expand Down
2 changes: 0 additions & 2 deletions tests/IsVotableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ public function test_user_can_vote_another_entity(): void
$user->voteOn($politician, 4);
$this->assertEquals(9, $user->getNextVoteCost($politician));
}


}
1 change: 0 additions & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

class TestCase extends \Orchestra\Testbench\TestCase
{

protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
Expand Down
7 changes: 0 additions & 7 deletions tests/UserVotesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ protected function setUp(): void
*/
public function test_user_can_get_next_vote_cost(): void
{

// create a user mock object
/** @var User $user */
$user = User::factory()->create();
Expand Down Expand Up @@ -62,7 +61,6 @@ public function it_can_vote_two_ideas(): void
/** @test */
public function two_users_can_vote_one_idea(): void
{

/** @var User $user */
$user1 = User::factory()->create();
$user2 = User::factory()->create();
Expand All @@ -88,7 +86,6 @@ public function test_two_users_can_vote_two_ideas()

$this->assertEquals(3, $idea1->getCountVotes());
$this->assertEquals(3, $idea1->getCountVotes());

}

public function test_get_voters_of_an_idea(): void
Expand Down Expand Up @@ -133,7 +130,6 @@ public function user_can_get_overall_votes_of_two_ideas()
$user->voteOn($idea2, 30); // 4 votes

$this->assertEquals(7, $user->getVotesAlreadyEmittedOverall());

}

/** @test */
Expand All @@ -150,7 +146,6 @@ public function user_can_get_its_next_vote_cost_of_an_idea()

$this->assertEquals(4, $user->getNextVoteCost($idea1));
$this->assertEquals(16, $user->getNextVoteCost($idea2));

}

/** @test */
Expand Down Expand Up @@ -193,6 +188,4 @@ public function it_can_downvote_two_different_ideas()

$this->assertEquals(100, $user->getVoteCredits());
}


}
7 changes: 0 additions & 7 deletions tests/VotingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ protected function setUp(): void
*/
public function test_user_can_vote_an_idea(): void
{

// create a user mock object
/** @var User $user */
$user = User::factory()->create();
Expand Down Expand Up @@ -75,7 +74,6 @@ public function test_get_votes_of_a_thing_as_paying_in_consecutive_cost(): void
*/
public function test_get_votes_of_a_thing_not_paying_in_order(): void
{

// $this->expectException(\Exception::class);
/** @var User $user */
$user = User::factory()->create();
Expand All @@ -86,15 +84,13 @@ public function test_get_votes_of_a_thing_not_paying_in_order(): void
$user->voteOn($idea, 14);

$this->assertEquals(3, $idea->getCountVotes());

}

public function test_get_votes_default()
{
$idea = Idea::factory()->create();

$this->assertEquals(0, $idea->getCountVotes());

}

public function test_vote_costs_exponentially()
Expand All @@ -107,7 +103,6 @@ public function test_vote_costs_exponentially()
$this->assertEquals(3, $user->voteOn($idea, 14));
$this->assertEquals(0, $user->getVoteCredits(), "Cant spend correctly");
$this->assertEquals(3, $idea->getCountVotes());

}

public function test_cant_vote_without_credits()
Expand All @@ -131,7 +126,6 @@ public function test_cant_vote_more_than_his_credits()
$user->giveVoteCredits(5);

$user->voteOn($idea, 14);

}

/** @test */
Expand All @@ -147,7 +141,6 @@ public function test_two_voters_can_vote_same_idea()
$user2->voteOn($idea, 14);

$this->assertEquals(6, $idea->getCountVotes());

}

public function test_give_vote_credits_massively()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
/**
* Dummy table
*/
return new class extends Migration
{
return new class () extends Migration {
/**
* Run the migrations.
*
Expand Down