Skip to content

Commit

Permalink
Merge pull request #1 from matt-daneshvar/analysis-zeg2j7
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
matt-daneshvar authored Aug 21, 2019
2 parents 63662c0 + 4d108be commit 8c7c2f8
Show file tree
Hide file tree
Showing 23 changed files with 152 additions and 159 deletions.
4 changes: 2 additions & 2 deletions database/factories/AnswerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
$factory->define(Answer::class, function (Faker $faker) {
return [
'value' => $faker->text(10),
'question_id' => factory(Question::class)->create()->id
'question_id' => factory(Question::class)->create()->id,
];
});
});
2 changes: 1 addition & 1 deletion database/factories/QuestionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
return [
'content' => $faker->name,
];
});
});
2 changes: 1 addition & 1 deletion database/factories/SurveyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
return [
'name' => $faker->name,
];
});
});
6 changes: 3 additions & 3 deletions src/Exceptions/GuestEntriesNotAllowedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class GuestEntriesNotAllowedException extends Exception
{
/**
* The exception message.
*
* @var string
*
* @var string
*/
protected $message = 'Login is required for this survey.';
}
}
2 changes: 1 addition & 1 deletion src/Exceptions/MaxEntriesPerUserLimitExceeded.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ class MaxEntriesPerUserLimitExceeded extends Exception
* @var string
*/
protected $message = 'Maximum entries per user exceeded.';
}
}
10 changes: 5 additions & 5 deletions src/Http/View/Composers/SurveyComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace MattDaneshvar\Survey\Http\View\Composers;

use Illuminate\Contracts\Auth\Guard;
use Illuminate\View\View;
use Illuminate\Contracts\Auth\Guard;

class SurveyComposer
{
protected $auth;

/**
* SurveyComposer constructor.
*
*
* @param Guard $auth
*/
public function __construct(Guard $auth)
Expand All @@ -21,14 +21,14 @@ public function __construct(Guard $auth)

/**
* Compose the view with relevant values.
*
*
* @param View $view
*/
public function compose(View $view)
{
$view->with([
'eligible' => $view->survey->isEligible($this->auth->user()),
'lastEntry' => $view->survey->lastEntry(auth()->user())
'lastEntry' => $view->survey->lastEntry(auth()->user()),
]);
}
}
}
6 changes: 3 additions & 3 deletions src/Models/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Answer extends Model

/**
* The entry the answer belongs to.
*
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function entry()
Expand All @@ -25,11 +25,11 @@ public function entry()

/**
* The question the answer belongs to.
*
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function question()
{
return $this->belongsTo(Question::class);
}
}
}
31 changes: 16 additions & 15 deletions src/Models/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace MattDaneshvar\Survey\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User;
use MattDaneshvar\Survey\Exceptions\GuestEntriesNotAllowedException;
use Illuminate\Database\Eloquent\Model;
use MattDaneshvar\Survey\Exceptions\MaxEntriesPerUserLimitExceeded;
use MattDaneshvar\Survey\Exceptions\GuestEntriesNotAllowedException;

class Entry extends Model
{
Expand All @@ -26,15 +26,15 @@ protected static function boot()
parent::boot();

//Prevent submission of entries that don't meet the parent survey.
static::creating(function (Entry $entry) {
static::creating(function (self $entry) {
$entry->validateParticipant();
$entry->validateMaxEntryPerUserRequirement();
});
}

/**
* The answers within the entry.
*
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function answers()
Expand All @@ -44,7 +44,7 @@ public function answers()

/**
* The survey the entry belongs to.
*
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function survey()
Expand All @@ -54,7 +54,7 @@ public function survey()

/**
* The participant that the entry belongs to.
*
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function participant()
Expand All @@ -64,7 +64,7 @@ public function participant()

/**
* Set the survey the entry belongs to.
*
*
* @param Survey $survey
* @return $this
*/
Expand All @@ -77,7 +77,7 @@ public function for(Survey $survey)

/**
* Set the participant who the entry belongs to.
*
*
* @param Model|null $model
* @return $this
*/
Expand All @@ -90,7 +90,7 @@ public function by(Model $model = null)

/**
* Create an entry from an array.
*
*
* @param array $values
* @return $this
*/
Expand All @@ -104,7 +104,7 @@ public function fromArray(array $values)
$this->answers->add(Answer::make([
'question_id' => substr($key, 1),
'entry_id' => $this->id,
'value' => $value
'value' => $value,
]));
}

Expand All @@ -113,13 +113,14 @@ public function fromArray(array $values)

/**
* The answer for a given question.
*
*
* @param Question $question
* @return mixed|null
*/
public function answerFor(Question $question)
{
$answer = $this->answers()->where('question_id', $question->id)->first();

return isset($answer) ? $answer->value : null;
}

Expand All @@ -142,7 +143,7 @@ public function push()

/**
* Validate participant's legibility.
*
*
* @throws GuestEntriesNotAllowedException
*/
public function validateParticipant()
Expand All @@ -159,9 +160,9 @@ public function validateParticipant()
}

/**
* Validate if entry exceeds the survey's
* Validate if entry exceeds the survey's
* max entry per participant limit.
*
*
* @throws MaxEntriesPerUserLimitExceeded
*/
public function validateMaxEntryPerUserRequirement()
Expand All @@ -178,4 +179,4 @@ public function validateMaxEntryPerUserRequirement()
throw new MaxEntriesPerUserLimitExceeded();
}
}
}
}
26 changes: 13 additions & 13 deletions src/Models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Question extends Model
* @var array
*/
protected $fillable = ['type', 'options', 'content', 'rules', 'survey_id'];

protected $casts = [
'rules' => 'array',
'options' => 'array',
Expand All @@ -28,19 +28,18 @@ protected static function boot()
parent::boot();

//Ensure the question's survey is the same as the section it belongs to.
static::creating(function (Question $question) {
static::creating(function (self $question) {
$question->load('section');

if($question->section)
{

if ($question->section) {
$question->survey_id = $question->section->survey_id;
}
});
}

/**
* The survey the question belongs to.
*
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function survey()
Expand All @@ -50,7 +49,7 @@ public function survey()

/**
* The section the question belongs to.
*
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function section()
Expand All @@ -60,7 +59,7 @@ public function section()

/**
* The answers that belong to the question.
*
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function answers()
Expand All @@ -70,19 +69,20 @@ public function answers()

/**
* The question's validation rules.
*
*
* @param $value
* @return array|mixed
*/
public function getRulesAttribute($value)
{
$value = $this->castAttribute('rules', $value);

return $value !== null ? $value : [];
}

/**
* The unique key representing the question.
*
*
* @return string
*/
public function getKeyAttribute()
Expand All @@ -91,14 +91,14 @@ public function getKeyAttribute()
}

/**
* Scope a query to only include questions that
* Scope a query to only include questions that
* don't belong to any sections.
*
*
* @param $query
* @return mixed
*/
public function scopeWithoutSection($query)
{
return $query->where('section_id', null);
}
}
}
4 changes: 2 additions & 2 deletions src/Models/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class Section extends Model

/**
* The questions of the section.
*
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function questions()
{
return $this->hasMany(Question::class);
}
}
}
Loading

0 comments on commit 8c7c2f8

Please sign in to comment.