Completed
Push — master ( 42d8fc...e36597 )
by PROSPER
03:36
created

ClockworkController::sendTextMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
7
use App\Http\Requests;
8
use App\Http\Controllers\Controller;
9
use MJErwin\Clockwork\ClockworkClient;
10
use MJErwin\Clockwork\Message;
11
12
class ClockworkController extends Controller
13
{
14
15
    protected $apiKey;
16
    protected $client;
17
18
    public function __construct()
19
    {
20
        $this->apiKey = env('CLOCKWORK_API_KEY');
21
        $this->client = new ClockworkClient($this->apiKey);
22
        $this->message = new Message();
0 ignored issues
show
Bug introduced by
The property message does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
        $this->message->setNumber('07700900123');
24
        $this->message->setContent('Check out this message!');
25
26
    }
27
    /**
28
     * Return all data to the Clockwork API dashboard
29
     * @return mixed
30
     */
31
    public function getPage()
32
    {
33
        return view('api.clockwork');
34
    }
35
36
    /**
37
     * Send a Text Message
38
     * @param  Request $request
39
     * @return string
40
     */
41
    public function sendTextMessage(Request $request)
42
    {
43
        $this->validate($request, [
44
            'telephone'  => 'required'
45
        ]);
46
47
        $number = $request->input('number');
0 ignored issues
show
Unused Code introduced by
$number is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
48
        $message = 'Testing Clockwork SMS #LaravelHackathonStarter';
0 ignored issues
show
Unused Code introduced by
$message is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
49
50
        $response = $this->client->sendMessage($this->message);
51
        dd($response);
52
53
        //return redirect()->back()->with('info','Your Message has been sent successfully');
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
54
    }
55
}
56