From 3fe452626dd0865bfb708d77ecd594e0b901eb79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 20 Mar 2019 23:24:20 +0100 Subject: [PATCH] Fixed some inspection issues. --- src/Entity/Part.php | 4 ++-- src/Entity/PermissionsEmbed.php | 4 ++-- src/Entity/StructuralDBElement.php | 24 +++++++++---------- .../ElementPermissionListener.php | 10 ++++---- src/Security/Voter/PartVoter.php | 2 +- src/Services/EntityURLGenerator.php | 2 ++ templates/Parts/show_part_info.html.twig | 2 +- templates/Users/user_info.html.twig | 2 +- templates/base.html.twig | 2 +- 9 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/Entity/Part.php b/src/Entity/Part.php index 73931e06..c3e57e02 100644 --- a/src/Entity/Part.php +++ b/src/Entity/Part.php @@ -585,9 +585,9 @@ class Part extends AttachmentContainingDBElement if (\is_string($delimeter)) { return implode($delimeter, $supplier_names); - } else { - return $supplier_names; } + + return $supplier_names; } } diff --git a/src/Entity/PermissionsEmbed.php b/src/Entity/PermissionsEmbed.php index 5f95327d..39e15ef4 100644 --- a/src/Entity/PermissionsEmbed.php +++ b/src/Entity/PermissionsEmbed.php @@ -286,9 +286,9 @@ class PermissionsEmbed if (self::DISALLOW == $value) { return false; - } else { - return null; } + + return null; } /** diff --git a/src/Entity/StructuralDBElement.php b/src/Entity/StructuralDBElement.php index 6fa0cf3d..b10e6946 100644 --- a/src/Entity/StructuralDBElement.php +++ b/src/Entity/StructuralDBElement.php @@ -40,10 +40,10 @@ use Doctrine\ORM\PersistentCollection; */ abstract class StructuralDBElement extends AttachmentContainingDBElement { - const ID_ROOT_ELEMENT = 0; + public const ID_ROOT_ELEMENT = 0; //This is a not standard character, so build a const, so a dev can easily use it - const PATH_DELIMITER_ARROW = ' → '; + public const PATH_DELIMITER_ARROW = ' → '; // We can not define the mapping here or we will get an exception. Unfortunatly we have to do the mapping in the // subclasses @@ -146,9 +146,7 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement */ public function getComment(bool $parse_bbcode = true): string { - $val = htmlspecialchars($this->comment ?? ''); - - return $val; + return htmlspecialchars($this->comment ?? ''); } /** @@ -217,15 +215,15 @@ abstract class StructuralDBElement extends AttachmentContainingDBElement if (!$recursive) { return $this->children; - } else { - $all_elements = array(); - foreach ($this->children as $subelement) { - $all_elements[] = $subelement; - $all_elements = array_merge($all_elements, $subelement->getSubelements(true)); - } - - return $all_elements; } + + $all_elements = array(); + foreach ($this->children as $subelement) { + $all_elements[] = $subelement; + $all_elements = array_merge($all_elements, $subelement->getSubelements(true)); + } + + return $all_elements; } /****************************************************************************** diff --git a/src/Security/EntityListeners/ElementPermissionListener.php b/src/Security/EntityListeners/ElementPermissionListener.php index 0cc7819e..e7b09647 100644 --- a/src/Security/EntityListeners/ElementPermissionListener.php +++ b/src/Security/EntityListeners/ElementPermissionListener.php @@ -76,12 +76,10 @@ class ElementPermissionListener $annotation = $reader->getPropertyAnnotation($property, ColumnSecurity::class); - if (null !== $annotation) { - //Check if user is allowed to read info, otherwise apply placeholder - if (!$this->security->isGranted($annotation->getReadOperationName(), $element)) { - $property->setAccessible(true); - $property->setValue($element, $annotation->getPlaceholder()); - } + //Check if user is allowed to read info, otherwise apply placeholder + if ((null !== $annotation) && !$this->security->isGranted($annotation->getReadOperationName(), $element)) { + $property->setAccessible(true); + $property->setValue($element, $annotation->getPlaceholder()); } } } diff --git a/src/Security/Voter/PartVoter.php b/src/Security/Voter/PartVoter.php index 3de8c089..a7355448 100644 --- a/src/Security/Voter/PartVoter.php +++ b/src/Security/Voter/PartVoter.php @@ -13,7 +13,7 @@ use Symfony\Component\Security\Core\Authorization\Voter\Voter; */ class PartVoter extends ExtendedVoter { - const READ = 'read'; + public const READ = 'read'; protected function supports($attribute, $subject) { diff --git a/src/Services/EntityURLGenerator.php b/src/Services/EntityURLGenerator.php index abe38698..c309ea9f 100644 --- a/src/Services/EntityURLGenerator.php +++ b/src/Services/EntityURLGenerator.php @@ -109,5 +109,7 @@ class EntityURLGenerator if ($entity instanceof NamedDBElement) { return sprintf('%s', $href, $entity->getName()); } + + throw new EntityNotSupported('The given entity is not supported yet!'); } } diff --git a/templates/Parts/show_part_info.html.twig b/templates/Parts/show_part_info.html.twig index a4729f97..7a2d0513 100644 --- a/templates/Parts/show_part_info.html.twig +++ b/templates/Parts/show_part_info.html.twig @@ -18,7 +18,7 @@
- + Part main image
{{ part.manufacturer.name ?? ""}}
diff --git a/templates/Users/user_info.html.twig b/templates/Users/user_info.html.twig index 31c9e401..07262c01 100644 --- a/templates/Users/user_info.html.twig +++ b/templates/Users/user_info.html.twig @@ -9,7 +9,7 @@
- + User avatar
diff --git a/templates/base.html.twig b/templates/base.html.twig index 3f5a7361..0856d7b5 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -1,5 +1,5 @@ - +