Passed
Push — Showing-Posts ( a72031...c030ab )
by Stone
02:07
created

postModification::modifyOnFrontPage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 9
nc 2
nop 0
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace App\Controllers\Ajax;
4
5
use App\Models\PostModel;
6
use Core\AjaxController;
7
use Core\Container;
8
9
class postModification extends AjaxController{
10
11
12
    private $postModule;
13
14
    public function __construct(Container $container)
15
    {
16
        parent::__construct($container);
17
        $this->postModule = new PostModel($this->container);
18
    }
19
20
    public function modifyPublished()
21
    {
22
        $this->onlyAdmin();
23
        if (!$this->container->getRequest()->isPost()) {
24
            throw new \Core\JsonException('Call is not post');
25
        }
26
        $state = (bool)($this->request->getData("state") === 'true');
27
        $postId = (int)$this->request->getData("postId");
28
29
        $result["success"] = $this->postModule->setPublished(!$state, $postId);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.
Loading history...
30
        $result["state"] = !$state;
31
        $result["postId"] = $postId;
32
        echo json_encode($result);
33
    }
34
35
    public function modifyOnFrontPage()
36
    {
37
        $this->onlyAdmin();
38
        if (!$this->container->getRequest()->isPost()) {
39
            throw new \Core\JsonException('Call is not post');
40
        }
41
        $state = ($this->request->getData("state") === 'true');
42
        $postId = (int)$this->request->getData("postId");
43
44
        $result["success"] = $this->postModule->setOnFrontPage(!$state, $postId);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$result was never initialized. Although not strictly required by PHP, it is generally a good practice to add $result = array(); before regardless.
Loading history...
45
        $result["state"] = !$state;
46
        $result["postId"] = $postId;
47
        echo json_encode($result);
48
    }
49
}