These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 Symfony\Bundle\FrameworkBundle\Controller\Controller; |
||
15 | use Symfony\Component\Console\Input\ArrayInput; |
||
16 | use Symfony\Component\Console\Output\NullOutput; |
||
17 | use Symfony\Component\HttpFoundation\JsonResponse; |
||
18 | use Symfony\Component\HttpFoundation\Request; |
||
19 | |||
20 | /** |
||
21 | * Controller used for api's actions. |
||
22 | */ |
||
23 | class ApiController extends Controller |
||
24 | { |
||
25 | /** |
||
26 | * Action for editing translation objects. |
||
27 | * |
||
28 | * @param Request $request Http request object. |
||
29 | * @param string $id |
||
30 | * |
||
31 | * @return JsonResponse |
||
32 | */ |
||
33 | public function updateAction(Request $request, $id) |
||
34 | { |
||
35 | $response = ['error' => false]; |
||
36 | |||
37 | try { |
||
38 | $this->get('ongr_translations.translation_manager')->update($id, $request); |
||
39 | } catch (\LogicException $e) { |
||
40 | $response = ['error' => true]; |
||
41 | } |
||
42 | |||
43 | return new JsonResponse($response); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * Action for getting translation. |
||
48 | * |
||
49 | * @param Request $request Http request object. |
||
50 | * @param string $id |
||
51 | * |
||
52 | * @return JsonResponse |
||
53 | */ |
||
54 | public function getAction(Request $request, $id) |
||
55 | { |
||
56 | return new JsonResponse($this->get('ongr_translations.translation_manager')->get($id)); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @param Request $request |
||
61 | * @return JsonResponse |
||
62 | */ |
||
63 | public function allAction(Request $request) |
||
64 | { |
||
65 | return new JsonResponse($this->get('ongr_translations.translation_manager')->getAll()); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Action for executing export command. |
||
70 | * |
||
71 | * @return JsonResponse |
||
72 | */ |
||
73 | public function exportAction() |
||
74 | { |
||
75 | $cwd = getcwd(); |
||
76 | if (substr($cwd, -3) === 'web') { |
||
77 | chdir($cwd . DIRECTORY_SEPARATOR . '..'); |
||
78 | } |
||
79 | |||
80 | $output = ['error' => false]; |
||
81 | |||
82 | if ($this->get('ongr_translations.command.export')->run(new ArrayInput([]), new NullOutput()) != 0) { |
||
83 | $output['error'] = true; |
||
84 | } |
||
85 | |||
86 | return new JsonResponse($output); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Action for executing history command. |
||
91 | * |
||
92 | * @param Request $request Http request object. |
||
93 | * @param string $id |
||
94 | * |
||
95 | * @return JsonResponse |
||
96 | */ |
||
97 | public function historyAction(Request $request, $id) |
||
98 | { |
||
99 | $document = $this->get('ongr_translations.translation_manager')->get($id); |
||
100 | |||
101 | if (empty($document)) { |
||
102 | return new JsonResponse(['error' => true, 'message' => 'translation not found']); |
||
103 | } |
||
104 | |||
105 | return new JsonResponse($this->get('ongr_translations.history_manager')->get($document)); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @param Request $request Http request object. |
||
110 | * |
||
111 | * @return JsonResponse |
||
112 | */ |
||
113 | public function tagsAction(Request $request) |
||
0 ignored issues
–
show
|
|||
114 | { |
||
115 | return new JsonResponse($this->get('ongr_translations.translation_manager')->getTags()); |
||
116 | } |
||
117 | } |
||
118 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.