Fixed some inspection issues.

This commit is contained in:
Jan Böhmer 2020-08-21 22:43:37 +02:00
parent 6caf605fe2
commit e01b06fb85
80 changed files with 173 additions and 218 deletions

View file

@ -52,7 +52,6 @@ use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\PostLoad;
use Doctrine\ORM\Mapping\PreUpdate;
use function get_class;
use InvalidArgumentException;
use ReflectionClass;
@ -162,14 +161,14 @@ class ElementPermissionListener
$property->setAccessible(true);
//If the user is not allowed to edit or read this property, reset all values.
//Set value to old value, so that there a no change to this property
if ((!$this->isGranted('read', $annotation, $element)
|| !$this->isGranted('edit', $annotation, $element))) {
//Set value to old value, so that there a no change to this property
if (isset($old_data[$property->getName()])) {
|| !$this->isGranted('edit', $annotation, $element)) && isset(
$old_data[$property->getName()]
)) {
$property->setValue($element, $old_data[$property->getName()]);
$changed = true;
}
}
if ($changed) {
//Schedule for update, so the post update method will be called
@ -184,13 +183,9 @@ class ElementPermissionListener
*
* @return bool Returns true if the current programm is running from CLI (terminal)
*/
protected function isRunningFromCLI()
protected function isRunningFromCLI(): bool
{
if (empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && count($_SERVER['argv']) > 0) {
return true;
}
return false;
return empty($_SERVER['REMOTE_ADDR']) && !isset($_SERVER['HTTP_USER_AGENT']) && count($_SERVER['argv']) > 0;
}
/**

View file

@ -66,7 +66,7 @@ abstract class ExtendedVoter extends Voter
$this->entityManager = $entityManager;
}
final protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
final protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
{
$user = $token->getUser();

View file

@ -44,7 +44,6 @@ namespace App\Security\Voter;
use App\Entity\Parts\Part;
use App\Entity\UserSystem\User;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
/**
* A Voter that votes on Part entities.

View file

@ -76,16 +76,14 @@ class UserVoter extends ExtendedVoter
*/
protected function voteOnUser($attribute, $subject, User $user): bool
{
if ($subject instanceof User) {
//Check if the checked user is the user itself
if ($subject->getID() === $user->getID() &&
$this->resolver->isValidOperation('self', $attribute)) {
//Then we also need to check the self permission
$tmp = $this->resolver->inherit($user, 'self', $attribute) ?? false;
//But if the self value is not allowed then use just the user value:
if ($tmp) {
return $tmp;
}
//Check if the checked user is the user itself
if (($subject instanceof User) && $subject->getID() === $user->getID() &&
$this->resolver->isValidOperation('self', $attribute)) {
//Then we also need to check the self permission
$tmp = $this->resolver->inherit($user, 'self', $attribute) ?? false;
//But if the self value is not allowed then use just the user value:
if ($tmp) {
return $tmp;
}
}