Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Jul 15, 2023
1 parent 6737cf6 commit 7eb6264
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
11 changes: 10 additions & 1 deletion migrations/2023_07_14_000000_create_polls_settings_column.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<?php

/*
* This file is part of fof/polls.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Flarum\Database\Migration;

return Migration::addColumns('polls', [
'settings' => ['json']
'settings' => ['json'],
]);
17 changes: 13 additions & 4 deletions migrations/2023_07_14_000001_polls_use_settings_column.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of fof/polls.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Illuminate\Database\Schema\Builder;

return [
Expand All @@ -9,7 +18,7 @@
$db->table('polls')
->select(1)
->update([
'settings' => $db->raw(<<<SQL
'settings' => $db->raw(<<<'SQL'
JSON_OBJECT(
"public_poll", public_poll,
"allow_multiple_votes", allow_multiple_votes,
Expand All @@ -24,9 +33,9 @@
$db->table('polls')
->select(1)
->update([
'public_poll' => $db->raw('JSON_EXTRACT(settings, "$.public_poll")'),
'public_poll' => $db->raw('JSON_EXTRACT(settings, "$.public_poll")'),
'allow_multiple_votes' => $db->raw('JSON_EXTRACT(settings, "$.allow_multiple_votes")'),
'max_votes' => $db->raw('JSON_EXTRACT(settings, "$.max_votes")'),
'max_votes' => $db->raw('JSON_EXTRACT(settings, "$.max_votes")'),
]);
}
},
];
13 changes: 11 additions & 2 deletions migrations/2023_07_14_000002_delete_extra_polls_columns.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?php

/*
* This file is part of fof/polls.
*
* Copyright (c) FriendsOfFlarum.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

use Flarum\Database\Migration;

return Migration::dropColumns('polls', [
'public_poll' => ['boolean', 'default' => false],
'public_poll' => ['boolean', 'default' => false],
'allow_multiple_votes' => ['boolean', 'default' => false],
'max_votes' => ['integer', 'unsigned' => true, 'default' => 0],
'max_votes' => ['integer', 'unsigned' => true, 'default' => 0],
]);
17 changes: 10 additions & 7 deletions src/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
use Illuminate\Support\Arr;

/**
* @property int $id
* @property string $question
* @property int $id
* @property string $question
* @property-read bool $public_poll
* @property-read bool $allow_multiple_votes
* @property-read int $max_votes
Expand Down Expand Up @@ -79,9 +79,9 @@ public static function build($question, $postId, $actorId, $endDate, $publicPoll
$poll->user_id = $actorId;
$poll->end_date = $endDate;
$poll->settings = [
'public_poll' => $publicPoll,
'public_poll' => $publicPoll,
'allow_multiple_votes' => $allowMultipleVotes,
'max_votes' => min(0, (int) $maxVotes),
'max_votes' => min(0, (int) $maxVotes),
];

return $poll;
Expand Down Expand Up @@ -148,15 +148,18 @@ public static function setStateUser(User $user)
static::$stateUser = $user;
}

protected function getPublicPollAttribute() {
protected function getPublicPollAttribute()
{
return (bool) Arr::get($this->settings, 'public_poll');
}

protected function getAllowMultipleVotesAttribute() {
protected function getAllowMultipleVotesAttribute()
{
return (bool) Arr::get($this->settings, 'allow_multiple_votes');
}

protected function getMaxVotesAttribute() {
protected function getMaxVotesAttribute()
{
return (int) Arr::get($this->settings, 'max_votes');
}

Expand Down

0 comments on commit 7eb6264

Please sign in to comment.