Completed
Branch master (bb48cc)
by vijay
148:50 queued 92:39
created

ProductController::GetProducts()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 50
Code Lines 31

Duplication

Lines 22
Ratio 44 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 22
loc 50
rs 8.6315
cc 5
eloc 31
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Product;
4
5
use App\Http\Controllers\Controller;
6
use App\Http\Requests\Product\ProductRequest;
7
use App\Model\Payment\Currency;
8
use App\Model\Payment\Plan;
9
use App\Model\Product\Addon;
10
use App\Model\Product\Price;
11
use App\Model\Product\Product;
12
use App\Model\Product\ProductGroup;
13
use App\Model\Product\Subscription;
14
use App\Model\Product\Type;
15
use Illuminate\Http\Request;
16
17
class ProductController extends Controller {
18
19
    public $product;
20
    public $addon;
21
    public $price;
22
    public $type;
23
    public $subscription;
24
    public $currency;
25
    public $group;
26
    public $plan;
27
28
    public function __construct() {
29
        $this->middleware('auth');
30
        $this->middleware('admin',['except' => ['userDownload']]);
31
32
        $product = new Product();
33
        $this->product = $product;
34
35
        $addon = new Addon();
36
        $this->addon = $addon;
37
38
        $price = new Price();
39
        $this->price = $price;
40
41
        $type = new Type();
42
        $this->type = $type;
43
44
        $subscription = new Subscription();
45
        $this->subscription = $subscription;
46
47
        $currency = new Currency();
48
        $this->currency = $currency;
49
50
        $group = new ProductGroup();
51
        $this->group = $group;
52
53
        $plan = new Plan();
54
        $this->plan = $plan;
55
    }
56
57
    /**
58
     * Display a listing of the resource.
59
     *
60
     * @return Response
61
     */
62
    public function index() {
63
        try {
64
            return view('themes.default1.product.product.index');
65
        } catch (\Exception $e) {
66
            return redirect('/')->with('fails', $e->getMessage());
67
        }
68
    }
69
70
    public function GetProducts() {
71
72
        // try {
73
        return \Datatable::collection($this->product->select('id', 'name', 'type', 'group')->where('id', '!=', 1)->get())
74
                        ->addColumn('#', function ($model) {
75
                            return "<input type='checkbox' value=" . $model->id . ' name=select[] id=check>';
76
                        })
77
                        ->addColumn('name', function ($model) {
78
                            return ucfirst($model->name);
79
                        })
80 View Code Duplication
                        ->addColumn('type', function ($model) {
81
                            //dd($model->type());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
82
                            if ($this->type->where('id', $model->type)->first()) {
83
                                return $this->type->where('id', $model->type)->first()->name;
84
                            } else {
85
                                return 'Not available';
86
                            }
87
                        })
88
                        ->addColumn('group', function ($model) {
89
                            //dd($model->type());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% 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...
90
                            if ($this->group->where('id', $model->group)->first()) {
91
                                return $this->group->where('id', $model->group)->first()->name;
92
                            } else {
93
                                return 'Not available';
94
                            }
95
                        })
96 View Code Duplication
                        ->addColumn('price', function ($model) {
97
                            if ($this->price->where('product_id', $model->id)->first()) {
98
                                return $this->price->where('product_id', $model->id)->first()->price;
99
                            } else {
100
                                return 'Not available';
101
                            }
102
                        })
103 View Code Duplication
                        ->addColumn('currency', function ($model) {
104
                            if ($this->price->where('product_id', $model->id)->first()) {
105
                                return $this->price->where('product_id', $model->id)->first()->currency;
106
                            } else {
107
                                return 'Not available';
108
                            }
109
                        })
110
                        ->addColumn('action', function ($model) {
111
                            return '<a href=' . url('products/' . $model->id . '/edit') . " class='btn btn-sm btn-primary'>Edit</a>";
112
                        })
113
                        ->searchColumns('name', 'email')
114
                        ->orderColumns('name', 'email')
115
                        ->make();
116
//        } catch (\Exception $e) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
117
//            return redirect()->back()->with('fails', $e->getMessage());
118
//        }
119
    }
120
121
    /**
122
     * Show the form for creating a new resource.
123
     *
124
     * @return Response
125
     */
126
    public function create() {
127
        try {
128
            /*
129
             * server url
130
             */
131
132
            $url = $this->GetMyUrl();
133
            $i = $this->product->orderBy('created_at', 'desc')->first()->id + 1;
134
            $cartUrl = $url . '/pricing?id=' . $i;
135
            $addon = $this->addon;
136
            $type = $this->type->lists('name', 'id')->toArray();
137
            $subscription = $this->plan->lists('name', 'id')->toArray();
138
            $currency = $this->currency->lists('name', 'code')->toArray();
139
            $group = $this->group->lists('name', 'id')->toArray();
140
            $products = $this->product->lists('name', 'id')->toArray();
141
142
            return view('themes.default1.product.product.create', compact('subscription', 'addon', 'type', 'currency', 'group', 'cartUrl', 'products'));
143
        } catch (\Exception $e) {
144
            return redirect()->back()->with('fails', $e->getMessage());
145
        }
146
    }
147
148
    /**
149
     * Store a newly created resource in storage.
150
     *
151
     * @return Response
152
     */
153
    public function store(Request $request) {
154
        $input = $request->all();
155
        $v = \Validator::make($input, [
156
                    'name' => 'required',
157
                    'type' => 'required',
158
                    'group' => 'required',
159
                    'subscription' => 'required',
160
                    'currency.*' => 'required',
161
                    'price.*' => 'required',
162
        ]);
163 View Code Duplication
        $v->sometimes(['file', 'image'], 'required', function($input) {
164
            return ($input->type == 2 && $input->github_owner == '' && $input->github_repository == '' );
165
        });
166
167 View Code Duplication
        $v->sometimes(['github_owner', 'github_repository'], 'required', function($input) {
168
            return ($input->type == 2 && $input->file == '' && $input->image == '' );
169
        });
170
        if ($v->fails()) {
171
            return redirect()->back()->with('errors', $v->errors());
172
            //dd();
173
        }
174
        try {
175 View Code Duplication
            if ($request->hasFile('image')) {
176
                $image = $request->file('image')->getClientOriginalName();
177
                $imagedestinationPath = 'dist/product/images';
178
                $request->file('image')->move($imagedestinationPath, $image);
179
                $this->product->image = $image;
0 ignored issues
show
Documentation introduced by
The property image does not exist on object<App\Model\Product\Product>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
180
            }
181 View Code Duplication
            if ($request->hasFile('file')) {
182
                $file = $request->file('file')->getClientOriginalName();
183
                $filedestinationPath = storage_path() . '/products';
184
                $request->file('file')->move($filedestinationPath, $file);
185
                $this->product->file = $file;
0 ignored issues
show
Documentation introduced by
The property file does not exist on object<App\Model\Product\Product>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
186
            }
187
188
            //dd($request->input('currency'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
189
190
            $product = $this->product;
191
            $product->fill($request->except('image', 'file'))->save();
192
193
            $product_id = $product->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<App\Model\Product\Product>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
194
            $subscription = $request->input('subscription');
195
            $price = $request->input('price');
196
            $sales_price = $request->input('sales_price');
197
            $currencies = $request->input('currency');
198
199 View Code Duplication
            foreach ($currencies as $key => $currency) {
0 ignored issues
show
Bug introduced by
The expression $currencies 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...
200
                $this->price->create(['product_id' => $product_id, 'currency' => $currency, 'subscription' => $subscription, 'price' => $price[$key], 'sales_price' => $sales_price[$key]]);
201
            }
202
203
            return redirect()->back()->with('success', \Lang::get('message.saved-successfully'));
204
        } catch (\Exception $e) {
205
            return redirect()->back()->with('fails', $e->getMessage());
206
        }
207
    }
208
209
    /**
210
     * Display the specified resource.
211
     *
212
     * @param int $id
213
     *
214
     * @return Response
215
     */
216
    public function show($id) {
217
        //
218
    }
219
220
    /**
221
     * Show the form for editing the specified resource.
222
     *
223
     * @param int $id
224
     *
225
     * @return Response
226
     */
227
    public function edit($id) {
228
        try {
229
            $addon = $this->addon;
230
            $type = $this->type->lists('name', 'id')->toArray();
231
            $subscription = $this->plan->lists('name', 'id')->toArray();
232
            $currency = $this->currency->lists('name', 'code')->toArray();
233
            $group = $this->group->lists('name', 'id')->toArray();
234
            $products = $this->product->lists('name', 'id')->toArray();
235
            $url = $this->GetMyUrl();
236
            $cartUrl = $url . '/cart?id=' . $id;
237
            $product = $this->product->where('id', $id)->first();
238
            $price = $this->price->where('product_id', $product->id);
239
            foreach ($currency as $key => $value) {
240
                if ($this->price->where('product_id', $product->id)->where('currency', $key)->first()) {
241
                    $regular[$key] = $this->price->where('product_id', $product->id)->where('currency', $key)->first()->price;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$regular was never initialized. Although not strictly required by PHP, it is generally a good practice to add $regular = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
242
                    $sales[$key] = $this->price->where('product_id', $product->id)->where('currency', $key)->first()->sales_price;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$sales was never initialized. Although not strictly required by PHP, it is generally a good practice to add $sales = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
243
                } else {
244
                    $regular[$key] = '';
0 ignored issues
show
Bug introduced by
The variable $regular 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...
245
                    $sales[$key] = '';
0 ignored issues
show
Bug introduced by
The variable $sales 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...
246
                }
247
            }
248
            //dd($regular);
249
250
            return view('themes.default1.product.product.edit', compact('product', 'addon', 'type', 'subscription', 'currency', 'group', 'price', 'cartUrl', 'products', 'regular', 'sales'));
251
        } catch (\Exception $e) {
252
            return redirect()->back()->with('fails', $e->getMessage());
253
        }
254
    }
255
256
    /**
257
     * Update the specified resource in storage.
258
     *
259
     * @param int $id
260
     *
261
     * @return Response
262
     */
263
    public function update($id, Request $request) {
264
        $input = $request->all();
265
        //dd($input);
266
        $v = \Validator::make($input, [
267
                    'name' => 'required',
268
                    'type' => 'required',
269
                    'group' => 'required',
270
                    'subscription' => 'required',
271
                    'currency.*' => 'required',
272
                    'price.*' => 'required',
273
        ]);
274 View Code Duplication
        $v->sometimes(['file', 'image'], 'required', function($input) {
275
            return ($input->type == 2 && $input->github_owner == '' && $input->github_repository == '' );
276
        });
277
278 View Code Duplication
        $v->sometimes(['github_owner', 'github_repository'], 'required', function($input) {
279
            return ($input->type == 2 && $input->file == '' && $input->image == '' );
280
        });
281
        if ($v->fails()) {
282
            return redirect()->back()->with('errors', $v->errors());
283
            //dd();
284
        }
285
        try {
286
            $product = $this->product->where('id', $id)->first();
287 View Code Duplication
            if ($request->hasFile('image')) {
288
                $image = $request->file('image')->getClientOriginalName();
289
                $imagedestinationPath = 'dist/product/images';
290
                $request->file('image')->move($imagedestinationPath, $image);
291
                $product->image = $image;
292
            }
293 View Code Duplication
            if ($request->hasFile('file')) {
294
                $file = $request->file('file')->getClientOriginalName();
295
                $filedestinationPath = storage_path() . '/products';
296
                $request->file('file')->move($filedestinationPath, $file);
297
                $product->file = $file;
298
            }
299
300
            $product->fill($request->except('image', 'file'))->save();
301
302
            $product_id = $product->id;
303
            $subscription = $request->input('subscription');
304
            $cost = $request->input('price');
305
            $sales_price = $request->input('sales_price');
306
            $currencies = $request->input('currency');
307
308
            $prices = $this->price->where('product_id', $product->id)->get();
309
            foreach ($prices as $price) {
310
                $price->delete();
311
            }
312
313 View Code Duplication
            foreach ($currencies as $key => $currency) {
0 ignored issues
show
Bug introduced by
The expression $currencies 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...
314
                $this->price->create(['product_id' => $product_id, 'currency' => $currency, 'subscription' => $subscription, 'price' => $cost[$key], 'sales_price' => $sales_price[$key]]);
315
            }
316
317
            return redirect()->back()->with('success', \Lang::get('message.updated-successfully'));
318
        } catch (\Exception $e) {
319
            return redirect()->back()->with('fails', $e->getMessage());
320
        }
321
    }
322
323
    /**
324
     * Remove the specified resource from storage.
325
     *
326
     * @param int $id
0 ignored issues
show
Bug introduced by
There is no parameter named $id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
327
     *
328
     * @return Response
329
     */
330 View Code Duplication
    public function destroy(Request $request) {
331
        try {
332
            $ids = $request->input('select');
333
            if (!empty($ids)) {
334
                foreach ($ids as $id) {
0 ignored issues
show
Bug introduced by
The expression $ids 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...
335
                    if ($id != 1) {
336
                        $product = $this->product->where('id', $id)->first();
337
                        if ($product) {
338
                            $product->delete();
339
                        } else {
340
                            echo "<div class='alert alert-danger alert-dismissable'>
341
                    <i class='fa fa-ban'></i>
342
                    <b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . '
343
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
344
                        ' . \Lang::get('message.no-record') . '
345
                </div>';
346
                            //echo \Lang::get('message.no-record') . '  [id=>' . $id . ']';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
347
                        }
348
                        echo "<div class='alert alert-success alert-dismissable'>
349
                    <i class='fa fa-ban'></i>
350
                    <b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.success') . '
351
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
352
                        ' . \Lang::get('message.deleted-successfully') . '
353
                </div>';
354
                    } else {
355
                        echo "<div class='alert alert-danger alert-dismissable'>
356
                    <i class='fa fa-ban'></i>
357
                    <b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . '
358
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
359
                        ' . \Lang::get('message.can-not-delete-default') . '
360
                </div>';
361
                    }
362
                }
363
            } else {
364
                echo "<div class='alert alert-danger alert-dismissable'>
365
                    <i class='fa fa-ban'></i>
366
                    <b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . '
367
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
368
                        ' . \Lang::get('message.select-a-row') . '
369
                </div>';
370
                //echo \Lang::get('message.select-a-row');
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
371
            }
372
        } catch (\Exception $e) {
373
            echo "<div class='alert alert-danger alert-dismissable'>
374
                    <i class='fa fa-ban'></i>
375
                    <b>" . \Lang::get('message.alert') . '!</b> ' . \Lang::get('message.failed') . '
376
                    <button type=button class=close data-dismiss=alert aria-hidden=true>&times;</button>
377
                        ' . $e->getMessage() . '
378
                </div>';
379
        }
380
    }
381
382
    public function GetMyUrl() {
383
        $server = new Request();
0 ignored issues
show
Unused Code introduced by
$server 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...
384
        $url = $_SERVER['REQUEST_URI'];
385
        $server = parse_url($url);
386
        $server['path'] = dirname($server['path']);
387
        $server = parse_url($server['path']);
388
        $server['path'] = dirname($server['path']);
389
390
        $server = 'http://' . $_SERVER['HTTP_HOST'] . $server['path'];
391
392
        return $server;
393
    }
394
    
395
    public function downloadProduct($id){
396
        try{
397
            $product = $this->product->findOrFail($id);
398
            //dd($product);
399
            $type = $product->type;
400
            $owner = $product->github_owner;
401
            $repository = $product->github_repository;
402
            $file = $product->file;
403
            if($type==2){
404
                if($owner&&$repository){
405
                    //dd($repository);
406
                    $github_controller = new \App\Http\Controllers\Github\GithubController();
407
                    return $github_controller->getReleaseByTag($owner, $repository);
408
                }elseif($file){
409
                    $file = storage_path() . '/products/' . $file;
410
                    return \Response::download($file);
411
                }
412
            }
413
        } catch (\Exception $e) {
414
            return redirect()->back()->with('fails', $e->getMessage());
415
        }
416
    }
417
    
418
    public function userDownload($userid,$invoice_number){
419
        try{
420
            $user = new \App\User();
421
            $user = $user->findOrFail($userid);
422
            $invoice = new \App\Model\Order\Invoice();
423
            $invoice = $invoice->where('number',$invoice_number)->first();
424
            if($user&&$invoice){
425
                if($user->active==1){
426
                    $invoice_item = new \App\Model\Order\InvoiceItem();
427
                    $item = $invoice_item->where('invoice_id',$invoice->id)->first();
428
                    $product_id= $this->product->where('name',$item->product_name)->first()->id;
429
                    $this->downloadProduct($product_id);
430
                }else{
431
                    return redirect('auth/login')->with('fails',\Lang::get('activate-your-account'));
432
                }
433
            }else{
434
                return redirect('auth/login')->with('fails',\Lang::get('please-purcahse-a-product'));
435
            }
436
        } catch (Exception $ex) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
Bug introduced by
The class App\Http\Controllers\Product\Exception does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
437
438
        }
439
    }
440
441
}
442