From 1492282ae5d6bbd11efb6ab5ef7fa8394e7bd35b Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 15 Jul 2018 16:41:56 +0200 Subject: [PATCH] Cleanup --- src/controller/AbstractController.php | 32 ++++++++++------- src/controller/AbstractDefaultController.php | 26 +++++++------- src/controller/order/Order.php | 8 ++--- src/controller/product/Product.php | 9 +++-- src/controller/standart/Standart.php | 4 ++- src/controller/standart/StandartInterface.php | 3 +- src/controller/user/User.php | 3 +- src/core/Core.php | 2 +- src/core/CoreInterface.php | 19 +++++----- src/core/CoreTest.php | 35 +++++++++++-------- src/entity/payment/method1/Method1Test.php | 4 ++- .../frames/structure/navbar.html.twig | 5 +-- src/template/order/basket.html.twig | 5 ++- src/template/product/list.html.twig | 4 +-- src/template/standart/homepage.html.twig | 4 ++- src/template/user/login.html.twig | 24 +++++++------ src/template/user/register.html.twig | 33 +++++++++-------- 17 files changed, 129 insertions(+), 91 deletions(-) diff --git a/src/controller/AbstractController.php b/src/controller/AbstractController.php index e443807..7bc5404 100644 --- a/src/controller/AbstractController.php +++ b/src/controller/AbstractController.php @@ -11,35 +11,41 @@ use router\Router; */ abstract class AbstractController { + /** + * * @var CoreInterface */ protected $core; - + /** - * + * * @var array */ protected $post; - - public function __construct(CoreInterface $core){ - $this->core = $core; + + public function __construct(CoreInterface $core) + { + $this->core = $core; $this->post = $_POST; } - - protected function render(string $template,array $variables=[]):void{ - echo $this->core->getTwig()->render($template,$this->addUser($variables)); + + protected function render(string $template, array $variables = []): void + { + echo $this->core->getTwig()->render($template, $this->addUser($variables)); } - - private function addUser(array $variables):array{ - if(array_key_exists('user', $variables)){ + + private function addUser(array $variables): array + { + if (array_key_exists('user', $variables)) { throw new \Exception('Key user isn\'t allowed!'); } $variables['user'] = $this->core->getUser(); return $variables; } - - protected function route(?array $get =[]):void{ + + protected function route(?array $get = []): void + { $router = new Router(); $router->setCore($this->core); $router->setGet($get); diff --git a/src/controller/AbstractDefaultController.php b/src/controller/AbstractDefaultController.php index 73d3c75..6b1c4f3 100644 --- a/src/controller/AbstractDefaultController.php +++ b/src/controller/AbstractDefaultController.php @@ -22,8 +22,8 @@ class AbstractDefaultController extends AbstractController private function addMenuItems(array $variables): array { if (array_key_exists('menu_items', $variables)) { - $variables['menu_items'] = array_merge($this->getMenuItems(),$variables['menu_items']); - }else{ + $variables['menu_items'] = array_merge($this->getMenuItems(), $variables['menu_items']); + } else { $variables['menu_items'] = $this->getMenuItems(); } return $variables; @@ -54,16 +54,18 @@ class AbstractDefaultController extends AbstractController ], 'logout') ]; } - return [new LinkCollection('login',[ - new Link([ - Router::CONTROLLER => 'user', - Router::ACTION => 'login' - ], 'login'), - new Link([ - Router::CONTROLLER => 'user', - Router::ACTION => 'register' - ], 'register') - ])]; + return [ + new LinkCollection('login', [ + new Link([ + Router::CONTROLLER => 'user', + Router::ACTION => 'login' + ], 'login'), + new Link([ + Router::CONTROLLER => 'user', + Router::ACTION => 'register' + ], 'register') + ]) + ]; } } diff --git a/src/controller/order/Order.php b/src/controller/order/Order.php index 683fd94..f15936d 100644 --- a/src/controller/order/Order.php +++ b/src/controller/order/Order.php @@ -45,9 +45,9 @@ final class Order extends AbstractDefaultController implements OrderInterface private function store(): void { $this->core->getBasket()->setCustomer($this->core->getUser()); - if($this->orderRepository->saveOrder($this->core->getBasket())){ + if ($this->orderRepository->saveOrder($this->core->getBasket())) { $this->core->setBasket(new OrderEntity()); - }else{ + } else { throw new \Exception('Order could not be saved!'); } } @@ -59,7 +59,7 @@ final class Order extends AbstractDefaultController implements OrderInterface } $this->render('order/basket.html.twig', [ 'basket' => $this->core->getBasket(), - 'payment_methods'=>AbstractPayment::getPaymentMethods(), + 'payment_methods' => AbstractPayment::getPaymentMethods() ]); } @@ -68,7 +68,7 @@ final class Order extends AbstractDefaultController implements OrderInterface if ($this->post['add']) { $this->addProduct(); } - if ($this->post['store']){ + if ($this->post['store']) { $this->store(); } } diff --git a/src/controller/product/Product.php b/src/controller/product/Product.php index aad5079..45c2487 100644 --- a/src/controller/product/Product.php +++ b/src/controller/product/Product.php @@ -37,9 +37,14 @@ final class Product extends AbstractDefaultController implements ProductInterfac } $this->render('product/list.html.twig', [ 'products' => $products, - 'add_to_basket'=> new Link(['controller'=>'order','action'=>'basket']), + 'add_to_basket' => new Link([ + 'controller' => 'order', + 'action' => 'basket' + ]), 'colors' => $this->getColors(), - 'menu_items'=>[$this->getColors()] + 'menu_items' => [ + $this->getColors() + ] ]); } diff --git a/src/controller/standart/Standart.php b/src/controller/standart/Standart.php index 5e2dc63..21a1ef5 100644 --- a/src/controller/standart/Standart.php +++ b/src/controller/standart/Standart.php @@ -10,7 +10,9 @@ use controller\AbstractDefaultController; */ final class Standart extends AbstractDefaultController implements StandartInterface { - public function homepage():void{ + + public function homepage(): void + { $this->render('standart/homepage.html.twig'); } } diff --git a/src/controller/standart/StandartInterface.php b/src/controller/standart/StandartInterface.php index 9681e2a..d17fa07 100644 --- a/src/controller/standart/StandartInterface.php +++ b/src/controller/standart/StandartInterface.php @@ -8,6 +8,7 @@ namespace controller\standart; */ interface StandartInterface { - public function homepage():void; + + public function homepage(): void; } diff --git a/src/controller/user/User.php b/src/controller/user/User.php index 1f13fc0..0420352 100644 --- a/src/controller/user/User.php +++ b/src/controller/user/User.php @@ -13,6 +13,7 @@ use entity\user\User as UserEntity; */ final class User extends AbstractDefaultController implements UserInterface { + /** * * @var UserRepository @@ -68,7 +69,7 @@ final class User extends AbstractDefaultController implements UserInterface $this->route(); } - private function validateRegistrationData():bool + private function validateRegistrationData(): bool { if (! filter_var($this->post['email'], FILTER_VALIDATE_EMAIL)) { throw new \Exception('Not a valid email!'); diff --git a/src/core/Core.php b/src/core/Core.php index 16dfa21..0bc159a 100644 --- a/src/core/Core.php +++ b/src/core/Core.php @@ -64,7 +64,7 @@ final class Core implements CoreInterface private function initSession(): void { - if (!headers_sent()) { + if (! headers_sent()) { session_start(); } } diff --git a/src/core/CoreInterface.php b/src/core/CoreInterface.php index 3ce8b82..9a1e621 100644 --- a/src/core/CoreInterface.php +++ b/src/core/CoreInterface.php @@ -7,19 +7,20 @@ use entity\order\Order; /** * * @author kevinfrantz - * + * */ interface CoreInterface { - public function getDatabase():\PDO; - public function getTwig():\Twig_Environment; + public function getDatabase(): \PDO; - public function getUser():?UserInterface; + public function getTwig(): \Twig_Environment; - public function setUser(?UserInterface $user = null):void; - - public function getBasket():Order; - - public function setBasket(Order $basket):void; + public function getUser(): ?UserInterface; + + public function setUser(?UserInterface $user = null): void; + + public function getBasket(): Order; + + public function setBasket(Order $basket): void; } diff --git a/src/core/CoreTest.php b/src/core/CoreTest.php index de0275d..95d2c3f 100644 --- a/src/core/CoreTest.php +++ b/src/core/CoreTest.php @@ -11,19 +11,21 @@ use entity\user\User; */ class CoreTest extends TestCase { + /** - * + * * @var Core */ protected $core; - + /** - * + * * @var User */ protected $user; - - protected function setUp():void{ + + protected function setUp(): void + { $this->core = new Core(); $this->user = new User(); $this->user->setId(1); @@ -31,21 +33,26 @@ class CoreTest extends TestCase $this->user->setPasswordHashByPassword('passwort:)'); $this->core->setUser($this->user); } - - public function testTwig():void{ + + public function testTwig(): void + { $this->assertInstanceOf(\Twig_Environment::class, $this->core->getTwig()); } - - public function testDatabase():void{ + + public function testDatabase(): void + { $this->assertInstanceOf(\PDO::class, $this->core->getDatabase()); } - - public function testUser():void{ + + public function testUser(): void + { $this->assertEquals($this->user, $this->core->getUser()); } - - public function testSession():void{ - $this->assertEquals($this->core->getUser()->getPasswordHash(), $_SESSION['user']->getPasswordHash()); + + public function testSession(): void + { + $this->assertEquals($this->core->getUser() + ->getPasswordHash(), $_SESSION['user']->getPasswordHash()); } } diff --git a/src/entity/payment/method1/Method1Test.php b/src/entity/payment/method1/Method1Test.php index 9886810..846f837 100644 --- a/src/entity/payment/method1/Method1Test.php +++ b/src/entity/payment/method1/Method1Test.php @@ -1,12 +1,14 @@ assertEquals(Method1::getName(), 'method1'); diff --git a/src/template/frames/structure/navbar.html.twig b/src/template/frames/structure/navbar.html.twig index 6bbe9e1..9cc1b13 100644 --- a/src/template/frames/structure/navbar.html.twig +++ b/src/template/frames/structure/navbar.html.twig @@ -22,12 +22,13 @@ {% endif %} {% endif %} - {% endfor %} diff --git a/src/template/order/basket.html.twig b/src/template/order/basket.html.twig index 4a04838..23a87d7 100644 --- a/src/template/order/basket.html.twig +++ b/src/template/order/basket.html.twig @@ -28,8 +28,7 @@ basket {% for key,payment in payment_methods %} {% endfor %} - - - + {% endblock %} \ No newline at end of file diff --git a/src/template/product/list.html.twig b/src/template/product/list.html.twig index faf7208..4ea4e0c 100644 --- a/src/template/product/list.html.twig +++ b/src/template/product/list.html.twig @@ -23,8 +23,8 @@ product overview
- - +
diff --git a/src/template/standart/homepage.html.twig b/src/template/standart/homepage.html.twig index dca58c6..374a89f 100644 --- a/src/template/standart/homepage.html.twig +++ b/src/template/standart/homepage.html.twig @@ -1,5 +1,7 @@ {% extends "frames/default.html.twig" %} -{% block title %}Homepage{% endblock %} +{% block title %} +Homepage +{% endblock %} {% block content %}

Welcome to the online shop!

diff --git a/src/template/user/login.html.twig b/src/template/user/login.html.twig index e68ff8f..6fad0ce 100644 --- a/src/template/user/login.html.twig +++ b/src/template/user/login.html.twig @@ -1,16 +1,20 @@ {% extends "frames/default.html.twig" %} -{% block title %}login{% endblock %} +{% block title %} +login +{% endblock %} {% block content %}

Login

-
- - -
-
- - -
- +
+ +
+
+ +
+
{% endblock %} diff --git a/src/template/user/register.html.twig b/src/template/user/register.html.twig index 2a7f0d5..34ab93c 100644 --- a/src/template/user/register.html.twig +++ b/src/template/user/register.html.twig @@ -1,20 +1,25 @@ {% extends "frames/default.html.twig" %} -{% block title %}register{% endblock %} +{% block title %} +register +{% endblock %} {% block content %}

Register

-
- - -
-
- - -
-
- - -
- +
+ +
+
+ +
+
+ +
+
{% endblock %}