Passed
Push — Showing-Posts ( 9bf220...f78be0 )
by Stone
01:51
created

Tag   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 22 3
A update() 0 22 3
1
<?php
2
3
namespace App\Controllers\Ajax;
4
5
use App\Models\TagModel;
6
use Core\AjaxController;
7
8
class Tag extends AjaxController{
9
10
11
    /**
12
     * Update the tag via ajax
13
     * @throws \Core\JsonException
14
     */
15
    public function update()
16
    {
17
        //security checks
18
        $this->onlyAdmin();
19
        if (!$this->request->isPost()) {
20
            throw new JsonException('Call is not post');
0 ignored issues
show
Bug introduced by
The type App\Controllers\Ajax\JsonException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
        }
22
23
        //prepating our return results
24
        $result = array();
25
        $tagUpdateJson = ($this->request->getData('tag-update'));
26
        $tagUpdate = json_decode($tagUpdateJson);
27
28
        //Converting our array of objects to simple array
29
        $send = array();
30
        foreach ($tagUpdate as $item) {
31
            $send[$item->name] = $item->value;
32
        }
33
34
        $tagModel = new TagModel($this->container);
35
        $result['success'] = $tagModel->update($send["idtags"], $send["tag_name"]);
36
        echo json_encode($result);
37
    }
38
39
    /**
40
     * Delete a tag via Ajax
41
     * @throws \Core\JsonException
42
     */
43
    public function delete()
44
    {
45
        //security checks
46
        $this->onlyAdmin();
47
        if (!$this->request->isPost()) {
48
            throw new JsonException('Call is not post');
49
        }
50
51
        //prepating our return results
52
        $result = array();
53
        $DeleteJson = ($this->request->getData('tag-delete'));
54
        $Delete = json_decode($DeleteJson);
55
56
        //Converting our array of objects to simple array
57
        $send = array();
58
        foreach ($Delete as $item) {
59
            $send[$item->name] = $item->value;
60
        }
61
62
        $tagModel = new TagModel($this->container);
63
        $result['success'] = $tagModel->delete($send["idtags"]);
64
        echo json_encode($result);
65
    }
66
}