You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Operating System / Distribution & Version: (Windows 10 / CentOS 7.6 / ...): Ubuntu
Current Behavior
Rule ifstatementassignment is thrown on a function signature that does not contain any if-statement assignments.
Full Function where Rule is Thrown:
public function setOrganizations() : AssociateRecords
{
if ($this->request->has('organizations')) {
// get the user's current organizations so we can properly set updated user / date
$currentOrganizations = $this->user->organizations->keyBy('id');
$organizationIDs = Organization::findMany($this->request->get('organizations'))
->pluck('id');
$toSync = collect();
// loop over each ID and update or modify the record
$organizationIDs->each(function ($id) use ($currentOrganizations, $toSync) {
$createdAt = new \DateTime;
$createdBy = auth()->id();
if ($currentOrganizations->has($id)) {
/** @var Organization $org */
$org = $currentOrganizations->get($id);
$createdAt = $org->pivot->created_at;
$createdBy = $org->pivot->created_by;
}
$toSync->put($id, [
'created_at' => $createdAt,
'created_by' => $createdBy,
'updated_at' => new \DateTime(),
'modified_by' => auth()->id(),
]);
});
// sync
$this->user->organizations()->sync($toSync->toArray());
}
return $this;
}
Expected Behavior
The rule should not be thrown in the example code above. I'm not sure exactly what is causing it to trigger. I thought it was the type hinted return type but removing that didn't resolve it.
Steps To Reproduce:
Explain all the steps you did to create this bug so we can reproduce it.
I have been using phpmd on my code base for quite a while and not encountered this violation before
my code base has not changed significantly and these lines are not newly created. I'm not sure why this just started happening, it popped up in a CI / CD build recently.
I updated to the latest version of phpmd 2.7 in hopes that it would be resolved, but that did not help.
Checks before submitting
Be sure that there isn't already an issue about this. See: Issues list
Be sure that there isn't already a pull request about this. See: Pull requests
I have added every step to reproduce the bug.
If possible I added relevant code examples.
This issue is about 1 bug and nothing more.
The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".
The text was updated successfully, but these errors were encountered:
Current Behavior
Rule
ifstatementassignment
is thrown on a function signature that does not contain any if-statement assignments.Full Function where Rule is Thrown:
Expected Behavior
The rule should not be thrown in the example code above. I'm not sure exactly what is causing it to trigger. I thought it was the type hinted return type but removing that didn't resolve it.
Steps To Reproduce:
Explain all the steps you did to create this bug so we can reproduce it.
Checks before submitting
The text was updated successfully, but these errors were encountered: