diff --git a/application/src/Controller/AbstractEntityController.php b/application/src/Controller/AbstractEntityController.php index 7278006..187936d 100644 --- a/application/src/Controller/AbstractEntityController.php +++ b/application/src/Controller/AbstractEntityController.php @@ -1,4 +1,5 @@ setEntityName(); } - - abstract protected function setEntityName():void; - + + abstract protected function setEntityName(): void; + protected function loadEntityById(int $id): EntityInterface { $entity = $this->getDoctrine() @@ -31,13 +31,14 @@ abstract class AbstractEntityController extends FOSRestController if (!$entity) { throw $this->createNotFoundException('No entity found for id '.$id); } + return $entity; } - + protected function redirectToRouteById(string $route, int $id): RedirectResponse { return $this->redirectToRoute($route, [ - 'id' => $id + 'id' => $id, ]); } -} \ No newline at end of file +} diff --git a/application/src/Controller/LawController.php b/application/src/Controller/LawController.php index 9ae4bb2..e6beaa1 100644 --- a/application/src/Controller/LawController.php +++ b/application/src/Controller/LawController.php @@ -1,64 +1,60 @@ loadEntityById($id); $view = $this->view($law, 200) ->setTemplate('law/view/standard.html.twig') ->setTemplateVar('law'); + return $this->handleView($view); } /** - * * @Route("/law/{id}/right.{_format}", defaults={"_format"="html"}) */ public function right(int $id): RedirectResponse { - /** - * - * @todo Implement function! - */ + /* + * + * @todo Implement function! + */ } /** - * * @Route("/law/{id}/node.{_format}", defaults={"_format"="html"}) */ public function node(int $id): RedirectResponse { - /** - * - * @todo Implement function! - */ + /* + * + * @todo Implement function! + */ } protected function setEntityName(): void { $this->entityName = Law::class; } -} \ No newline at end of file +} diff --git a/application/src/Controller/NodeController.php b/application/src/Controller/NodeController.php index 5aea2aa..9542866 100644 --- a/application/src/Controller/NodeController.php +++ b/application/src/Controller/NodeController.php @@ -12,6 +12,7 @@ use App\Entity\Meta\Relation; /** * @todo IMPLEMENT SECURITY! * @todo Refactor! + * * @author kevinfrantz */ class NodeController extends AbstractEntityController @@ -22,42 +23,46 @@ class NodeController extends AbstractEntityController public function show(Request $request, int $id): Response { /** - * @var RelationInterface $node + * @var RelationInterface */ $relation = $this->loadEntityById($id); $view = $this->view($relation, 200) ->setTemplate('node/view/standard.html.twig') ->setTemplateVar('node'); + return $this->handleView($view); } - + /** * @Route("/node/{id}/law.{_format}", defaults={"_format"="html"}) */ public function law(int $id): RedirectResponse { $lawId = $this->loadEntityById($id)->getLaw()->getId(); - return $this->redirectToRouteById('app_law_show',$lawId); + + return $this->redirectToRouteById('app_law_show', $lawId); } - + /** * @Route("/node/{id}/parents.{_format}", defaults={"_format"="html"}) */ - public function parents(int $id):Response{ - /** + public function parents(int $id): Response + { + /* * @todo Implement */ } - + /** * @Route("/node/{id}/childs.{_format}", defaults={"_format"="html"}) */ - public function childs(int $id):Response{ - /** + public function childs(int $id): Response + { + /* * @todo Implement */ } - + protected function setEntityName(): void { $this->entityName = Relation::class; diff --git a/application/src/Controller/SourceController.php b/application/src/Controller/SourceController.php index 69735d6..54f3fb2 100644 --- a/application/src/Controller/SourceController.php +++ b/application/src/Controller/SourceController.php @@ -1,12 +1,11 @@ view($source, 200) ->setTemplate((new SourceTemplateFactory($source, $request))->getTemplatePath()) ->setTemplateVar('source'); - + return $this->handleView($view); } /** - * * @Route("/source/{id}/edit.{_format}", defaults={"_format"="html"}) */ public function edit(Request $request, int $id): Response @@ -52,23 +47,24 @@ class SourceController extends AbstractEntityController $source = $form->getData(); $this->saveSource($source); } - + return $this->render((new SourceTemplateFormFactory($source, $request))->getTemplatePath(), [ - 'form' => $form->createView() + 'form' => $form->createView(), ]); } /** - * * @Route("/source/{id}/node.{_format}", defaults={"_format"="html"}) */ public function node(int $id): RedirectResponse { $nodeId = $this->loadNodeById($id)->getId(); - return $this->redirectToRouteById('app_node_show',$nodeId); + + return $this->redirectToRouteById('app_node_show', $nodeId); } - - private function loadNodeById(int $id):RelationInterface{ + + private function loadNodeById(int $id): RelationInterface + { return $this->loadEntityById($id)->getNode(); } diff --git a/application/src/DBAL/Types/MenuEventType.php b/application/src/DBAL/Types/MenuEventType.php index 7569131..eec69b1 100644 --- a/application/src/DBAL/Types/MenuEventType.php +++ b/application/src/DBAL/Types/MenuEventType.php @@ -5,20 +5,22 @@ namespace App\DBAL\Types; use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType; /** - * Not integrated in the db. Just used for mapping. - * May it will be helpfull for tracking ;) + * Not integrated in the db. Just used for mapping. + * May it will be helpfull for tracking ;). + * * @author kevinfrantz */ final class MenuEventType extends AbstractEnumType -{ +{ public const USER = 'app.menu.topbar.user'; - + public const SOURCE = 'app.menu.subbar.source'; public const NODE = 'app.menu.subbar.node'; - + /** - * May this will be used in the future + * May this will be used in the future. + * * @var array */ protected static $choices = []; diff --git a/application/src/Entity/AbstractEntity.php b/application/src/Entity/AbstractEntity.php index 9ce9dc8..7a5f7fd 100644 --- a/application/src/Entity/AbstractEntity.php +++ b/application/src/Entity/AbstractEntity.php @@ -1,4 +1,5 @@ version = $version; } - - public function getVersion():int{ + + public function getVersion(): int + { return $this->version; } } - diff --git a/application/src/Entity/Attribut/VersionAttributInterface.php b/application/src/Entity/Attribut/VersionAttributInterface.php index 764d232..4846cd4 100644 --- a/application/src/Entity/Attribut/VersionAttributInterface.php +++ b/application/src/Entity/Attribut/VersionAttributInterface.php @@ -1,24 +1,28 @@ groups; } - + /** - * * @param Collection|GroupSourceInterface[] $groups */ - public function setGroupSources(Collection $groups):void{ + public function setGroupSources(Collection $groups): void + { $this->groups = $groups; } } - diff --git a/application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php b/application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php index 0c40bf2..61ead32 100644 --- a/application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php +++ b/application/src/Entity/Source/Attribut/GroupSourcesAttributInterface.php @@ -1,24 +1,22 @@ members = $members; } } - diff --git a/application/src/Entity/Source/Attribut/MembersAttributInterface.php b/application/src/Entity/Source/Attribut/MembersAttributInterface.php index 6f2827c..6f1f5a3 100644 --- a/application/src/Entity/Source/Attribut/MembersAttributInterface.php +++ b/application/src/Entity/Source/Attribut/MembersAttributInterface.php @@ -1,17 +1,16 @@ members = new ArrayCollection(); } } - diff --git a/application/src/Entity/Source/GroupSourceInterface.php b/application/src/Entity/Source/GroupSourceInterface.php index b60d873..5e66a58 100644 --- a/application/src/Entity/Source/GroupSourceInterface.php +++ b/application/src/Entity/Source/GroupSourceInterface.php @@ -1,14 +1,14 @@ result = new Result(); - /** + /* * @var OperandInterface */ foreach ($this->operands->toArray() as $operand) { if (!$operand->getResult()->getBool()) { $this->result->setAll(false); + return; } } diff --git a/application/src/Entity/Source/SourceInterface.php b/application/src/Entity/Source/SourceInterface.php index 3008418..d72ae56 100644 --- a/application/src/Entity/Source/SourceInterface.php +++ b/application/src/Entity/Source/SourceInterface.php @@ -1,4 +1,5 @@ factory = $factory; $this->item = $item; $this->request = $request; } - + /** * @return FactoryInterface */ @@ -42,7 +41,7 @@ class MenuEvent extends Event { return $this->factory; } - + /** * @return ItemInterface */ @@ -50,7 +49,7 @@ class MenuEvent extends Event { return $this->item; } - + /** * @return RequestStack */ @@ -58,4 +57,4 @@ class MenuEvent extends Event { return $this->request; } -} \ No newline at end of file +} diff --git a/application/src/Menu/Menu.php b/application/src/Menu/Menu.php index ed46f6c..8ab5427 100644 --- a/application/src/Menu/Menu.php +++ b/application/src/Menu/Menu.php @@ -1,4 +1,5 @@ createBasicMenuItem(); $this->dispatcher->dispatch($type, new MenuEvent($this->factory, $menu, $request)); + return $menu; } @@ -55,8 +54,8 @@ class Menu { return $this->factory->createItem('root', [ 'childrenAttributes' => [ - 'class' => 'navbar-nav mr-auto' - ] + 'class' => 'navbar-nav mr-auto', + ], ]); } } diff --git a/application/src/Repository/LawRepository.php b/application/src/Repository/LawRepository.php index 58e5f45..9638fe4 100644 --- a/application/src/Repository/LawRepository.php +++ b/application/src/Repository/LawRepository.php @@ -1,14 +1,12 @@ checkInstance($subject) && $this->checkRight($attribute); + return $this->checkInstance($subject) && $this->checkRight($attribute); } - + //private function checkLayer(string $layer):bool{ // return (in_array($right, array_keys(LayerType::getChoices()))); //} - - private function checkRight(string $right):bool{ - return (in_array($right, array_keys(RightType::getChoices()))); + + private function checkRight(string $right): bool + { + return in_array($right, array_keys(RightType::getChoices())); } - - private function checkInstance($subject):bool{ - return ($subject instanceof SourceInterface); + + private function checkInstance($subject): bool + { + return $subject instanceof SourceInterface; } /** * @todo add if father, that it should have all rights! - * @param string[] $attribute + * + * @param string[] $attribute * @param SourceInterface $subject - * @param TokenInterface $token - * {@inheritdoc} + * @param TokenInterface $token + * {@inheritdoc} + * * @see \Symfony\Component\Security\Core\Authorization\Voter\Voter::voteOnAttribute() */ protected function voteOnAttribute($attribute, $subject, TokenInterface $token) { /** - * @var UserInterface $user + * @var UserInterface */ $user = $token->getUser(); + return $subject->getNode() ->getLaw() ->isGranted($user->getSource()->getNode(), LayerType::SOURCE, $attribute); } } - diff --git a/application/src/Structur/Facade/Security/Source/AbstractSourceFacade.php b/application/src/Structur/Facade/Security/Source/AbstractSourceFacade.php index 1e3fd5f..0aaf675 100644 --- a/application/src/Structur/Facade/Security/Source/AbstractSourceFacade.php +++ b/application/src/Structur/Facade/Security/Source/AbstractSourceFacade.php @@ -7,7 +7,6 @@ use App\Entity\Source\SourceInterface; use App\Entity\User; use App\DBAL\Types\RightType; use App\DBAL\Types\LayerType; -use App\Structur\Facade\Security\Source\SourceFacadeInterface; /** * @author kevinfrantz @@ -15,7 +14,8 @@ use App\Structur\Facade\Security\Source\SourceFacadeInterface; abstract class AbstractSourceFacade implements SourceFacadeInterface { /** - * Propably it woul be better to solve this over the constructor + * Propably it woul be better to solve this over the constructor. + * * @var User */ protected static $facadeUser; diff --git a/application/src/Structur/Facade/Security/Source/SourceFacadeInterface.php b/application/src/Structur/Facade/Security/Source/SourceFacadeInterface.php index 31d4713..5fff407 100644 --- a/application/src/Structur/Facade/Security/Source/SourceFacadeInterface.php +++ b/application/src/Structur/Facade/Security/Source/SourceFacadeInterface.php @@ -1,10 +1,10 @@ translator = $translator; } - protected function generateShowDropdown(ItemInterface $menu, Event $event,string $route): void + protected function generateShowDropdown(ItemInterface $menu, Event $event, string $route): void { $dropdown = $menu->addChild($this->trans('show'), [ 'attributes' => [ 'icon' => 'fas fa-eye', - 'dropdown' => 'true' - ] + 'dropdown' => 'true', + ], ]); foreach (self::FORMAT_TYPES as $format) { $dropdown->addChild($format, [ 'route' => $route, 'routeParameters' => [ 'id' => $this->getRequestId($event), - '_format' => $format + '_format' => $format, ], 'attributes' => [ 'icon' => 'fas fa-sign-out-alt', - 'divider_append' => true - ] + 'divider_append' => true, + ], ]); } $dropdown->addChild($this->trans('standard'), [ 'route' => $route, 'routeParameters' => [ - 'id' => $this->getRequestId($event) + 'id' => $this->getRequestId($event), ], 'attributes' => [ - 'icon' => 'fas fa-sign-out-alt' - ] + 'icon' => 'fas fa-sign-out-alt', + ], ]); } - - protected function trans(string $id, array $parameter=[]):string{ - return $this->translator->trans($id,$parameter); + + protected function trans(string $id, array $parameter = []): string + { + return $this->translator->trans($id, $parameter); } protected function getRequestId(Event $event): int @@ -70,4 +70,3 @@ abstract class AbstractEntityMenuSubscriber implements EventSubscriberInterface return $event->getRequest()->getCurrentRequest()->attributes->get('id'); } } - diff --git a/application/src/Subscriber/NodeMenuSubscriber.php b/application/src/Subscriber/NodeMenuSubscriber.php index d24c893..204b930 100644 --- a/application/src/Subscriber/NodeMenuSubscriber.php +++ b/application/src/Subscriber/NodeMenuSubscriber.php @@ -1,20 +1,19 @@ getItem(); - $this->generateShowDropdown($menu, $event,'app_source_show'); + $this->generateShowDropdown($menu, $event, 'app_source_show'); $menu->addChild($this->trans('law'), [ 'route' => 'app_node_law', 'routeParameters' => [ @@ -43,12 +42,11 @@ class NodeMenuSubscriber extends AbstractEntityMenuSubscriber ], ]); } - + public static function getSubscribedEvents() { return [ - MenuEventType::NODE => 'onNodeMenuConfigure' + MenuEventType::NODE => 'onNodeMenuConfigure', ]; } } - diff --git a/application/src/Subscriber/SourceMenuSubscriber.php b/application/src/Subscriber/SourceMenuSubscriber.php index 968ee08..810d3e6 100644 --- a/application/src/Subscriber/SourceMenuSubscriber.php +++ b/application/src/Subscriber/SourceMenuSubscriber.php @@ -19,7 +19,7 @@ class SourceMenuSubscriber extends AbstractEntityMenuSubscriber 'icon' => 'fas fa-edit', ], ]); - $this->generateShowDropdown($menu, $event,'app_source_show'); + $this->generateShowDropdown($menu, $event, 'app_source_show'); $menu->addChild($this->trans('node'), [ 'route' => 'app_source_node', 'routeParameters' => [ diff --git a/application/src/Subscriber/UserMenuSubscriber.php b/application/src/Subscriber/UserMenuSubscriber.php index ac475f1..3c87f03 100644 --- a/application/src/Subscriber/UserMenuSubscriber.php +++ b/application/src/Subscriber/UserMenuSubscriber.php @@ -90,7 +90,7 @@ class UserMenuSubscriber implements EventSubscriberInterface public static function getSubscribedEvents(): array { return [ - MenuEventType::USER=> 'onUserMenuConfigure', + MenuEventType::USER => 'onUserMenuConfigure', ]; } } diff --git a/application/tests/unit/Entity/Source/AbstractSourceTest.php b/application/tests/unit/Entity/Source/AbstractSourceTest.php index 06f5135..0ef3f58 100644 --- a/application/tests/unit/Entity/Source/AbstractSourceTest.php +++ b/application/tests/unit/Entity/Source/AbstractSourceTest.php @@ -1,4 +1,5 @@ source = new class extends \App\Entity\Source\AbstractSource{}; + + public function setUp() + { + $this->source = new class() extends \App\Entity\Source\AbstractSource { + }; $this->source->setId(self::ID); } - - public function testId(){ - $this->assertEquals($this->source->getId(),self::ID); + + public function testId() + { + $this->assertEquals($this->source->getId(), self::ID); } - - public function testLaw(){ - $this->assertInstanceOf(LawInterface::class,$this->source->getLaw()); + + public function testLaw() + { + $this->assertInstanceOf(LawInterface::class, $this->source->getLaw()); } - - public function testRelation(){ - $this->assertInstanceOf(RelationInterface::class,$this->source->getRelation()); + + public function testRelation() + { + $this->assertInstanceOf(RelationInterface::class, $this->source->getRelation()); } - - public function testGroups(){ - $this->assertInstanceOf(Collection::class,$this->source->getGroupSources()); - $group = new class extends AbstractSource{}; + + public function testGroups() + { + $this->assertInstanceOf(Collection::class, $this->source->getGroupSources()); + $group = new class() extends AbstractSource { + }; $groups = new ArrayCollection([$group]); $this->source->setGroupSources($groups); $this->assertEquals($group, $this->source->getGroupSources()->get(0)); } } - diff --git a/application/tests/unit/Entity/Source/GroupSourceTest.php b/application/tests/unit/Entity/Source/GroupSourceTest.php index 0c695e1..d78fa29 100644 --- a/application/tests/unit/Entity/Source/GroupSourceTest.php +++ b/application/tests/unit/Entity/Source/GroupSourceTest.php @@ -1,4 +1,5 @@ groupSource = new GroupSource(); } - - public function testMembers(){ + + public function testMembers() + { $this->assertInstanceOf(Collection::class, $this->groupSource->getMembers()); - $member = new class extends AbstractSource{}; + $member = new class() extends AbstractSource { + }; $this->groupSource->setMembers(new ArrayCollection([$member])); $this->assertEquals($member, $this->groupSource->getMembers()->get(0)); } } - diff --git a/application/tests/unit/Entity/Source/NameSourceTest.php b/application/tests/unit/Entity/Source/NameSourceTest.php index a7d3305..9f882c7 100644 --- a/application/tests/unit/Entity/Source/NameSourceTest.php +++ b/application/tests/unit/Entity/Source/NameSourceTest.php @@ -1,4 +1,5 @@ nameSource = new NameSource(); } - - public function testName():void{ + + public function testName(): void + { $this->assertEquals('', $this->nameSource->getName()); $name = 'Hello World!'; $this->nameSource->setName($name); $this->assertEquals($name, $this->nameSource->getName()); } } - diff --git a/application/tests/unit/Entity/UserTest.php b/application/tests/unit/Entity/UserTest.php index 71fc3d1..7086725 100644 --- a/application/tests/unit/Entity/UserTest.php +++ b/application/tests/unit/Entity/UserTest.php @@ -27,10 +27,10 @@ class UserTest extends TestCase $this->user = new User(); $this->user->setUsername(self::USERNAME); $this->user->setPassword(self::PASSWORD); - } - - public function testConstructor():void{ + + public function testConstructor(): void + { $this->assertInstanceOf(UserInterface::class, new User()); }