Completed
Pull Request — master (#89)
by
unknown
452:27 queued 387:21
created

ApiController::checkAction()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 14
cp 0
rs 8.8571
cc 5
eloc 9
nc 3
nop 1
crap 30

1 Method

Rating   Name   Duplication   Size   Complexity  
A ApiController::historyAction() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\TranslationsBundle\Controller;
13
14
use ONGR\TranslationsBundle\Service\TranslationChecker;
15
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
16
use Symfony\Component\Console\Input\ArrayInput;
17
use Symfony\Component\Console\Output\NullOutput;
18
use Symfony\Component\HttpFoundation\JsonResponse;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
22
23
/**
24
 * Controller used for api's actions.
25
 */
26
class ApiController extends Controller
27
{
28
    /**
29
     * Action for editing translation objects.
30
     *
31
     * @param Request $request Http request object.
32
     * @param string  $id
33
     *
34
     * @return JsonResponse
35
     */
36
    public function editAction(Request $request, $id)
37
    {
38
        $response = ['error' => false];
39
40
        try {
41
            $this->get('ongr_translations.translation_manager')->edit($id, $request);
42
        } catch (\LogicException $e) {
43
            $response = ['error' => true];
44
        }
45
46
        return new JsonResponse($response);
47
    }
48
49
    /**
50
     * Action for getting translation.
51
     *
52
     * @param Request $request Http request object.
53
     * @param string  $id
54
     *
55
     * @return JsonResponse
56
     */
57
    public function getAction(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
58
    {
59
        return new JsonResponse($this->get('ongr_translations.translation_manager')->getTranslation($id));
60
    }
61
62
    /**
63
     * Action for executing export command.
64
     *
65
     * @return JsonResponse
66
     */
67
    public function exportAction()
68
    {
69
        $cwd = getcwd();
70
        if (substr($cwd, -3) === 'web') {
71
            chdir($cwd . DIRECTORY_SEPARATOR . '..');
72
        }
73
74
        $output = ['error' => false];
75
76
        if ($this->get('ongr_translations.command.export')->run(new ArrayInput([]), new NullOutput()) != 0) {
77
            $output['error'] = true;
78
        }
79
80
        return new JsonResponse($output);
81
    }
82
83
    /**
84
     * Action for executing history command.
85
     *
86
     * @param Request $request Http request object.
87
     * @param string  $id
88
     *
89
     * @return JsonResponse
90
     */
91
    public function historyAction(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
    {
93
        $document = $this->get('ongr_translations.translation_manager')->getTranslation($id);
94
95
        if (empty($document)) {
96
            return new JsonResponse(['error' => true, 'message' => 'translation not found']);
97
        }
98
99
        return new JsonResponse($this->get('ongr_translations.history_manager')->getHistory($document));
100
    }
101
}
102