NewsletterController::subscribe()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 18
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
c 0
b 0
f 0
nc 3
nop 1
dl 18
loc 18
rs 9.4285
1
<?php
2
3
namespace App\Http\Controllers\Front\Api;
4
5
use Newsletter;
6
use App\Http\Requests\Front\Api\NewsletterSubscriptionRequest;
7
8 View Code Duplication
class NewsletterController extends Controller
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    /**
11
     * @param \App\Http\Requests\Front\NewsletterSubscriptionRequest $request
12
     *
13
     * @return \Illuminate\Http\JsonResponse
14
     */
15
    public function subscribe(NewsletterSubscriptionRequest $request)
16
    {
17
        $email = strtolower($request->get('email'));
18
19
        if (Newsletter::hasMember($email)) {
20
            return $this->respond(['message' => fragment('newsletter.subscription.result.alreadySubscribed'), 'type' => 'info']);
21
        }
22
23
        $result = Newsletter::subscribe($email);
24
25
        if (! $result) {
26
            return $this->respondWithBadRequest(['message' => fragment('newsletter.subscription.result.error'), 'type' => 'error']);
0 ignored issues
show
Documentation introduced by
array('message' => fragm...r'), 'type' => 'error') is of type array<string,string,{"me...ring","type":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
27
        }
28
29
        activity()->log("{$email} schreef zich in op de nieuwsbrief");
30
31
        return $this->respond(['message' => fragment('newsletter.subscription.result.ok'), 'type' => 'success']);
32
    }
33
}
34