Passed
Pull Request — master (#55)
by Stone
04:19
created

AjaxSlugify   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A slugifyString() 0 12 2
1
<?php
2
3
namespace App\Controllers\Ajax;
4
5
use Core\AjaxController;
6
use Cocur\Slugify\Slugify;
7
use Core\JsonException;
8
use Core\Traits\StringFunctions;
9
10
class AjaxSlugify extends AjaxController
11
{
12
    use StringFunctions;
0 ignored issues
show
Bug introduced by
The trait Core\Traits\StringFunctions requires the property $childNodes which is not provided by App\Controllers\Ajax\AjaxSlugify.
Loading history...
13
14
    /**
15
     * @return string slugified string
16
     * @throws JsonException
17
     */
18
    public function slugifyString()
19
    {
20
        //only admins can update the slug
21
        $this->onlyAdmin();
22
        if (!$this->container->getRequest()->isPost()) {
23
            throw new JsonException('Call is not post');
24
        }
25
        $slug = $this->request->getData("slugText-update");
26
        $result = array();
27
        $slugify = new Slugify();
28
        $result['slug'] = $slugify->slugify($slug);
29
        echo json_encode($result);
30
    }
31
}