Passed
Push — developer ( 1132c4...b56112 )
by Mariusz
285:11 queued 250:18
created

ChangeCompany::checkPermission()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 * Change company action file.
4
 *
5
 * @package Action
6
 *
7
 * @copyright YetiForce Sp. z o.o.
8
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Radosław Skrzypczak <[email protected]>
10
 * @author Mariusz Krzaczkowski <[email protected]>
11
 */
12
13
namespace YF\Modules\Base\Action;
14
15
/**
16
 * Change company action class.
17
 */
18
class ChangeCompany extends \App\Controller\Action
19
{
20
	/** {@inheritdoc} */
21
	public function checkPermission(): void
22
	{
23
		parent::checkPermission();
24
		$companies = \App\User::getUser()->getCompanies();
25
		if (!isset($companies[$this->request->getInteger('record')])) {
26
			throw new \App\Exceptions\NoPermitted('ERR_ACTION_PERMISSION_DENIED');
27
		}
28
	}
29
30
	/** {@inheritdoc} */
31
	public function process(): void
32
	{
33
		$user = \App\User::getUser();
34
		$user->set('companyId', $this->request->getInteger('record'));
35
		$companies = $user->getCompanies();
36
		$user->set('parentName', $companies[$this->request->getInteger('record')]['name']);
37
38
		$response = new \App\Response();
39
		$response->setResult(true);
40
		$response->emit();
41
	}
42
}
43