Issues (36)

lib/Controller/NavigationController.php (4 issues)

Labels
Severity
1
<?php declare(strict_types=1);
2
3
4
/**
5
 * Files_FromMail - Recover your email attachments from your cloud.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2017
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 *  You should have received a copy of the GNU Affero General Public License
25
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Files_FromMail\Controller;
31
32
use Exception;
33
use OCA\Files_FromMail\AppInfo\Application;
34
use OCA\Files_FromMail\Service\MailService;
35
use OCA\Files_FromMail\Service\MiscService;
36
use OCP\AppFramework\Controller;
0 ignored issues
show
The type OCP\AppFramework\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use OCP\AppFramework\Http;
0 ignored issues
show
The type OCP\AppFramework\Http was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
38
use OCP\AppFramework\Http\DataResponse;
0 ignored issues
show
The type OCP\AppFramework\Http\DataResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
use OCP\IRequest;
0 ignored issues
show
The type OCP\IRequest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
40
41
42
/**
43
 * Class NavigationController
44
 *
45
 * @package OCA\Files_FromMail\Controller
46
 */
47
class NavigationController extends Controller {
48
49
50
	/** @var MailService */
51
	private $mailService;
52
53
	/** @var MiscService */
54
	private $miscService;
55
56
57
	/**
58
	 * RemoteController constructor.
59
	 *
60
	 * @param IRequest $request
61
	 * @param string $userId
62
	 * @param MailService $mailService
63
	 * @param MiscService $miscService
64
	 */
65
	function __construct(IRequest $request, MailService $mailService, MiscService $miscService) {
66
		parent::__construct(Application::APP_NAME, $request);
67
68
		$this->mailService = $mailService;
69
		$this->miscService = $miscService;
70
	}
71
72
73
	/**
74
	 * @return DataResponse
75
	 */
76
	public function getMailbox(): DataResponse {
77
		try {
78
			$mailbox = $this->mailService->getMailAddresses();
79
80
			return new DataResponse($mailbox, Http::STATUS_CREATED);
81
		} catch (Exception $e) {
82
			return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
83
		}
84
	}
85
86
87
	/**
88
	 * @param string $address
89
	 * @param string $password
90
	 *
91
	 * @return DataResponse
92
	 */
93
	public function newMailbox(string $address, string $password): DataResponse {
94
		try {
95
			$this->mailService->addMailAddress($address, $password);
96
97
			return new DataResponse(['ok'], Http::STATUS_CREATED);
98
		} catch (Exception $e) {
99
			return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
100
		}
101
	}
102
103
104
	/**
105
	 * @param string $address
106
	 *
107
	 * @return DataResponse
108
	 */
109
	public function deleteMailbox(string $address): DataResponse {
110
		try {
111
			$this->mailService->removeMailAddress($address);
112
113
			return new DataResponse(['ok'], Http::STATUS_CREATED);
114
		} catch (Exception $e) {
115
			return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
116
		}
117
	}
118
119
120
}
121
122