From 9159648dc29e408237b7447a70aa1635b15ef339 Mon Sep 17 00:00:00 2001 From: danchukas Date: Thu, 18 Jul 2019 14:29:07 +0300 Subject: [PATCH] Update PostController.php bit clear code --- Controller/PostController.php | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/Controller/PostController.php b/Controller/PostController.php index fba49b8..089d659 100644 --- a/Controller/PostController.php +++ b/Controller/PostController.php @@ -16,15 +16,6 @@ class PostController extends AbstractController { - private function _getRequestArrayWithDisqusShortname($array) - { - $config = $this->container->getParameter('stfalcon_blog.config'); - return array_merge( - $array, - array('disqus_shortname' => $config['disqus_shortname']) - ); - } - /** * List of posts for admin * @@ -37,7 +28,7 @@ private function _getRequestArrayWithDisqusShortname($array) * * @return array */ - public function indexAction($page) + public function indexAction(int $page): array { $allPosts = $this->get('doctrine')->getEntityManager() ->getRepository("StfalconBlogBundle:Post")->getAllPosts(); @@ -48,9 +39,9 @@ public function indexAction($page) $breadcrumbs->addChild('Блог')->setCurrent(true); } - return $this->_getRequestArrayWithDisqusShortname(array( + return $this->_getRequestDataWithDisqusShortname([ 'posts' => $posts - )); + ]); } /** @@ -63,7 +54,7 @@ public function indexAction($page) * * @return array */ - public function viewAction(Post $post) + public function viewAction(Post $post): array { if ($this->has('application_default.menu.breadcrumbs')) { $breadcrumbs = $this->get('application_default.menu.breadcrumbs'); @@ -71,9 +62,9 @@ public function viewAction(Post $post) $breadcrumbs->addChild($post->getTitle())->setCurrent(true); } - return $this->_getRequestArrayWithDisqusShortname(array( + return $this->_getRequestDataWithDisqusShortname([ 'post' => $post - )); + ]); } /** @@ -91,14 +82,14 @@ public function rssAction() $feed->setTitle($config['rss']['title']); $feed->setDescription($config['rss']['description']); - $feed->setLink($this->generateUrl('blog_rss', array(), true)); + $feed->setLink($this->generateUrl('blog_rss', [], true)); $posts = $this->get('doctrine')->getEntityManager() ->getRepository("StfalconBlogBundle:Post")->getAllPosts(); foreach ($posts as $post) { $entry = new \Zend\Feed\Writer\Entry(); $entry->setTitle($post->getTitle()); - $entry->setLink($this->generateUrl('blog_post_view', array('slug' => $post->getSlug()), true)); + $entry->setLink($this->generateUrl('blog_post_view', ['slug' => $post->getSlug()], true)); $feed->addEntry($entry); } @@ -115,11 +106,11 @@ public function rssAction() * * @return array() */ - public function lastAction($count = 1) + public function lastAction(int $count = 1): array { $posts = $this->get('doctrine')->getEntityManager() ->getRepository("StfalconBlogBundle:Post")->getLastPosts($count); - return array('posts' => $posts); + return ['posts' => $posts]; } -} \ No newline at end of file +}