Conditions | 6 |
Paths | 6 |
Total Lines | 53 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
51 | public function createNewPost() |
||
52 | { |
||
53 | //Security checks |
||
54 | $this->onlyAdmin(); |
||
55 | if (!$this->request->isPost()) { |
||
56 | $this->alertBox->setAlert('Only post messages allowed', 'error'); |
||
57 | $this->response->redirect('admin'); |
||
58 | } |
||
59 | $posts = $this->container->getRequest()->getDataFull(); |
||
60 | $userSessionid = $this->container->getSession()->get("user_id"); |
||
61 | |||
62 | //TODO |
||
63 | //Slug, check if duplicate |
||
64 | //Tags, check if duplicate before creating new tag |
||
65 | //Tags, must have created the post and got the id before associating the tags |
||
66 | //grab author from session |
||
67 | |||
68 | $title = $posts["newPostTitle"]; |
||
69 | $postImage = $posts["newPostImage"]; //TODO Sanatize the input ? Or will PDO be enough ? |
||
70 | $postSlug = $posts["newPostSlug"]; //TODO Check if unique |
||
71 | $article = $posts["newPostTextArea"]; |
||
72 | $idCategory = $posts["categorySelector"]; |
||
73 | $published = $posts["isPublished"]; |
||
74 | $onFrontpage = $posts["isOnFrontPage"]; |
||
75 | $idUser = $userSessionid; |
||
76 | |||
77 | $slugModel = new SlugModel($this->container); |
||
78 | $tagModel = new TagsModel($this->container); |
||
79 | $postModel = new PostModel($this->container); |
||
80 | |||
81 | //security and error checks |
||
82 | if (!$slugModel->isUnique($postSlug, "posts", "posts_slug")) { |
||
83 | die("SLUG not unique"); |
||
1 ignored issue
–
show
|
|||
84 | } |
||
85 | |||
86 | $postId = $postModel->newPost($title, $postImage, $idCategory, $article, $idUser, $published, $onFrontpage, $postSlug); |
||
87 | |||
88 | echo "<p>new post ID : " . $postId . "</p>"; |
||
89 | |||
90 | if(isset($posts["tags"])){ |
||
91 | foreach ($posts["tags"] as $tag) { |
||
92 | if(isset($tag["id"])){ |
||
93 | $tagModel->addTagToPost($postId, $tag["id"]); |
||
94 | continue; |
||
95 | } |
||
96 | $tagModel->addNewTagToPost($postId, $tag["name"]); |
||
97 | } |
||
98 | } |
||
99 | |||
100 | |||
101 | echo "<pre>"; |
||
102 | var_dump($posts); |
||
103 | die(); |
||
1 ignored issue
–
show
|
|||
104 | |||
109 | } |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.