Passed
Pull Request — Comments (#65)
by Stone
05:43 queued 02:26
created

AjaxSlugify::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
use Core\Container;
10
11
class AjaxSlugify extends AjaxController
12
{
13
    use StringFunctions;
14
15
    private $slugify;
16
17
    public function __construct(Container $container)
18
    {
19
        parent::__construct($container);
20
        $this->slugify = new Slugify();
21
    }
22
23
    /**
24
     * @return string slugified string
25
     * @throws JsonException
26
     */
27
    public function slugifyString()
28
    {
29
        //only admins can update the slug
30
        $this->onlyAdmin();
31
        $this->onlyPost();
32
        $slug = $this->request->getData("slugText-update");
33
        $result = array();
34
        $result['slug'] = $this->slugify->slugify($slug);
35
        echo json_encode($result);
36
    }
37
}