Completed
Pull Request — develop (#48)
by
unknown
01:11
created

TenantsController::form()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cortex\Tenants\Http\Controllers\Managerarea;
6
7
use Exception;
8
use Cortex\Tenants\Models\Tenant;
9
use Illuminate\Foundation\Http\FormRequest;
10
use Cortex\Foundation\Http\Controllers\AuthenticatedController;
11
12
class TenantsController extends AuthenticatedController
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    protected $resource = Tenant::class;
18
    /**
19
     * Show tenant create/edit form.
20
     *
21
     * @param \Cortex\Tenants\Models\Tenant $tenant
0 ignored issues
show
Bug introduced by
There is no parameter named $tenant. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
22
     *
23
     * @return \Illuminate\View\View
24
     */
25
    protected function form()
26
    {
27
        $tenant = config('rinvex.tenants.active');
28
        $countries = collect(countries())->map(function ($country, $code) {
29
            return [
30
                'id' => $code,
31
                'text' => $country['name'],
32
                'emoji' => $country['emoji'],
33
            ];
34
        })->values();
35
36
        $tags = app('rinvex.tags.tag')->pluck('name', 'id');
37
        $languages = collect(languages())->pluck('name', 'iso_639_1');
38
        return view('cortex/tenants::managerarea.pages.tenant', compact('tenant', 'countries', 'languages', 'tags'));
39
    }
40
41
    /**
42
     * Process stored/updated tenant.
43
     *
44
     * @param \Cortex\Tenants\Http\Requests\Managerarea\TenantFormRequest $request
0 ignored issues
show
Documentation introduced by
Should the type for parameter $request not be TenantFormRequest?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
45
     * @param \Cortex\Tenants\Models\Tenant                               $tenant
0 ignored issues
show
Bug introduced by
There is no parameter named $tenant. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
46
     *
47
     * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
48
     */
49
    protected function process(TenantFormRequest $request)
50
    {
51
        $tenant = config('rinvex.tenants.active');
52
        // Prepare required input fields
53
        $data = $request->validated();
54
55
        ! $request->hasFile('profile_picture')
56
        || $tenant->addMediaFromRequest('profile_picture')
57
                       ->sanitizingFileName(function ($fileName) {
58
                           return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION);
59
                       })
60
                       ->toMediaCollection('profile_picture', config('cortex.auth.media.disk'));
61
62
        ! $request->hasFile('cover_photo')
63
        || $tenant->addMediaFromRequest('cover_photo')
64
                       ->sanitizingFileName(function ($fileName) {
65
                           return md5($fileName).'.'.pathinfo($fileName, PATHINFO_EXTENSION);
66
                       })
67
                       ->toMediaCollection('cover_photo', config('cortex.auth.media.disk'));
68
69
        // Save tenant
70
        $tenant->fill($data)->save();
71
72
        return intend([
73
            'back' => true,
74
            'with' => ['success' => trans('cortex/foundation::messages.resource_saved', ['resource' => trans('cortex/tenants::common.tenant'), 'identifier' => $tenant->name])],
75
        ]);
76
    }
77
78
}
79