View   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_user() 0 4 1
B provide() 0 19 5
1
<?php
2
3
/*
4
 * This file is part of the Icybee package.
5
 *
6
 * (c) Olivier Laviale <[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 Icybee\Modules\Users;
13
14
use ICanBoogie\HTTP\AuthenticationRequired;
15
16
use Icybee\Modules\Views\ViewOptions;
17
18
/**
19
 * @property-read User $user
20
 */
21
class View extends \Icybee\Modules\Views\View
22
{
23
	protected function get_user()
24
	{
25
		return $this->app->user;
26
	}
27
28
	/**
29
	 * @throws AuthenticationRequired with code 401 if the record is offline and the user don't
30
	 * have access permission to the module.
31
	 *
32
	 * @inheritdoc
33
	 */
34
	protected function provide($provider, array $conditions)
35
	{
36
		if ($this->renders == ViewOptions::RENDERS_MANY)
37
		{
38
			$conditions['is_activated'] = true;
39
		}
40
41
		$rc = parent::provide($provider, $conditions);
42
43
		if ($rc instanceof User && !$rc->is_activated)
44
		{
45
			if (!$this->user->has_permission(Module::PERMISSION_ACCESS, $rc->constructor))
46
			{
47
				throw new AuthenticationRequired;
48
			}
49
		}
50
51
		return $rc;
52
	}
53
}
54