From 264afc703b6929c5443ef8d23b783b72179609a5 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Wed, 29 Mar 2023 17:52:11 +0000 Subject: [PATCH] style: Format code with php-cs-fixer Format code with php-cs-fixer This commit fixes the style issues introduced in 57086f2 according to the output from php-cs-fixer. Details: https://deepsource.io/gh/Punksolid/laravel-quadratic-voting/transform/3798c5f1-1490-4c35-bf04-5225a19f99fd/ --- database/factories/PoliticianFactory.php | 2 -- database/factories/UserFactory.php | 1 - .../migrations/2018_10_26_074757_create_votes_table.php | 1 - rector.php | 1 - src/Interfaces/IsVotableInterface.php | 1 - src/Interfaces/VoterInterface.php | 3 +-- src/Models/Idea.php | 1 - src/Models/Politician.php | 1 - src/Models/User.php | 3 --- src/Models/VoteCredit.php | 1 - src/Providers/LaravelQuadraticVotingServiceProvider.php | 4 ---- src/Services/QuadraticVoteService.php | 2 -- src/Traits/VoterTrait.php | 9 +++------ tests/IsVotableTest.php | 2 -- tests/TestCase.php | 1 - tests/UserVotesTest.php | 7 ------- tests/VotingTest.php | 7 ------- .../migrations/2023_03_09_210510_create_ideas_table.php | 3 +-- .../2023_03_09_210511_create_politicians_table.php | 3 +-- 19 files changed, 6 insertions(+), 47 deletions(-) diff --git a/database/factories/PoliticianFactory.php b/database/factories/PoliticianFactory.php index fb90cde..ea15dc0 100644 --- a/database/factories/PoliticianFactory.php +++ b/database/factories/PoliticianFactory.php @@ -5,8 +5,6 @@ use Illuminate\Database\Eloquent\Factories\Factory; use LaravelQuadraticVoting\Models\Politician; - - class PoliticianFactory extends Factory { protected $model = Politician::class; diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 8d461fa..2f887cc 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -8,7 +8,6 @@ class UserFactory extends Factory { - protected $model = User::class; /** diff --git a/database/migrations/2018_10_26_074757_create_votes_table.php b/database/migrations/2018_10_26_074757_create_votes_table.php index d752a0b..ba56bd9 100644 --- a/database/migrations/2018_10_26_074757_create_votes_table.php +++ b/database/migrations/2018_10_26_074757_create_votes_table.php @@ -23,7 +23,6 @@ public function up() $table->integer('quantity')->nullable(); $table->timestamps(); }); - } /** diff --git a/rector.php b/rector.php index 7ac4b62..f8d9200 100644 --- a/rector.php +++ b/rector.php @@ -66,5 +66,4 @@ $rectorConfig->rule(JoinStringConcatRector::class); $rectorConfig->rule(LogicalToBooleanRector::class); $rectorConfig->rule(NarrowUnionTypeDocRector::class); - }; diff --git a/src/Interfaces/IsVotableInterface.php b/src/Interfaces/IsVotableInterface.php index 5de0ee6..2e0e86c 100644 --- a/src/Interfaces/IsVotableInterface.php +++ b/src/Interfaces/IsVotableInterface.php @@ -12,5 +12,4 @@ public function voters(): BelongsToMany; public function getCountVotes(): int; public function getVoters(): \Illuminate\Support\Collection; - } diff --git a/src/Interfaces/VoterInterface.php b/src/Interfaces/VoterInterface.php index 90b9ba8..15a40e3 100644 --- a/src/Interfaces/VoterInterface.php +++ b/src/Interfaces/VoterInterface.php @@ -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; } diff --git a/src/Models/Idea.php b/src/Models/Idea.php index 5dcd1ad..fcb08b2 100644 --- a/src/Models/Idea.php +++ b/src/Models/Idea.php @@ -2,7 +2,6 @@ namespace LaravelQuadraticVoting\Models; - use Database\Factories\IdeaFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; diff --git a/src/Models/Politician.php b/src/Models/Politician.php index 74a9a2f..c69a69f 100644 --- a/src/Models/Politician.php +++ b/src/Models/Politician.php @@ -2,7 +2,6 @@ namespace LaravelQuadraticVoting\Models; - use Database\Factories\IdeaFactory; use Database\Factories\PoliticianFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; diff --git a/src/Models/User.php b/src/Models/User.php index 87023d7..9abd36e 100644 --- a/src/Models/User.php +++ b/src/Models/User.php @@ -2,7 +2,6 @@ namespace LaravelQuadraticVoting\Models; - use Database\Factories\UserFactory; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -14,7 +13,6 @@ */ class User extends Model implements VoterInterface { - use VoterTrait; use HasFactory; @@ -24,5 +22,4 @@ protected static function newFactory() { return UserFactory::new(); } - } diff --git a/src/Models/VoteCredit.php b/src/Models/VoteCredit.php index d2319f7..f5e9e41 100644 --- a/src/Models/VoteCredit.php +++ b/src/Models/VoteCredit.php @@ -20,5 +20,4 @@ public function voter(): BelongsTo { return $this->belongsTo(VoterInterface::class, 'voter_id'); } - } diff --git a/src/Providers/LaravelQuadraticVotingServiceProvider.php b/src/Providers/LaravelQuadraticVotingServiceProvider.php index fa034a4..2a42256 100644 --- a/src/Providers/LaravelQuadraticVotingServiceProvider.php +++ b/src/Providers/LaravelQuadraticVotingServiceProvider.php @@ -1,6 +1,5 @@ registerModelBindings(); - - } /** @@ -53,5 +50,4 @@ private function registerModelBindings() $this->app->bind(VoterInterface::class, $config['voter']); $this->app->bind(IsVotableInterface::class, $config['vote_credit']); } - } diff --git a/src/Services/QuadraticVoteService.php b/src/Services/QuadraticVoteService.php index 5a7c6dc..2943f5b 100644 --- a/src/Services/QuadraticVoteService.php +++ b/src/Services/QuadraticVoteService.php @@ -88,6 +88,4 @@ public function getCostOfVoteNumber(int $vote): int { return $vote * $vote; } - - } diff --git a/src/Traits/VoterTrait.php b/src/Traits/VoterTrait.php index d547fdf..7513160 100644 --- a/src/Traits/VoterTrait.php +++ b/src/Traits/VoterTrait.php @@ -8,7 +8,6 @@ namespace LaravelQuadraticVoting\Traits; - use Exception; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -63,7 +62,6 @@ public function voteOn(Model $model, int $vote_credits = 1): int $this->spendCredits($vote_credits); return $votes_quantity; - } /** @@ -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 @@ -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", @@ -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); @@ -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() diff --git a/tests/IsVotableTest.php b/tests/IsVotableTest.php index b735b36..e9ea584 100644 --- a/tests/IsVotableTest.php +++ b/tests/IsVotableTest.php @@ -45,6 +45,4 @@ public function test_user_can_vote_another_entity(): void $user->voteOn($politician, 4); $this->assertEquals(9, $user->getNextVoteCost($politician)); } - - } diff --git a/tests/TestCase.php b/tests/TestCase.php index cfa4c6e..f684732 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,7 +7,6 @@ class TestCase extends \Orchestra\Testbench\TestCase { - protected function getEnvironmentSetUp($app) { // Setup default database to use sqlite :memory: diff --git a/tests/UserVotesTest.php b/tests/UserVotesTest.php index 520a5b6..305e247 100644 --- a/tests/UserVotesTest.php +++ b/tests/UserVotesTest.php @@ -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(); @@ -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(); @@ -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 @@ -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 */ @@ -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 */ @@ -193,6 +188,4 @@ public function it_can_downvote_two_different_ideas() $this->assertEquals(100, $user->getVoteCredits()); } - - } diff --git a/tests/VotingTest.php b/tests/VotingTest.php index 0ad7704..a652fb2 100644 --- a/tests/VotingTest.php +++ b/tests/VotingTest.php @@ -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(); @@ -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(); @@ -86,7 +84,6 @@ 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() @@ -94,7 +91,6 @@ public function test_get_votes_default() $idea = Idea::factory()->create(); $this->assertEquals(0, $idea->getCountVotes()); - } public function test_vote_costs_exponentially() @@ -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() @@ -131,7 +126,6 @@ public function test_cant_vote_more_than_his_credits() $user->giveVoteCredits(5); $user->voteOn($idea, 14); - } /** @test */ @@ -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() diff --git a/tests/database/migrations/2023_03_09_210510_create_ideas_table.php b/tests/database/migrations/2023_03_09_210510_create_ideas_table.php index 939527a..3609fc4 100644 --- a/tests/database/migrations/2023_03_09_210510_create_ideas_table.php +++ b/tests/database/migrations/2023_03_09_210510_create_ideas_table.php @@ -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. * diff --git a/tests/database/migrations/2023_03_09_210511_create_politicians_table.php b/tests/database/migrations/2023_03_09_210511_create_politicians_table.php index 035a5ca..1027826 100644 --- a/tests/database/migrations/2023_03_09_210511_create_politicians_table.php +++ b/tests/database/migrations/2023_03_09_210511_create_politicians_table.php @@ -7,8 +7,7 @@ /** * Dummy table */ -return new class extends Migration -{ +return new class () extends Migration { /** * Run the migrations. *