GetPlans   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 4
Bugs 1 Features 0
Metric Value
eloc 31
c 4
b 1
f 0
dl 0
loc 70
rs 10
wmc 11

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 63 11
1
<?php
2
3
namespace App\Http\Controllers\Stripe;
4
5
use App\Http\Controllers\Controller;
6
use Illuminate\Http\Request;
7
use LaravelEnso\Roles\Models\Role;
8
use Stripe;
9
10
class GetPlans extends Controller
11
{
12
    /**
13
     * Handle the incoming request.
14
     *
15
     * @return \Illuminate\Http\Response
16
     */
17
    public function __invoke(Request $request)
18
    {
19
//        $role = Role::where("name", "free")->first();
20
        Stripe\Stripe::setApiKey(\Config::get('services.stripe.secret'));
21
22
        $plans = Stripe\Plan::all();
23
24
        $result = [];
25
        foreach ($plans as $plan) {
26
            if (! $plan->active || $plan->amount == 0) {
27
                continue;
28
            }
29
30
            /*
31
             * FREE PLAN
32
             */
33
34
            /**
35
             * if ($k === 0) {
36
             * $row1 = [];
37
             * $row1["id"] = $role->id;
38
             * $row1["amount"] = 0;
39
             * $row1["nickname"] = $role->name;
40
             * $row1["title"] = $role->display_name;
41
             * $row1["subscribed"] = false;
42
             * $result[] = $row1;
43
             * }.
44
             **/
45
            if (empty($plan->nickname)) {
46
                continue;
47
            }
48
            $row = [];
49
50
            $row['id'] = $plan->id;
51
            $row['amount'] = $plan->amount;
52
            $row['title'] = $plan->nickname;
53
            $row['nickname'] = $plan->title;
54
            $row['interval'] = $plan->interval;
55
            $row['trial_end'] = null;
56
57
            $row['features'] = [];
58
            $row['features_missing'] = [];
59
            $row['metadata'] = [
60
                'featured' => false,
61
                'description' => 'Missing description!!!',
62
            ];
63
64
            foreach ($plan->metadata->toArray() as $key => $value) {
65
                if (preg_match('/^feature-missing\d*$/', (string) $key)) {
66
                    $row['features_missing'][] = $value;
67
                }
68
                if (preg_match('/^feature\d*$/', (string) $key)) {
69
                    $row['features'][] = $value;
70
                }
71
                if ($key == 'featured' && ($value == 1 || $value == 'true')) {
72
                    $row['metadata']['featured'] = true;
73
                }
74
            }
75
            $row['subscribed'] = false;
76
            $result[] = $row;
77
        }
78
79
        return $result;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $result returns the type array|array<mixed,array> which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
80
    }
81
}
82