nyacide /
amma
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
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\Repositories\UserRepository; |
||
| 6 | use App\Repositories\LotRepository; |
||
| 7 | use App\Repositories\ProfileRepository; |
||
| 8 | use App\Repositories\InvolvedRepository; |
||
| 9 | use Carbon\Carbon; |
||
| 10 | use Illuminate\Contracts\Auth\Guard; |
||
| 11 | use App\Http\Requests\UpdateUserSettings; |
||
| 12 | use App\Http\Requests\UpdateUserPassword; |
||
| 13 | use App\Services\ImageProcessor; |
||
| 14 | use App\Video; |
||
| 15 | use Illuminate\Http\UploadedFile; |
||
| 16 | |||
| 17 | |||
| 18 | class DashboardController extends Controller |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var UserRepository |
||
| 22 | */ |
||
| 23 | protected $users; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var ProfileRepository |
||
| 27 | */ |
||
| 28 | protected $profile; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var Guard |
||
| 32 | */ |
||
| 33 | private $auth; |
||
| 34 | |||
| 35 | private $lots; |
||
| 36 | |||
| 37 | private $involved; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * DashboardController constructor. |
||
| 41 | * @param UserRepository $userRepository |
||
| 42 | * @param Guard $auth |
||
| 43 | */ |
||
| 44 | public function __construct(UserRepository $userRepository, |
||
| 45 | Guard $auth, |
||
| 46 | ProfileRepository $profileRepository, |
||
| 47 | LotRepository $lotRepository, |
||
| 48 | InvolvedRepository $involvedRepository |
||
| 49 | ) |
||
| 50 | { |
||
| 51 | $this->users = $userRepository; |
||
| 52 | $this->profile = $profileRepository; |
||
| 53 | $this->auth = $auth; |
||
| 54 | $this->lots = $lotRepository; |
||
| 55 | $this->involved = $involvedRepository; |
||
| 56 | } |
||
| 57 | |||
| 58 | public function howWork() |
||
| 59 | { |
||
| 60 | |||
| 61 | $video = Video::orderBy('id', 'desc')->get(); |
||
| 62 | |||
| 63 | return view('dashboard.how-amma-work', compact('video')); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * My vendors. |
||
| 68 | * |
||
| 69 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 70 | */ |
||
| 71 | public function myVendors() |
||
| 72 | { |
||
| 73 | $vendors = $this->auth->user()->vendors; |
||
|
0 ignored issues
–
show
|
|||
| 74 | |||
| 75 | return view('dashboard.my-vendors', compact('vendors')); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * My products. |
||
| 80 | * |
||
| 81 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 82 | */ |
||
| 83 | public function myProducts() |
||
| 84 | { |
||
| 85 | $vendors = $this->auth->user()->vendors; |
||
|
0 ignored issues
–
show
Accessing
vendors on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
| 86 | |||
| 87 | return view('dashboard.my-products', compact('vendors')); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * My products. |
||
| 92 | * |
||
| 93 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 94 | */ |
||
| 95 | public function myInvolved() |
||
| 96 | { |
||
| 97 | $involved = $this->auth->user()->involved()->active()->get(); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Illuminate\Contracts\Auth\Authenticatable as the method involved() does only exist in the following implementations of said interface: App\User.
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 98 | |||
| 99 | $product = $this->sortInvolvedProducts($involved); |
||
| 100 | |||
| 101 | return view('dashboard.my-involved', compact('product')); |
||
| 102 | } |
||
| 103 | |||
| 104 | public function sortInvolvedProducts($involved) { |
||
| 105 | |||
| 106 | if (count($involved)) { |
||
| 107 | foreach ($involved as $item) { |
||
| 108 | if ($item->lot->verify_status == 'verified') { |
||
| 109 | $product[] = ['date' =>$item->lot->public_date, 'product' => $item->product, 'involved' => $item]; |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$product was never initialized. Although not strictly required by PHP, it is generally a good practice to add $product = 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 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...
|
|||
| 110 | }else { |
||
| 111 | $product[] = ['date' =>date('dmy',strtotime('9999999')), 'product' => $item->product, 'involved' => $item]; |
||
|
0 ignored issues
–
show
The variable
$product 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
Loading history...
|
|||
| 112 | } |
||
| 113 | } |
||
| 114 | usort($product, function ($product, $b) { |
||
| 115 | return date('dmy',strtotime($b['date'])) - date('dmy',strtotime($product['date'])); |
||
| 116 | }); |
||
| 117 | |||
| 118 | return $product; |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Account and password settings. |
||
| 124 | * |
||
| 125 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
||
| 126 | */ |
||
| 127 | public function accountSettings() |
||
| 128 | { |
||
| 129 | return view('dashboard.account-settings'); |
||
| 130 | } |
||
| 131 | |||
| 132 | public function userPassword() |
||
| 133 | { |
||
| 134 | return view('dashboard.user-password'); |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param UpdateUserSettings $request |
||
| 139 | * @return mixed |
||
| 140 | */ |
||
| 141 | public function update(UpdateUserSettings $request) |
||
| 142 | { |
||
| 143 | $this->users->update_user($request->all()); |
||
| 144 | |||
| 145 | $image = $request->file('photo'); |
||
| 146 | if ($image && $image instanceof UploadedFile) { |
||
| 147 | (new ImageProcessor())->changeAvatar($image); |
||
| 148 | } |
||
| 149 | |||
| 150 | return back()->withStatus('Setarile au fost modificate!')->withColor('green')->with('activeclass', 'update_settings'); |
||
|
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...
|
|||
| 151 | } |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @param UpdateUserPassword $request |
||
| 155 | * @return mixed |
||
| 156 | */ |
||
| 157 | public function updatePassword(UpdateUserPassword $request) |
||
| 158 | { |
||
| 159 | $this->users->updatePassword($request->password); |
||
|
0 ignored issues
–
show
The property
password does not exist on object<App\Http\Requests\UpdateUserPassword>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?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...
|
|||
| 160 | |||
| 161 | return back()->withStatus('Password Updated!')->with('activeclass', 'update_password'); |
||
|
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...
|
|||
| 162 | } |
||
| 163 | } |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: