Completed
Push — master ( e04365...86cad5 )
by vijay
09:15 queued 05:39
created

ServiceProviderController::AddtoCart()   A

Complexity

Conditions 2
Paths 5

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 22
rs 9.2
cc 2
eloc 13
nc 5
nop 2
1
<?php
2
3
namespace App\Http\Controllers\ServiceProvider;
4
5
use App\Http\Controllers\Controller;
6
use App\Model\licence\Licence;
7
use App\Model\Licence\LicencedOrganization;
8
use App\Model\licence\Sla;
9
use App\Model\licence\SlaServiceRelation;
10
use App\Model\Product\Service;
11
use App\Organization;
12
use Illuminate\Http\Request;
13
14
class ServiceProviderController extends Controller
15
{
16
    public $slaServiceRelation;
17
    public $service;
18
    public $licence;
19
20
    public function __construct()
21
    {
22
        $this->middleware('auth');
23
        $this->middleware('service.provider');
24
25
        $cart = new \App\Http\Controllers\Front\CheckoutController();
26
        $auth = $cart->GetXdeskAuthOrganization();
0 ignored issues
show
Documentation Bug introduced by
The method GetXdeskAuthOrganization does not exist on object<App\Http\Controll...ont\CheckoutController>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
27
        $this->org = $auth;
0 ignored issues
show
Bug introduced by
The property org does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28
29
        $sla = new Sla();
30
        $this->sla = $sla;
0 ignored issues
show
Bug introduced by
The property sla does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
32
        $LicencedOrg = new LicencedOrganization();
33
        $this->LicencedOrg = $LicencedOrg;
0 ignored issues
show
Bug introduced by
The property LicencedOrg does not seem to exist. Did you mean licence?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
34
35
        $slaServiceRelation = new SlaServiceRelation();
36
        $this->slaServiceRelation = $slaServiceRelation;
37
38
        $service = new Service();
39
        $this->service = $service;
40
41
        $organization = new Organization();
42
        $this->organization = $organization;
0 ignored issues
show
Bug introduced by
The property organization does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
43
44
        $licence = new Licence();
45
        $this->licence = $licence;
46
    }
47
48
    public function Orders()
49
    {
50
        try {
51
            return view('themes.default1.serviceprovider.orders');
52
        } catch (\Exception $ex) {
53
            return redirect()->back()->with('fails', $ex->getMessage());
54
        }
55
    }
56
57
    public function Sla()
58
    {
59
        try {
60
            return view('themes.default1.serviceprovider.sla');
61
        } catch (\Exception $ex) {
62
            return redirect()->back()->with('fails', $ex->getMessage());
63
        }
64
    }
65
66
    public function Pricing()
67
    {
68
        try {
69
            $licence = new \App\Model\licence\Licence();
70
            $licences = $licence->get();
0 ignored issues
show
Documentation Bug introduced by
The method get does not exist on object<App\Model\licence\Licence>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
71
72
            return view('themes.default1.serviceprovider.pricing', compact('licences'));
73
        } catch (\Exception $ex) {
74
            return redirect()->back()->with('fails', $ex->getMessage());
75
        }
76
    }
77
78
    public function GetOrders()
79
    {
80
        return \Datatable::collection($this->LicencedOrg->where('organization_id', $this->org->id)->get())
0 ignored issues
show
Bug introduced by
The property LicencedOrg does not seem to exist. Did you mean licence?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
81
82
                        ->showColumns('licence_name', 'licence_description', 'number_of_slas', 'price', 'payment_status')
83
                        ->searchColumns('licence_name')
84
                        ->orderColumns('licence_name')
85
                        ->make();
86
    }
87
88
    public function GetSlas()
89
    {
90
        return \Datatable::collection($this->sla->where('service_provider_id', $this->org->id)->get())
91
                        ->addColumn('licence_id', function ($model) {
92
                            $licence_name = $this->licence->where('id', $model->licence_id)->first()->name;
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\licence\Licence>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
93
94
                            return $licence_name;
95
                        })
96
                        ->showColumns('name', 'description')
97 View Code Duplication
                        ->addColumn('service', function ($model) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
                            $serviceid = $this->slaServiceRelation->where('sla_id', $model->id)->first()->service_id;
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\licence\SlaServiceRelation>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
99
100
                            return $this->service->where('id', $serviceid)->first()->name;
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\Product\Service>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
101
                        })
102 View Code Duplication
                        ->addColumn('organization_id', function ($model) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
                            $name = $this->organization->where('id', $model->organization_id)->where('type', 'client')->first()->name;
104
105
                            return $name;
106
                        })
107
108
                        ->showColumns('start_date', 'end_date', 'grace_period')
109
                        ->addColumn('action', function ($model) {
110
                            return '<a href='.url('slas/'.$model->id.'/edit')." class='btn btn-sm btn-primary'>Edit</a>";
111
                        })
112
                        ->searchColumns('name')
113
                        ->orderColumns('name')
114
                        ->make();
115
    }
116
117
    public function AddtoCart($id, Request $request)
118
    {
119
        try {
120
            $licence = new \App\Model\licence\Licence();
121
            $item = $licence->where('id', $id)->first();
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\licence\Licence>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
122
            //dd($item);
123
            $order = $this->LicencedOrg->create([
0 ignored issues
show
Bug introduced by
The property LicencedOrg does not seem to exist. Did you mean licence?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Unused Code introduced by
$order 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...
124
                'organization_id'     => $this->org->id,
125
                'licence_name'        => $item->name,
126
                'licence_description' => $item->description,
127
                'number_of_slas'      => $item->number_of_sla,
128
                'price'               => $item->price,
129
130
                ]);
131
132
            //dd($request);
133
           \Event::fire(new \App\Events\SmsIntegration($request));
134
           //\Event::fire(new \App\Events\PaymentGateway(['request' => $request, 'cart' => [], 'order' => $order]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
135
        } catch (\Exception $ex) {
136
            return redirect()->back()->with('fails', $ex->getMessage());
137
        }
138
    }
139
}
140