feat: prevent future object access issues in SameProjectRewardChargeValidator
This commit is contained in:
@@ -3,23 +3,31 @@
|
||||
namespace App\Validator;
|
||||
|
||||
use App\ApiResource\Project\RewardClaimApiResource;
|
||||
use App\Entity\Accounting\Accounting;
|
||||
use App\Entity\Project\Project;
|
||||
use App\Mapping\AutoMapper;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
final class SameProjectRewardChargeValidator extends ConstraintValidator
|
||||
{
|
||||
public function __construct(
|
||||
private AutoMapper $mapper,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param RewardClaimApiResource $value
|
||||
*/
|
||||
public function validate(mixed $value, Constraint $constraint): void
|
||||
{
|
||||
$charge = $value->charge;
|
||||
$reward = $value->reward;
|
||||
|
||||
/** @var Accounting */
|
||||
$target = $this->mapper->map($value->charge->target, Accounting::class);
|
||||
|
||||
if (
|
||||
$charge->target->ownerObject instanceof Project
|
||||
&& $charge->target->ownerObject?->getId() === $reward->project->id
|
||||
$target->getProject() instanceof Project
|
||||
&& $target->getProject()->getId() === $reward->project->id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user