AttachFileAdminController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 0
cbo 3
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fileDeleteAction() 0 16 3
1
<?php
2
3
namespace ItBlaster\AttachFileBundle\Controller;
4
5
6
use ItBlaster\AttachFileBundle\Model\AttachFileQuery;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * Class AttachFileAdminController
13
 * @package ItBlaster\AttachFileBundle\Controller
14
 */
15
class AttachFileAdminController extends Controller
16
{
17
    /**
18
     * Удаление файла
19
     *
20
     * @param Request $request
21
     * @return \Symfony\Component\HttpFoundation\Response
22
     */
23
    public function fileDeleteAction(Request $request)
24
    {
25
        if (!$this->get('security.context')->isGranted('ROLE_SUPER_ADMIN')) {
26
            throw new \Exception('Access denied');
27
        }
28
29
        $id = $request->get('attach_file');
30
        $attach_file = AttachFileQuery::create()->findOneById($id);
31
32
        $success = $attach_file ? $attach_file->deleteFile() : false;
33
34
        $response = new JsonResponse(array(
35
            'success'   =>  $success,
36
        ));
37
        return $response;
38
    }
39
}