Passed
Push — Showing-Posts ( 21612a...6a22d0 )
by Stone
08:05
created

Post::createNewPost()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 8
nc 2
nop 0
dl 0
loc 19
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controllers\Admin;
4
5
use App\Models\CategoryModel;
6
use App\Models\TagsModel;
7
use Core\AdminController;
8
9
class Post extends AdminController
10
{
11
12
    /**
13
     * page for new post
14
     */
15
    public function new()
16
    {
17
        $this->onlyAdmin();
18
        $categoryModel = new CategoryModel($this->container);
19
        $tagModel = new TagsModel($this->container);
20
        $this->data['categories'] = $categoryModel->getCategories();
21
        $this->data['tags'] = $tagModel->getTags();
22
        $this->renderView('Admin/NewPost');
23
    }
24
25
    /**
26
     * Lists all the posts
27
     */
28
    public function list()
29
    {
30
        $this->onlyAdmin();
31
32
    }
33
34
    /**
35
     * Shows the post to modify and update
36
     * @param $idPost
37
     */
38
    public function modify($idPost)
0 ignored issues
show
Unused Code introduced by
The parameter $idPost is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

38
    public function modify(/** @scrutinizer ignore-unused */ $idPost)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
        $this->onlyAdmin();
41
42
    }
43
44
    public function createNewPost()
45
    {
46
        //Security checks
47
        $this->onlyAdmin();
48
        if (!$this->request->isPost()) {
49
            $this->alertBox->setAlert('Only post messages allowed', 'error');
50
            $this->response->redirect('admin');
51
        }
52
        $posts = $this->container->getRequest()->getDataFull();
53
54
        //TODO
55
        //Slug, check if duplicate
56
        //Tags, check if duplicate before creating new tag
57
        //Tags, must have created the post and got the id before associating the tags
58
        //grab author from session
59
60
        echo "<pre>";
61
        var_dump($posts);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($posts) looks like debug code. Are you sure you do not want to remove it?
Loading history...
62
        die();
1 ignored issue
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
63
    }
64
}