Issues (415)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

app/Http/Controllers/LotsController.php (23 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Requests\SaveLotRequest;
6
use App\Lot;
7
use App\Repositories\ImprovedSpecRepository;
8
use App\Repositories\SpecPriceRepository;
9
use App\Repositories\LotRepository;
10
use App\Repositories\ProductsRepository;
11
use App\Repositories\SubCategoriesRepository;
12
use App\Repositories\MethodDeliveryPaymentRepository;
13
use App\Repositories\LotDeliveryPaymentRepository;
14
use App\Repositories\CurrenciesRepository;
15
use App\Vendor;
16
use Illuminate\Contracts\Auth\Guard;
17
use Illuminate\Http\Request;
18
19
use App\Http\Requests;
20
21
class LotsController extends Controller
22
{
23
    /**
24
     * @var LotRepository
25
     */
26
    protected $lots;
27
28
    /**
29
     * @var Guard
30
     */
31
    protected $auth;
32
33
    /**
34
     * @var ProductsRepository
35
     */
36
    protected $products;
37
38
    /**
39
     * @var ImprovedSpecRepository
40
     */
41
    protected $improvedSpecs;
42
43
    protected $specPrice;
44
45
46
    protected $sub_category;
47
48
    protected $method;
49
50
    protected $lot_method;
51
52
    protected $currencies;
53
54
    /**
55
     * LotsController constructor.
56
     * @param LotRepository $lotRepository
57
     * @param ProductsRepository $productsRepository
58
     * @param ImprovedSpecRepository $improvedSpecRepository
59
     * @param Guard $auth
60
     */
61 View Code Duplication
    public function __construct(
0 ignored issues
show
This method seems to be duplicated in your project.

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

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

Loading history...
62
        LotRepository $lotRepository,
63
        ProductsRepository $productsRepository,
64
        ImprovedSpecRepository $improvedSpecRepository,
65
        SpecPriceRepository $specPriceRepository,
66
        SubCategoriesRepository $subCategoriesRepository,
67
        MethodDeliveryPaymentRepository $methodDeliveryPaymentRepository,
68
        LotDeliveryPaymentRepository $lotDeliveryPaymentRepository,
69
        CurrenciesRepository $currenciesRepository,
70
        Guard $auth
71
    ) {
72
        $this->lots          = $lotRepository;
73
        $this->auth          = $auth;
74
        $this->products      = $productsRepository;
75
        $this->improvedSpecs = $improvedSpecRepository;
76
        $this->specPrice     = $specPriceRepository;
77
        $this->sub_category  = $subCategoriesRepository;
78
        $this->method        = $methodDeliveryPaymentRepository;
79
        $this->lot_method    = $lotDeliveryPaymentRepository;
80
        $this->currencies    = $currenciesRepository;
81
    }
82
83
    /**
84
     * Create lot or modify drafted for vendor.
85
     *
86
     * @param Vendor $vendor
87
     * @return \Illuminate\View\View
88
     */
89 View Code Duplication
    public function create(Vendor $vendor)
0 ignored issues
show
This method seems to be duplicated in your project.

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

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

Loading history...
90
    {
91
        $lot = $this->lots->addLot($vendor);
92
        $delivery = $this->method->getPublic('delivery');
93
        $payment = $this->method->getPublic('payment');
94
        return view('lots.create', compact('lot','delivery','payment'));
0 ignored issues
show
Bug Compatibility introduced by
The expression view('lots.create', comp...delivery', 'payment')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 94 which is incompatible with the return type documented by App\Http\Controllers\LotsController::create of type Illuminate\View\View.
Loading history...
95
    }
96
97
    /**
98
     * @param Lot $lot
99
     * @return \Illuminate\View\View
100
     */
101 View Code Duplication
    public function edit(Lot $lot)
0 ignored issues
show
This method seems to be duplicated in your project.

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

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

Loading history...
102
    {
103
        //dd($lot->lotDeliveryPayment());
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...
104
        $delivery = $this->method->getPublic('delivery');
105
        $payment = $this->method->getPublic('payment');
106
        return view('lots.create', compact('lot','delivery','payment'));
0 ignored issues
show
Bug Compatibility introduced by
The expression view('lots.create', comp...delivery', 'payment')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 106 which is incompatible with the return type documented by App\Http\Controllers\LotsController::edit of type Illuminate\View\View.
Loading history...
107
    }
108
109
    /**
110
     * Remove lot.
111
     *
112
     * @param Lot $lot
113
     * @return mixed
114
     */
115
    public function delete(Lot $lot)
116
    {
117
        $this->lots->delete($lot);
118
119
        return redirect()->route('my_lots')
0 ignored issues
show
The method withStatus() does not exist on Illuminate\Http\RedirectResponse. Did you maybe mean status()?

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...
120
            ->withStatus(sprintf('Lot %s was removed', $lot->present()->renderName()))
0 ignored issues
show
The method present() does not exist on App\Lot. Did you maybe mean scopePresent()?

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...
121
            ->withColor('green');
122
    }
123
124
    /**
125
     * Select category.
126
     *
127
     * @param Request $request
128
     * @param Lot $lot
129
     *
130
     * @return string
131
     */
132
/*    public function selectCategory(Request $request, Lot $lot)
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
133
    {
134
        if($this->lots->checkIfPossibleToChangeCategory($lot)) {
135
            $this->lots->changeCategory($lot, $request->get('category_id'));
136
            return 'true';
137
        }
138
139
        return 'false';
140
    }*/
141
142
    public function selectCategory(Request $request, Lot $lot)
143
    {
144
        $sub_category = $this->sub_category->getSubCategory($request->get('category_id'));
145
        $this->lots->changeCategory($lot, $request->get('category_id'));
146
        $json = array(
147
            'sub_category' => $sub_category,
148
            'respons'      => true
149
        );
150
         return response($json);
0 ignored issues
show
$json is of type array<string,?,{"sub_cat...","respons":"boolean"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
151
    }
152
153
    /**
154
     * Load product form for lot create/edit.
155
     *
156
     * @param Request $request
157
     * @param Lot $lot
158
     * @return mixed
159
     */
160
    public function loadProductBlock(Request $request, Lot $lot)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
161
    {
162
        if($lot->category_id) {
0 ignored issues
show
The property category_id does not exist on object<App\Lot>. Since you implemented __get, maybe consider adding a @property annotation.

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

}

If the property has read access only, you can use the @property-read 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...
163
            $product = $this->products->createPlain($lot);
164
165
            return view('lots.partials.form.product', ['product' => $product, 'lot' => $lot]);
166
        }
167
168
        return 'false';
169
    }
170
171
    /**
172
     * Load specification
173
     *
174
     * @param Request $request
175
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
176
     */
177
178
179
    /**
180
     * Load improved spec.
181
     * 
182
     * @param Request $request
183
     * @return mixed
184
     */
185
    public function loadImprovedSpec(Request $request)
186
    {
187
        $spec = $this->improvedSpecs->createPlain($request->get('product_id'));
188
        
189
        return view('lots.partials.form.improved_specs', [ 'spec' => $spec ]);
190
    }
191
192
    /**
193
     * @param SaveLotRequest $request
194
     * @param Lot $lot
195
     * @return mixed
196
     */
197
    public function saveLot(SaveLotRequest $request, Lot $lot)
198
    {
199
        $lot = $this->lots->save($lot, $request->all());
200
        return redirect()->route('edit_lot', [ $lot ])
0 ignored issues
show
The method withStatus() does not exist on Illuminate\Http\RedirectResponse. Did you maybe mean status()?

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...
201
            ->withStatus('You created lot successefully. Waiting for moderator verify it. You will be notificated!');
202
    }
203
204 View Code Duplication
    public function updateLot(SaveLotRequest $request, Lot $lot)
0 ignored issues
show
This method seems to be duplicated in your project.

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

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

Loading history...
205
    {
206
        $lot = $this->lots->save($lot, $request->all());
207
        $method = [];
208
        if ($request->input('method')) {
209
            $method  = $request->input('method');
210
        }
211
        $lotMethod = $this->lot_method->save($lot, $method);
0 ignored issues
show
It seems like $method defined by $request->input('method') on line 209 can also be of type string; however, App\Repositories\LotDeli...ymentRepository::save() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
$lotMethod 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...
212
        return response(array('respons'=>true));
0 ignored issues
show
array('respons' => true) is of type array<string,boolean,{"respons":"boolean"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
213
        
214
    }
215
216 View Code Duplication
    public function publishedLot(SaveLotRequest $request, Lot $lot)
0 ignored issues
show
This method seems to be duplicated in your project.

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

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

Loading history...
217
    {
218
        $lot = $this->lots->save($lot, $request->all());
219
        $method = [];
220
        if ($request->input('method')) {
221
            $method  = $request->input('method');
222
        }
223
        $lotMethod = $this->lot_method->save($lot, $method);
0 ignored issues
show
It seems like $method defined by $request->input('method') on line 221 can also be of type string; however, App\Repositories\LotDeli...ymentRepository::save() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
$lotMethod 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...
224
225
        return response(array('respons'=>true,'status'=>$lot->status));
0 ignored issues
show
array('respons' => true,...tatus' => $lot->status) is of type array<string,?,{"respons...boolean","status":"?"}>, but the function expects a string.

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

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

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

function acceptsInteger($int) { }

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

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
226
        
227
    }
228
229
    /**
230
     *
231
     */
232
    public function index()
233
    {
234
       /* dd(Lot::all());*/
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% 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...
235
    }
236
237
    /**
238
     * Show user's all lots;
239
     *
240
     * @return \Illuminate\View\View
241
     */
242
    public function myLots()
243
    {
244
        $lots = $this->lots->userLots($this->getUser(), 5);
245
        return view('lots.my_lots', compact('lots'));
0 ignored issues
show
Bug Compatibility introduced by
The expression view('lots.my_lots', compact('lots')); of type Illuminate\View\View|Ill...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 245 which is incompatible with the return type documented by App\Http\Controllers\LotsController::myLots of type Illuminate\View\View.
Loading history...
246
    }
247
248
    /**
249
     * @param Lot $lot
250
     * @return mixed
251
     */
252
    public function show(Lot $lot)
253
    {
254
        return view('lots.show', compact('lot'));
255
    }
256
257
258
    /**
259
     * Get user from Guard\Auth
260
     *
261
     * @return \Illuminate\Contracts\Auth\Authenticatable|null
262
     */
263
    public function getUser()
264
    {
265
        return $this->auth->user();
266
    }
267
}