Skip to content

Commit

Permalink
fix: phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 12, 2023
1 parent 08b8c39 commit e473f5e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 28 deletions.
4 changes: 0 additions & 4 deletions src/Access/FieldPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class FieldPolicy extends AbstractPolicy
*
* @param User $user
* @param Field $field
*
* @return bool
*/
public function useCustomAnswer(User $user, Field $field)
{
Expand All @@ -37,8 +35,6 @@ public function useCustomAnswer(User $user, Field $field)
*
* @param User $user
* @param Field $field
*
* @return bool
*/
public function skipField(User $user, Field $field)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Api/Serializers/FieldSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class FieldSerializer extends AbstractSerializer
/**
* Get the default set of serialized attributes for a model.
*
* @param Field|array $model
* @param Field $model
*
* @return array
*/
Expand All @@ -41,7 +41,7 @@ protected function getDefaultAttributes($model)
public function suggestedAnswers($model)
{
/**
* @var $answers AnswerRepository
* @var AnswerRepository $answers
*/
$answers = resolve(AnswerRepository::class);

Expand All @@ -51,18 +51,18 @@ public function suggestedAnswers($model)
/**
* @param Field $model
*
* @return Relationship
* @return Relationship|null
*/
public function allAnswers($model)
{
$actor = $this->getActor();

if (!$actor || !$actor->isAdmin()) {
if (!$actor->isAdmin()) {
return null;
}

/**
* @var $answers AnswerRepository
* @var AnswerRepository $answers
*/
$answers = resolve(AnswerRepository::class);

Expand Down
29 changes: 17 additions & 12 deletions src/ForumAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@

class ForumAttributes
{
/**
* @var SettingsRepositoryInterface
*/
protected $settings;

public function __construct(SettingsRepositoryInterface $settings)
{
$this->settings = $settings;
}

public function __invoke(ForumSerializer $serializer): array
{
/**
* @var $settings SettingsRepositoryInterface
*/
$settings = resolve(SettingsRepositoryInterface::class);

$actor = $serializer->getActor();

$canFill = $actor->can('fof-mason.fill-fields');
Expand All @@ -33,19 +38,19 @@ public function __invoke(ForumSerializer $serializer): array
];

if ($canFill || $canSeeSome) {
$attributes['fof-mason.fields-section-title'] = $settings->get('fof-mason.fields-section-title', '');
$attributes['fof-mason.column-count'] = (int) $settings->get('fof-mason.column-count', 1);
$attributes['fof-mason.fields-section-title'] = $this->settings->get('fof-mason.fields-section-title', '');
$attributes['fof-mason.column-count'] = (int) $this->settings->get('fof-mason.column-count', 1);
}

if ($canFill) {
$attributes['fof-mason.labels-as-placeholders'] = (bool) $settings->get('fof-mason.labels-as-placeholders', false);
$attributes['fof-mason.tags-as-fields'] = (bool) $settings->get('fof-mason.tags-as-fields', false);
$attributes['fof-mason.tags-field-name'] = $settings->get('fof-mason.tags-field-name', '');
$attributes['fof-mason.labels-as-placeholders'] = (bool) $this->settings->get('fof-mason.labels-as-placeholders', false);
$attributes['fof-mason.tags-as-fields'] = (bool) $this->settings->get('fof-mason.tags-as-fields', false);
$attributes['fof-mason.tags-field-name'] = $this->settings->get('fof-mason.tags-field-name', '');
}

if ($canSeeSome) {
$attributes['fof-mason.fields-in-hero'] = (bool) $settings->get('fof-mason.fields-in-hero', false);
$attributes['fof-mason.hide-empty-fields-section'] = (bool) $settings->get('fof-mason.hide-empty-fields-section', false);
$attributes['fof-mason.fields-in-hero'] = (bool) $this->settings->get('fof-mason.fields-in-hero', false);
$attributes['fof-mason.hide-empty-fields-section'] = (bool) $this->settings->get('fof-mason.hide-empty-fields-section', false);
}

return $attributes;
Expand Down
6 changes: 3 additions & 3 deletions src/Listeners/DiscussionSaving.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ protected function fillOrUpdateFields(Saving $event)
$answer = $this->answers->findOrFail($id);
} elseif (Arr::has($answerRelation, 'attributes.content') && Arr::has($answerRelation, 'relationships.field.data.id')) {
$field = $this->fields->findOrFail(Arr::get($answerRelation, 'relationships.field.data.id'));
$content = trim(Arr::get($answerRelation, 'attributes.content'));
$content = trim(Arr::get($answerRelation, 'attributes.content', ''));

/**
* @var $answerValidator UserAnswerValidator
* @var UserAnswerValidator $answerValidator
*/
$answerValidator = resolve(UserAnswerValidator::class);
$answerValidator->setField($field);
Expand All @@ -100,7 +100,7 @@ protected function fillOrUpdateFields(Saving $event)

// If the field is empty, we skip the findOrCreate part
// It will also not be counted towards the field answers count
if ($content === null || $content === '') {
if ($content === '') {
continue;
}

Expand Down
5 changes: 1 addition & 4 deletions src/Repositories/FieldRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,13 @@ protected function query(): Builder
/**
* @param $id
*
* @return Field|Model
* @return Field
*/
public function findOrFail($id): Field
{
return $this->field->newQuery()->findOrFail($id);
}

/**
* @return Collection|Field[]
*/
public function all(): Collection
{
return $this->query()->get();
Expand Down

0 comments on commit e473f5e

Please sign in to comment.