Test Setup Failed
Push — development ( 057645...ac5058 )
by Ashutosh
15:58
created

CheckoutController::checkoutForm()   C

Complexity

Conditions 10
Paths 40

Size

Total Lines 62

Duplication

Lines 10
Ratio 16.13 %

Importance

Changes 0
Metric Value
cc 10
nc 40
nop 1
dl 10
loc 62
rs 6.9624
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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\Front;
4
5
use App\ApiKey;
6
use App\Http\Controllers\Common\MailChimpController;
7
use App\Http\Controllers\Common\TemplateController;
8
use App\Model\Common\Setting;
9
use App\Model\Common\State;
10
use App\Model\Common\Template;
11
use App\Model\Order\Invoice;
12
use App\Model\Order\InvoiceItem;
13
use App\Model\Order\Order;
14
use App\Model\Payment\Plan;
15
use App\Model\Product\Price;
16
use App\Model\Product\Product;
17
use App\Model\Product\Subscription;
18
use App\User;
19
use Bugsnag;
20
use Cart;
21
use Illuminate\Http\Request;
22
use Log;
23
24
class CheckoutController extends InfoController
25
{
26
    public $subscription;
27
    public $plan;
28
    public $templateController;
29
    public $product;
30
    public $price;
31
    public $user;
32
    public $setting;
33
    public $template;
34
    public $order;
35
    public $addon;
36
    public $invoice;
37
    public $invoiceItem;
38
    public $mailchimp;
39
40
    public function __construct()
41
    {
42
        $subscription = new Subscription();
43
        $this->subscription = $subscription;
44
45
        $plan = new Plan();
46
        $this->plan = $plan;
47
48
        $templateController = new TemplateController();
49
        $this->templateController = $templateController;
50
51
        $product = new Product();
52
        $this->product = $product;
53
54
        $price = new Price();
55
        $this->price = $price;
56
57
        $user = new User();
58
        $this->user = $user;
59
60
        $setting = new Setting();
61
        $this->setting = $setting;
62
63
        $template = new Template();
64
        $this->template = $template;
65
66
        $order = new Order();
67
        $this->order = $order;
68
69
        $invoice = new Invoice();
70
        $this->invoice = $invoice;
71
72
        $invoiceItem = new InvoiceItem();
73
        $this->invoiceItem = $invoiceItem;
74
75
        // $mailchimp = new MailChimpController();
76
        // $this->mailchimp = $mailchimp;
77
    }
78
79
    public function checkoutForm(Request $request)
80
    {
81
        $currency = 'INR';
82
        $cart_currency = 'INR';
0 ignored issues
show
Coding Style introduced by
$cart_currency does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
83
        if (!\Auth::user()) {
84
            $url = $request->segments();
85
            $content = Cart::getContent();
86
87
            \Session::put('session-url', $url[0]);
88
            $domain = $request->input('domain');
89 View Code Duplication
            if (count($domain) > 0) {
90
                foreach ($domain as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $domain of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
91
                    \Session::put('domain'.$key, $value);
92
                }
93
            }
94
            \Session::put('content', $content);
95
96
            return redirect('auth/login')->with('fails', 'Please login');
97
        }
98
99
        if (\Session::has('items')) {
100
            $content = \Session::get('items');
101
            $attributes = $this->getAttributes($content);
102
        } else {
103
            $content = Cart::getContent();
104
            $attributes = $this->getAttributes($content);
105
        }
106
107
        $require = [];
108
109
        //        if ($content->count() == 0) {
110
        //            return redirect('home');
111
        //        }
112
        if ($cart_currency != $currency) {
0 ignored issues
show
Coding Style introduced by
$cart_currency does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
113
            return redirect('checkout');
114
        }
115
        if (count($require) > 0) {
116
            $this->validate($request, [
117
                'domain.*' => 'required',
118
                    ], [
119
                'domain.*.required' => 'Please provide Domain name',
120
                //'domain.*.url'      => 'Domain name is not valid',
121
                       ]);
122
        }
123
124
        try {
125
            $domain = $request->input('domain');
126 View Code Duplication
            if (count($domain) > 0) {
127
                foreach ($domain as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $domain of type string|array is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
128
                    \Session::put('domain'.$key, $value);
129
                }
130
            }
131
            //$content = Cart::getContent();
132
            return view('themes.default1.front.checkout', compact('content', 'attributes'));
133
        } catch (\Exception $ex) {
134
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
135
            app('log')->info($ex->getMessage());
136
            Bugsnag::notifyException($ex);
137
138
            return redirect()->back()->with('fails', $ex->getMessage());
139
        }
140
    }
141
142
    public function getAttributes($content)
143
    {
144
        $attributes = [];
145
        foreach ($content as $key => $item) {
146
            $attributes[] = $item->attributes;
147
            $cart_currency = $attributes[0]['currency'][0]['code'];
0 ignored issues
show
Coding Style introduced by
$cart_currency does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
148
            $user_currency = \Auth::user()->currency;
0 ignored issues
show
Coding Style introduced by
$user_currency does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
149
            $currency = 'INR';
150
            if ($user_currency == 1 || $user_currency == 'USD') {
0 ignored issues
show
Coding Style introduced by
$user_currency does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
151
                $currency = 'USD';
152
            }
153 View Code Duplication
            if ($cart_currency != $currency) {
0 ignored issues
show
Coding Style introduced by
$cart_currency does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
154
                $id = $item->id;
155
                Cart::remove($id);
156
                $controller = new CartController();
157
                $items = $controller->addProduct($id);
158
                Cart::add($items);
159
                //
160
            }
161
162
            $require_domain = $this->product->where('id', $item->id)->first()->require_domain;
0 ignored issues
show
Coding Style introduced by
$require_domain does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
163
            $require = [];
164
            if ($require_domain == 1) {
0 ignored issues
show
Coding Style introduced by
$require_domain does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
165
                $require[$key] = $item->id;
166
            }
167
168
            return $attributes;
169
            //$attributes[] = $item->attributes;
170
        }
171
    }
172
173
    public function payNow($invoiceid)
174
    {
175
        try {
176
            $invoice = $this->invoice->find($invoiceid);
177
            // dd($invoice);
178
            $items = new \Illuminate\Support\Collection();
179
            // dd($items);
180
            if ($invoice) {
181
                $items = $invoice->invoiceItem()->get();
182
183
                $product = $this->product($invoiceid);
184
            }
185
186
            return view('themes.default1.front.paynow', compact('invoice', 'items', 'product'));
187
        } catch (\Exception $ex) {
188
            Bugsnag::notifyException($ex);
189
190
            return redirect()->back()->with('fails', $ex->getMessage());
191
        }
192
    }
193
194
    public function postCheckout(Request $request)
195
    {
196
        $invoice_controller = new \App\Http\Controllers\Order\InvoiceController();
0 ignored issues
show
Coding Style introduced by
$invoice_controller does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
197
        $info_cont = new \App\Http\Controllers\Front\InfoController();
0 ignored issues
show
Coding Style introduced by
$info_cont does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
198
        $payment_method = $request->input('payment_gateway');
0 ignored issues
show
Coding Style introduced by
$payment_method does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
199
        $paynow = false;
200
        if ($request->input('invoice_id')) {
201
            $paynow = true;
202
        }
203
        $cost = $request->input('cost');
204
        $state = $this->getState();
205
206
        try {
207
            if ($paynow === false) {
208
                /*
209
                 * Do order, invoicing etc
210
                 */
211
                $invoice = $invoice_controller->generateInvoice();
0 ignored issues
show
Coding Style introduced by
$invoice_controller does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
212
213
                $pay = $this->payment($payment_method, $status = 'pending');
0 ignored issues
show
Coding Style introduced by
$payment_method does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
214
                $payment_method = $pay['payment'];
0 ignored issues
show
Coding Style introduced by
$payment_method does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
215
                $status = $pay['status'];
216
                $invoice_no = $invoice->number;
0 ignored issues
show
Coding Style introduced by
$invoice_no does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
217
                $date = $this->getDate($invoice);
218
                $invoiceid = $invoice->id;
219
                $amount = $invoice->grand_total;
220
                $url = '';
221
                $cart = Cart::getContent();
222
                $invoices = $this->invoice->find($invoiceid);
223
                $items = new \Illuminate\Support\Collection();
224
                if ($invoices) {
225
                    $items = $invoice->invoiceItem()->get();
226
                    $product = $this->product($invoiceid);
227
                    $content = Cart::getContent();
228
                    $attributes = $this->getAttributes($content);
229
                }
230
            } else {
231
                $items = new \Illuminate\Support\Collection();
232
                $invoice_id = $request->input('invoice_id');
0 ignored issues
show
Coding Style introduced by
$invoice_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
233
                $invoice = $this->invoice->find($invoice_id);
0 ignored issues
show
Coding Style introduced by
$invoice_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
234
                $items = $invoice->invoiceItem()->get();
235
                $product = $this->product($invoice_id);
0 ignored issues
show
Coding Style introduced by
$invoice_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
236
                $amount = $invoice->grand_total;
237
                $content = Cart::getContent();
238
                $attributes = $this->getAttributes($content);
239
            }
240
            if (Cart::getSubTotal() != 0 || $cost > 0) {
241
                $rzp_key = ApiKey::where('id', 1)->value('rzp_key');
0 ignored issues
show
Coding Style introduced by
$rzp_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
242
                $rzp_secret = ApiKey::where('id', 1)->value('rzp_secret');
0 ignored issues
show
Coding Style introduced by
$rzp_secret does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
243
                $apilayer_key = ApiKey::where('id', 1)->value('apilayer_key');
0 ignored issues
show
Coding Style introduced by
$apilayer_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
244
245
                return view('themes.default1.front.postCheckout', compact('amount', 'invoice_no', ' invoiceid', ' payment_method','phone', 'invoice', 'items', 'product', 'paynow', 'attributes','rzp_key','rzp_secret',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 216 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
246
                    'apilayer_key'));
247
            } else {
248
                $action = $this->checkoutAction($invoice);
249
                $check_product_category = $this->product($invoiceid);
0 ignored issues
show
Coding Style introduced by
$check_product_category does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The variable $invoiceid does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Comprehensibility Naming introduced by
The variable name $check_product_category exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
250
                $url = '';
251
                if ($check_product_category->category) {
0 ignored issues
show
Coding Style introduced by
$check_product_category does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
252
                    $url = view('themes.default1.front.postCheckoutTemplate', compact('invoice','date',
0 ignored issues
show
Bug introduced by
The method render does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

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...
253
                        'product', 'items', 'attributes', 'state'))->render();
254
                }
255
                \Cart::clear();
256
257
                return redirect()->back()->with('success', $url);
258
            }
259
        } catch (\Exception $ex) {
260
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
261
            app('log')->info($ex->getMessage());
262
            Bugsnag::notifyException($ex);
263
264
            return redirect()->back()->with('fails', $ex->getMessage());
265
        }
266
    }
267
268
    public function checkoutAction($invoice)
269
    {
270
        try {
271
            //get elements from invoice
272
            $invoice_number = $invoice->number;
0 ignored issues
show
Coding Style introduced by
$invoice_number does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
273
            $invoice_id = $invoice->id;
0 ignored issues
show
Coding Style introduced by
$invoice_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
274
            $invoice->status = 'success';
275
            $invoice->save();
276
            //dd($invoice->id);
277
278
            $invoice_items = $this->invoiceItem->where('invoice_id', $invoice->id)->first();
0 ignored issues
show
Coding Style introduced by
$invoice_items does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
279
            $product = $invoice_items->product_name;
0 ignored issues
show
Coding Style introduced by
$invoice_items does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
280
281
            $user_id = \Auth::user()->id;
0 ignored issues
show
Coding Style introduced by
$user_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
282
283
            $url = '';
284
            $check_product_category = $this->product($invoice_id);
0 ignored issues
show
Coding Style introduced by
$check_product_category does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Comprehensibility Naming introduced by
The variable name $check_product_category exceeds the maximum configured length of 20.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
285
            if ($check_product_category->category) {
0 ignored issues
show
Coding Style introduced by
$check_product_category does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
286
                $url = url("download/$user_id/$invoice_number");
0 ignored issues
show
Coding Style introduced by
$user_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
287
                //execute the order
288
                $order = new \App\Http\Controllers\Order\OrderController();
289
                $order->executeOrder($invoice->id, $order_status = 'executed');
0 ignored issues
show
Coding Style introduced by
$order_status does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
290
                $payment = new \App\Http\Controllers\Order\InvoiceController();
291
                $payment->postRazorpayPayment($invoice_id, $invoice->grand_total);
0 ignored issues
show
Coding Style introduced by
$invoice_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
292
            }
293
294
            return 'success';
295
        } catch (\Exception $ex) {
296
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
297
            app('log')->info($ex->getMessage());
298
            Bugsnag::notifyException($ex);
299
300
            return redirect()->back()->with('fails', $ex->getMessage());
301
        }
302
    }
303
304
    public function product($invoiceid)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
305
    {
306
        try {
307
            $invoice = $this->invoiceItem->where('invoice_id', $invoiceid)->first();
308
            // dd($invoice);
309
            $name = $invoice->product_name;
310
            $product = $this->product->where('name', $name)->first();
311
312
            return $product;
313
        } catch (\Exception $ex) {
314
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
315
            app('log')->info($ex->getMessage());
316
            Bugsnag::notifyException($ex);
317
318
            throw new \Exception($ex->getMessage());
319
        }
320
    }
321
322
    public function GenerateOrder()
1 ignored issue
show
Coding Style introduced by
function GenerateOrder() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
323
    {
324
        try {
325
            $products = [];
326
            $items = \Cart::getContent();
327
            foreach ($items as $item) {
328
329
               //this is product
330
                $id = $item->id;
331
                $this->AddProductToOrder($id);
332
            }
333
        } catch (\Exception $ex) {
334
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
335
            app('log')->info($ex->getMessage());
336
            Bugsnag::notifyException($ex);
337
338
            throw new \Exception('Can not Generate Order');
339
        }
340
    }
341
342
    public function AddProductToOrder($id)
1 ignored issue
show
Coding Style introduced by
function AddProductToOrder() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
343
    {
344
        try {
345
            $cart = \Cart::get($id);
346
            $client = \Auth::user()->id;
347
            $payment_method = \Input::get('payment_gateway');
0 ignored issues
show
Coding Style introduced by
$payment_method does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
348
            $promotion_code = '';
0 ignored issues
show
Coding Style introduced by
$promotion_code does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
349
            $order_status = 'pending';
0 ignored issues
show
Coding Style introduced by
$order_status does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
350
            $serial_key = '';
0 ignored issues
show
Coding Style introduced by
$serial_key does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
351
            $product = $id;
352
            $addon = '';
353
            $domain = '';
354
            $price_override = $cart->getPriceSumWithConditions();
0 ignored issues
show
Coding Style introduced by
$price_override does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
355
            $qty = $cart->quantity;
356
357
            $planid = $this->price->where('product_id', $id)->first()->subscription;
358
359
            $or = $this->order->create(['client' => $client, 'payment_method' => $payment_method, 'promotion_code' => $promotion_code, 'order_status' => $order_status, 'serial_key' => $serial_key, 'product' => $product, 'addon' => $addon, 'domain' => $domain, 'price_override' => $price_override, 'qty' => $qty]);
0 ignored issues
show
Coding Style introduced by
$payment_method does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The method create() does not exist on App\Model\Order\Order. Did you maybe mean getCreatedAtAttribute()?

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...
Comprehensibility introduced by
Avoid variables with short names like $or. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 313 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
360
361
            $this->AddSubscription($or->id, $planid);
362
        } catch (\Exception $ex) {
363
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
364
            app('log')->info($ex->getMessage());
365
            Bugsnag::notifyException($ex);
366
367
            throw new \Exception('Can not Generate Order for Product');
368
        }
369
    }
370
371
    public function AddSubscription($orderid, $planid)
1 ignored issue
show
Coding Style introduced by
function AddSubscription() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
372
    {
373
        try {
374
            $days = $this->plan->where('id', $planid)->first()->days;
375
            //dd($days);
376 View Code Duplication
            if ($days > 0) {
377
                $dt = \Carbon\Carbon::now();
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $dt. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
378
                //dd($dt);
379
                $user_id = \Auth::user()->id;
0 ignored issues
show
Coding Style introduced by
$user_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
380
                $ends_at = $dt->addDays($days);
0 ignored issues
show
Coding Style introduced by
$ends_at does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
381
            } else {
382
                $ends_at = '';
0 ignored issues
show
Coding Style introduced by
$ends_at does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
383
            }
384
            $this->subscription->create(['user_id' => \Auth::user()->id, 'plan_id' => $planid, 'order_id' => $orderid, 'ends_at' => $ends_at]);
0 ignored issues
show
Coding Style introduced by
$ends_at does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The method create() does not exist on App\Model\Product\Subscription. Did you maybe mean created()?

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...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 143 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
385
        } catch (\Exception $ex) {
386
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
387
            app('log')->info($ex->getMessage());
388
            Bugsnag::notifyException($ex);
389
390
            throw new \Exception('Can not Generate Subscription');
391
        }
392
    }
393
394
    public function GenerateInvoice()
1 ignored issue
show
Coding Style introduced by
function GenerateInvoice() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
395
    {
396
        try {
397
            $user_id = \Auth::user()->id;
0 ignored issues
show
Coding Style introduced by
$user_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
398
            $number = rand(11111111, 99999999);
399
            $date = \Carbon\Carbon::now();
400
            $grand_total = \Cart::getSubTotal();
0 ignored issues
show
Coding Style introduced by
$grand_total does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
401
402
            $invoice = $this->invoice->create(['user_id' => $user_id, 'number' => $number, 'date' => $date, 'grand_total' => $grand_total]);
0 ignored issues
show
Coding Style introduced by
$user_id does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The method create() does not exist on App\Model\Order\Invoice. Did you maybe mean getCreatedAtAttribute()?

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...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 140 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
403
            foreach (\Cart::getContent() as $cart) {
404
                $this->CreateInvoiceItems($invoice->id, $cart);
405
            }
406
        } catch (\Exception $ex) {
407
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
408
            app('log')->info($ex->getMessage());
409
            Bugsnag::notifyException($ex);
410
411
            throw new \Exception('Can not Generate Invoice');
412
        }
413
    }
414
415
    public function CreateInvoiceItems($invoiceid, $cart)
1 ignored issue
show
Coding Style introduced by
function CreateInvoiceItems() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
416
    {
417
        try {
418
            $product_name = $cart->name;
0 ignored issues
show
Coding Style introduced by
$product_name does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
419
            $regular_price = $cart->price;
0 ignored issues
show
Coding Style introduced by
$regular_price does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
420
            $quantity = $cart->quantity;
421
            $subtotal = $cart->getPriceSumWithConditions();
422
423
            $tax_name = '';
0 ignored issues
show
Coding Style introduced by
$tax_name does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
424
            $tax_percentage = '';
0 ignored issues
show
Coding Style introduced by
$tax_percentage does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
425
426 View Code Duplication
            foreach ($cart->attributes['tax'] as $tax) {
427
                //dd($tax['name']);
428
                $tax_name .= $tax['name'].',';
0 ignored issues
show
Coding Style introduced by
$tax_name does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
429
                $tax_percentage .= $tax['rate'].',';
0 ignored issues
show
Coding Style introduced by
$tax_percentage does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
430
            }
431
432
            //dd($tax_name);
433
434
            $invoiceItem = $this->invoiceItem->create(['invoice_id' => $invoiceid, 'product_name' => $product_name, 'regular_price' => $regular_price, 'quantity' => $quantity, 'tax_name' => $tax_name, 'tax_percentage' => $tax_percentage, 'subtotal' => $subtotal]);
0 ignored issues
show
Coding Style introduced by
$product_name does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Bug introduced by
The method create() does not exist on App\Model\Order\InvoiceItem. Did you maybe mean created()?

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...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 264 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
435
        } catch (\Exception $ex) {
436
            app('log')->useDailyFiles(storage_path().'/logs/laravel.log');
437
            app('log')->info($ex->getMessage());
438
            Bugsnag::notifyException($ex);
439
440
            throw new \Exception('Can not create Invoice Items');
441
        }
442
    }
443
}
444