Passed
Push — dev5 ( 1140b1...da16e0 )
by Ron
09:38
created

SettingsController::sendTestEmail()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 61

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 0
cts 3
cp 0
rs 8.8509
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace App\Http\Controllers\Installer;
4
5
use App\User;
6
use App\Settings;
7
use Carbon\Carbon;
8
use App\Mail\TestEmail;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\Log;
11
use Illuminate\Support\Facades\Auth;
12
use Illuminate\Support\Facades\Mail;
13
use App\Http\Controllers\Controller;
14
use Illuminate\Support\Facades\Route;
15
use Illuminate\Support\Facades\Config;
16
use Illuminate\Support\Facades\Storage;
17
use Illuminate\Support\Facades\Artisan;
18
19
class SettingsController extends Controller
20
{
21 24
    public function __construct()
22
    {
23 24
        $this->middleware(['auth', 'can:is_installer']);
24 24
    }
25
26
    //  Bring up the change logo form
27 2
    public function logoSettings()
28
    {
29 2
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
30
31 2
        return view('installer.logoSettings');
32
    }
33
    //  Submit the new company logo
34 2
    public function submitLogo(Request $request)
35
    {
36 2
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray());
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
37
38 2
        $request->validate([
0 ignored issues
show
Bug introduced by
The call to validate() misses a required argument $...$params.

This check looks for function calls that miss required arguments.

Loading history...
39 2
            'file' => 'mimes:jpeg,bmp,png,jpg,gif'
40
        ]);
41
42 2
        $file     = $request->file;
43 2
        $fileName = $file->getClientOriginalName();
44 2
        $file->storeAs('img', $fileName, 'public');
45
46 2
        Settings::firstOrCreate(
47 2
            ['key'   => 'app.logo'],
48 2
            ['key'   => 'app.logo', 'value' => '/storage/img/'.$fileName]
49 2
        )->update(['value' => '/storage/img/'.$fileName]);
50
51 2
        Log::notice('A new company logo has been uploaded by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
52
53 2
        return response()->json(['url' => '/storage/img/'.$fileName]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
54
    }
55
56 2
    public function configuration()
57
    {
58 2
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
59
60 2
        $settings = collect([
61
            // 'url'      => config('app.url'),
62 2
            'timezone' => config('app.timezone'),
63 2
            'filesize' => config('filesystems.paths.max_size'),
64
        ]);
65
66 2
        return view('installer.configuration', [
67 2
            'timzone_list' => \Timezonelist::toArray(),
68 2
            'settings'     => $settings,
69
        ]);
70
    }
71
72 2
    public function submitConfiguration(Request $request)
73
    {
74 2
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray());
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
75
76 2
        $request->validate([
0 ignored issues
show
Bug introduced by
The call to validate() misses a required argument $...$params.

This check looks for function calls that miss required arguments.

Loading history...
77 2
            'timezone' => 'required',
78
            'filesize' => 'required',
79
            //  TODO - add additinal validation to make sure proper information is passed in
80
        ]);
81
82
        //  Update the site timezone
83 2 View Code Duplication
        if (config('app.timezone') !== $request->timezone)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
        {
85 2
            Settings::firstOrCreate(
86 2
                ['key'   => 'app.timezone'],
87 2
                ['key'   => 'app.timezone', 'value' => $request->timezone]
88 2
            )->update(['value' => $request->timezone]);
89
        }
90
        //  Update the maximum file upload size
91 2 View Code Duplication
        if (config('filesystems.paths.max_size') !== $request->filesize)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
92
        {
93 2
            Settings::firstOrCreate(
94 2
                ['key'   => 'filesystems.paths.max_size'],
95 2
                ['key'   => 'filesystems.paths.max_size', 'value' => $request->filesize]
96 2
            )->update(['value' => $request->filesize]);
97
        }
98 2
        $request->session()->flash('success', 'Configuration Updated');
0 ignored issues
show
Bug introduced by
The method flash() does not seem to exist on object<Symfony\Component...ssion\SessionInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
99
100 2
        return response()->json(['success' => true]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
101
    }
102
103
    //  System backups index page
104
    public function backupsIndex()
105
    {
106
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
107
108
        return view('installer.backupsIndex');
109
    }
110
111
    //  Retrieve the list of backups
112
    public function getBackups()
113
    {
114
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
115
116
        $backups = Storage::disk('backup')->files();
117
        $buArray = [];
118
119
        //  Filter list to include timestamp
120
        foreach($backups as $backup)
121
        {
122
            $parts = pathinfo($backup);
123
            if($parts['extension'] === 'zip')
124
            {
125
                $buArray[] = [
126
                    'name' => $backup,
127
                    'date' => Carbon::createFromTimestamp(Storage::disk('backup')->lastModified($backup))->format('M d, Y h:m a'),
128
                ];
129
            }
130
        }
131
132
        return $buArray;
133
    }
134
135
    //  Delete a backup
136
    public function delBackup($name)
137
    {
138
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
139
140
        Storage::disk('backup')->delete($name);
141
142
        Log::notice('Backup '.$name.' deleted by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
143
        return response()->json(['success' => true]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
144
    }
145
146
    //  Download a backup
147
    public function downloadBackup($name)
148
    {
149
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
150
151
        if(Storage::disk('backup')->exists($name))
152
        {
153
            Log::info('Backup '.$name.' downloaded by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
154
            return Storage::disk('backup')->download($name);
155
        }
156
157
        Log::error('User '.Auth::user()->full_name.' tried to download a backup named '.$name.' that does not exist');
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
158
        return view('err.badFile');
159
    }
160
161
    //  Create a new backup
162 View Code Duplication
    public function runBackup()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
163
    {
164
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
165
166
        Artisan::call('tb-backup:run');
167
168
        Log::notice('Backup created by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
169
        return response()->json(['success' => true]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
170
    }
171
172
173
174
175
176
177
    //  Email Settings form
178
    public function emailSettings()
179
    {
180
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
181
182
        $settings = collect([
183
            'host'       => config('mail.host'),
184
            'port'       => config('mail.port'),
185
            'encryption' => config('mail.encryption'),
186
            'username'   => config('mail.username'),
187
            'fromEmail'  =>config('mail.from.address'),
188
            'fromName'   => config('mail.from.name'),
189
        ]);
190
191
        return view('installer.emailSettings', [
192
            'settings' => $settings,
193
        ]);
194
    }
195
196
    //  Send a test email
197
    public function sendTestEmail(Request $request)
198
    {
199
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray());
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
200
201
        //  TODO - fix this and make it work
202
        return response()->json(['success' => false]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
203
        // $request->validate([
204
        //     'host'       => 'required',
205
        //     'port'       => 'required|numeric',
206
        //     'encryption' => 'required',
207
        //     'username'   => 'required',
208
        //     'fromEmail'  => 'required',
209
        //     'fromName'   => 'required',
210
        // ]);
211
212
        // //  Update each setting
213
        // Settings::firstOrCreate(
214
        //     ['key'   => 'mail.host'],
215
        //     ['key'   => 'mail.host', 'value' => $request->host]
216
        // )->update(['value' => $request->host]);
217
        // Settings::firstOrCreate(
218
        //     ['key'   => 'mail.port'],
219
        //     ['key'   => 'mail.port', 'value' => $request->port]
220
        // )->update(['value' => $request->port]);
221
        // Settings::firstOrCreate(
222
        //     ['key'   => 'mail.encryption'],
223
        //     ['key'   => 'mail.encryption', 'value' => $request->encryption]
224
        // )->update(['value' => $request->encryption]);
225
        // Settings::firstOrCreate(
226
        //     ['key'   => 'mail.username'],
227
        //     ['key'   => 'mail.username', 'value' => $request->username]
228
        // )->update(['value' => $request->username]);
229
        // Settings::firstOrCreate(
230
        //     ['key'   => 'mail.from.address'],
231
        //     ['key'   => 'mail.from.address', 'value' => $request->fromEmail]
232
        // )->update(['value' => $request->fromEmail]);
233
        // Settings::firstOrCreate(
234
        //     ['key'   => 'mail.from.name'],
235
        //     ['key'   => 'mail.from.name', 'value' => $request->fromName]
236
        // )->update(['value' => $request->fromName]);
237
        // //  Only update the password if it has changed
238
        // if (!empty($request->password) && $request->password !== 'NULL') {
239
        //     // Settings::where('key', 'mail.password')->update(['value' => $request->password]);
240
        //     Settings::firstOrCreate(
241
        //         ['key'   => 'mail.password'],
242
        //         ['key'   => 'mail.password', 'value' => $request->password]
243
        //     )->update(['value' => $request->password]);
244
        // }
245
246
        // try
247
        // {
248
        //     Mail::to(Auth::user())->send(new TestEmail($request));
249
        // }
250
        // catch (\Exception $e)
251
        // {
252
        //     // return $e->getMessage();
253
        //     return response()->json(['success' => false, 'message' => $e->getMessage()]);
254
        // }
255
256
        // return response()->json(['success' => true, 'message' => 'Email successfully sent to '.Auth::user()->email]);
257
    }
258
259
    //  Submit the test email form
260
    public function submitEmailSettings(Request $request)
261
    {
262
        Log::debug('Route '.Route::currentRouteName().' visited by '.Auth::user()->full_name.'. Submitted Data - ', $request->toArray());
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
263
264
        $request->validate([
0 ignored issues
show
Bug introduced by
The call to validate() misses a required argument $...$params.

This check looks for function calls that miss required arguments.

Loading history...
265
            'host'       => 'required',
266
            'port'       => 'required|numeric',
267
            'encryption' => 'required',
268
            'fromEmail'  => 'required',
269
            'fromName'   => 'required',
270
        ]);
271
272
        //  Update each setting
273
        Settings::firstOrCreate(
274
            ['key'   => 'mail.host'],
275
            ['key'   => 'mail.host', 'value' => $request->host]
276
        )->update(['value' => $request->host]);
277
        Settings::firstOrCreate(
278
            ['key'   => 'mail.port'],
279
            ['key'   => 'mail.port', 'value' => $request->port]
280
        )->update(['value' => $request->port]);
281
        Settings::firstOrCreate(
282
            ['key'   => 'mail.encryption'],
283
            ['key'   => 'mail.encryption', 'value' => $request->encryption]
284
        )->update(['value' => $request->encryption]);
285
        Settings::firstOrCreate(
286
            ['key'   => 'mail.username'],
287
            ['key'   => 'mail.username', 'value' => $request->username]
288
        )->update(['value' => $request->username]);
289
        Settings::firstOrCreate(
290
            ['key'   => 'mail.from.address'],
291
            ['key'   => 'mail.from.address', 'value' => $request->fromEmail]
292
        )->update(['value' => $request->fromEmail]);
293
        Settings::firstOrCreate(
294
            ['key'   => 'mail.from.name'],
295
            ['key'   => 'mail.from.name', 'value' => $request->fromName]
296
        )->update(['value' => $request->fromName]);
297
        //  Only update the password if it has changed
298
        if(!empty($request->password) && $request->password !== 'NULL')
299
        {
300
            // Settings::where('key', 'mail.password')->update(['value' => $request->password]);
301
            Settings::firstOrCreate(
302
                ['key'   => 'mail.password'],
303
                ['key'   => 'mail.password', 'value' => $request->password]
304
            )->update(['value' => $request->password]);
305
        }
306
307
        Log::notice('Email Settings have been changed by '.Auth::user()->full_name);
0 ignored issues
show
Bug introduced by
Accessing full_name on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
308
        return response()->json(['success' => true]);
0 ignored issues
show
Bug introduced by
The method json does only exist in Illuminate\Contracts\Routing\ResponseFactory, but not in Illuminate\Http\Response.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
309
    }
310
}
311