SubscribeController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace App\Http\Controllers;
3
4
use App\Repositories\SubscribeRepository;
5
use App\Http\Requests\SubscribeRequest;
6
use App\Subscribe;
7
use Illuminate\Http\Request;
8
use Illuminate\Mail\Message;
9
10
class SubscribeController extends Controller
11
{
12
    protected $subscribe;
13
14
    public function __construct(SubscribeRepository $subscribeRepository)
15
    {
16
        $this->subscribe = $subscribeRepository;
17
    }
18
19
    public function index(SubscribeRequest $request)
20
    {
21
        if (!$this->subscribe->checkSubscriber($request['email']))
22
        {
23
            $subscribe = $this->subscribe->sendSubscribe($request->all());
24
25
            $this->sendEmail($subscribe);
26
        } else {
27
            $subscribe = $this->subscribe->getByEmail($request['email']);
28
29
            if (!$subscribe->active) {
0 ignored issues
show
Documentation introduced by
The property active does not exist on object<App\Subscribe>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
30
                $subscribe->fill([
31
                    'active' => (int)true,
32
                ])->save();
33
34
                $this->sendEmail($subscribe);
35
            } else {
36
                return redirect()->back()->withStatus('You already subscribed.');
0 ignored issues
show
Bug introduced by
The method withStatus() does not exist on Illuminate\Http\RedirectResponse. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37
            }
38
        }
39
40
        return back()->withStatus('You are subscribed to Amma!');
0 ignored issues
show
Bug introduced by
The method withStatus() does not exist on Illuminate\Http\RedirectResponse. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
41
    }
42
43
    /**
44
     * Send email.
45
     *
46
     * @param \App\Subscribe $subscribe
47
     * @return void
48
     */
49
    private function sendEmail(Subscribe $subscribe)
50
    {
51
        \Mail::send('email.subscribe', compact('subscribe'), function (Message $message) use ($subscribe) {
52
            $message->to($subscribe->email, sprintf('%s %s', $subscribe->email, $subscribe->token))
0 ignored issues
show
Documentation introduced by
The property email does not exist on object<App\Subscribe>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property token does not exist on object<App\Subscribe>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
53
                ->subject("Amma subscribed message!");
54
        });
55
    }
56
57
    public function unscribe(Request $request, $token)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        $this->subscribe->unscribe($token);
60
61
        return redirect()->route('home')->withStatus('You have unsubscribed!');
0 ignored issues
show
Bug introduced by
The method withStatus() does not exist on Illuminate\Http\RedirectResponse. Did you maybe mean status()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
62
    }
63
64
}