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/UsersController.php (5 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\InvolveProductRequest;
6
use App\Http\Requests\ExitProductRequest;
7
use App\Repositories\InvolvedRepository;
8
use App\Repositories\LotRepository;
9
use App\Repositories\SpecPriceRepository;
10
use Illuminate\Http\Request;
11
12
class UsersController extends Controller
13
{
14
    /**
15
     * @var InvolvedRepository
16
     */
17
    protected $involved;
18
19
    /**
20
     * @var LotRepository
21
     */
22
    protected $lot;
23
24
    /**
25
     * @var SpecPriceRepository
26
     */
27
    protected $specs;
28
29
    /**
30
     * UsersController constructor.
31
     * @param InvolvedRepository $involvedRepository
32
     */
33
    public function __construct(InvolvedRepository $involvedRepository,
34
                                LotRepository $lotRepository,
35
                                SpecPriceRepository $specPriceRepository)
36
    {
37
        $this->involved = $involvedRepository;
38
        $this->lot = $lotRepository;
39
        $this->specs = $specPriceRepository;
40
    }
41
42
    /**
43
     * Involve the product method.
44
     *
45
     * @param InvolveProductRequest $request
46
     * @param $product
47
     * @return \Illuminate\Http\RedirectResponse
48
     */
49
50
    public function involveProductOffer(InvolveProductRequest $request, $product)
51
    {
52
53
        $this->involved->create($request->all(), $product);
54
55
        $selledPrice = $this->countInvolvedLot($product);
56
57
        if ($selledPrice >= $product->lot->yield_amount) {
58
59
            $product->lot->update(['verify_status' => 'expired']);
60
61
            return redirect()->back()->with(['status' => 'Oferta este finisata!', 'color' => 'green']);
62
        }
63
64
        return redirect()->back()->with(['status' => 'Success! You are involve the product offer.', 'color' => 'green']);
65
    }
66
67
    /**
68
     * Exit involved product.
69
     *
70
     * @param ExitProductRequest $request
71
     * @param $involve
72
     * @return \Illuminate\Http\RedirectResponse
73
     */
74
    public function exitProductOffer(ExitProductRequest $request, $involve, $product)
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...
75
    {
76
        $selledPrice = $this->countInvolvedLot($product);
77
78
        $involve = $this->involved->update($involve, ['active' => 0]);
79
80
        $remaining = config('product.times') - $this->involved->getInvolveTimesProduct($involve->product);
0 ignored issues
show
The property product does not exist on object<App\Involved>. 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...
81
82
        if ($selledPrice < $product->lot->yield_amount) {
83
            $product->lot->update(['verify_status' => 'verified']);
84
        }
85
86
87
        return redirect()->back()->with(['status'=>'Success! You are exit from product offer. Remaining attempts (' . $remaining . ')','color'=>'green']);
88
    }
89
90
    /**
91
     * @param $product
92
     * @return number
93
     */
94
    public function countInvolvedLot($product)
95
    {
96
        $count = $product->lot->involved;
97
98
        foreach ($count as $item) {
99
            $changes[] = $item->count * $this->specs->getPriceById($item->price_id);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$changes was never initialized. Although not strictly required by PHP, it is generally a good practice to add $changes = 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...
The method getPriceById() does not seem to exist on object<App\Repositories\SpecPriceRepository>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
        }
101
        return array_sum($changes);
0 ignored issues
show
The variable $changes 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...
102
    }
103
}