Lint PHP code psr-12, add GH action
This commit is contained in:
@@ -3,15 +3,14 @@
|
||||
namespace App\Jobs\Form;
|
||||
|
||||
use App\Events\Forms\FormSubmitted;
|
||||
use App\Http\Controllers\Forms\PublicFormController;
|
||||
use App\Http\Controllers\Forms\FormController;
|
||||
use App\Http\Controllers\Forms\PublicFormController;
|
||||
use App\Http\Requests\AnswerFormRequest;
|
||||
use App\Models\Forms\Form;
|
||||
use App\Models\Forms\FormSubmission;
|
||||
use App\Service\Forms\FormLogicPropertyResolver;
|
||||
use App\Service\Storage\StorageFileNameParser;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Filesystem\Filesystem;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
@@ -22,7 +21,10 @@ use Vinkla\Hashids\Facades\Hashids;
|
||||
|
||||
class StoreFormSubmissionJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
use Dispatchable;
|
||||
use InteractsWithQueue;
|
||||
use Queueable;
|
||||
use SerializesModels;
|
||||
|
||||
public ?string $submissionId = null;
|
||||
|
||||
@@ -47,7 +49,7 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
|
||||
$this->storeSubmission($formData);
|
||||
|
||||
$formData["submission_id"] = $this->submissionId;
|
||||
$formData['submission_id'] = $this->submissionId;
|
||||
FormSubmitted::dispatch($this->form, $formData);
|
||||
}
|
||||
|
||||
@@ -59,6 +61,7 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
public function setSubmissionId(int $id)
|
||||
{
|
||||
$this->submissionId = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -82,12 +85,13 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
*/
|
||||
private function submissionToUpdate(): ?FormSubmission
|
||||
{
|
||||
if($this->submissionId){
|
||||
if ($this->submissionId) {
|
||||
return $this->form->submissions()->findOrFail($this->submissionId);
|
||||
}
|
||||
if ($this->form->editable_submissions && isset($this->submissionData['submission_id']) && $this->submissionData['submission_id']) {
|
||||
$submissionId = $this->submissionData['submission_id'] ? Hashids::decode($this->submissionData['submission_id']) : false;
|
||||
$submissionId = $submissionId[0] ?? null;
|
||||
|
||||
return $this->form->submissions()->findOrFail($submissionId);
|
||||
}
|
||||
|
||||
@@ -111,7 +115,7 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
// Do required transformation per type (e.g. file uploads)
|
||||
foreach ($data as $answerKey => $answerValue) {
|
||||
$field = $properties->where('id', $answerKey)->first();
|
||||
if (!$field) {
|
||||
if (! $field) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -128,10 +132,10 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
}
|
||||
} else {
|
||||
if ($field['type'] == 'text' && isset($field['generates_uuid']) && $field['generates_uuid']) {
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? Str::uuid() : "Please upgrade your OpenForm subscription to use our ID generation features";
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? Str::uuid() : 'Please upgrade your OpenForm subscription to use our ID generation features';
|
||||
} else {
|
||||
if ($field['type'] == 'text' && isset($field['generates_auto_increment_id']) && $field['generates_auto_increment_id']) {
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? (string) ($this->form->submissions_count + 1) : "Please upgrade your OpenForm subscription to use our ID generation features";
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? (string) ($this->form->submissions_count + 1) : 'Please upgrade your OpenForm subscription to use our ID generation features';
|
||||
} else {
|
||||
$finalData[$field['id']] = $answerValue;
|
||||
}
|
||||
@@ -139,12 +143,12 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
}
|
||||
|
||||
// For Singrature
|
||||
if($this->form->is_pro && $field['type'] == 'signature') {
|
||||
if ($this->form->is_pro && $field['type'] == 'signature') {
|
||||
$finalData[$field['id']] = $this->storeSignature($answerValue);
|
||||
}
|
||||
|
||||
// For Phone
|
||||
if($field['type'] == 'phone_number' && $answerValue && ctype_alpha(substr($answerValue, 0, 2)) && (!isset($field['use_simple_text_input']) || !$field['use_simple_text_input'])) {
|
||||
if ($field['type'] == 'phone_number' && $answerValue && ctype_alpha(substr($answerValue, 0, 2)) && (! isset($field['use_simple_text_input']) || ! $field['use_simple_text_input'])) {
|
||||
$finalData[$field['id']] = substr($answerValue, 2);
|
||||
}
|
||||
}
|
||||
@@ -156,6 +160,7 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
private function isSkipForUpload($value)
|
||||
{
|
||||
$newPath = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $this->form->id);
|
||||
|
||||
return Storage::exists($newPath.'/'.$value);
|
||||
}
|
||||
|
||||
@@ -173,15 +178,16 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
return null;
|
||||
}
|
||||
|
||||
if(filter_var($value, FILTER_VALIDATE_URL) !== false && str_contains($value, parse_url(config('app.url'))['host'])) { // In case of prefill we have full url so convert to s3
|
||||
if (filter_var($value, FILTER_VALIDATE_URL) !== false && str_contains($value, parse_url(config('app.url'))['host'])) { // In case of prefill we have full url so convert to s3
|
||||
$fileName = basename($value);
|
||||
$path = FormController::ASSETS_UPLOAD_PATH . '/' . $fileName;
|
||||
$path = FormController::ASSETS_UPLOAD_PATH.'/'.$fileName;
|
||||
$newPath = Str::of(PublicFormController::FILE_UPLOAD_PATH)->replace('?', $this->form->id);
|
||||
Storage::move($path, $newPath.'/'.$fileName);
|
||||
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
if($this->isSkipForUpload($value)) {
|
||||
if ($this->isSkipForUpload($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
@@ -189,7 +195,7 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
|
||||
// Make sure we retrieve the file in tmp storage, move it to persistent
|
||||
$fileName = PublicFormController::TMP_FILE_UPLOAD_PATH.'/'.$fileNameParser->uuid;
|
||||
if (!Storage::exists($fileName)) {
|
||||
if (! Storage::exists($fileName)) {
|
||||
// File not found, we skip
|
||||
return null;
|
||||
}
|
||||
@@ -209,7 +215,7 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
|
||||
private function storeSignature(?string $value)
|
||||
{
|
||||
if ($value == null || !isset(explode(',', $value)[1])) {
|
||||
if ($value == null || ! isset(explode(',', $value)[1])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -225,7 +231,6 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
/**
|
||||
* Adds prefill from hidden fields
|
||||
*
|
||||
* @param array $formData
|
||||
* @param AnswerFormRequest $request
|
||||
*/
|
||||
private function addHiddenPrefills(array &$formData): void
|
||||
@@ -235,9 +240,9 @@ class StoreFormSubmissionJob implements ShouldQueue
|
||||
return isset($property['hidden'])
|
||||
&& isset($property['prefill'])
|
||||
&& FormLogicPropertyResolver::isHidden($property, $this->submissionData)
|
||||
&& !is_null($property['prefill'])
|
||||
&& !in_array($property['type'], ['files'])
|
||||
&& !($property['type'] == 'url' && isset($property['file_upload']) && $property['file_upload']);
|
||||
&& ! is_null($property['prefill'])
|
||||
&& ! in_array($property['type'], ['files'])
|
||||
&& ! ($property['type'] == 'url' && isset($property['file_upload']) && $property['file_upload']);
|
||||
})->each(function (array $property) use (&$formData) {
|
||||
if ($property['type'] === 'date' && isset($property['prefill_today']) && $property['prefill_today']) {
|
||||
$formData[$property['id']] = now()->format((isset($property['with_time']) && $property['with_time']) ? 'Y-m-d H:i' : 'Y-m-d');
|
||||
|
||||
Reference in New Issue
Block a user