Passed
Push — master ( 889b95...5c0c69 )
by Georgi
03:04
created

HomePageCommon::getUserHomePagePath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Epesi\Core\HomePage;
4
5
use Epesi\Core\HomePage\Integration\Joints\HomePageJoint;
6
use Illuminate\Support\Facades\Auth;
7
use Epesi\Core\HomePage\Database\Models\HomePage;
8
9
class HomePageCommon
10
{
11
	/**
12
	 * Fallback path in case no home page set for the user
13
	 * 
14
	 * @var string
15
	 */
16
	protected static $defaultPath = 'view/user.settings';
17
	
18
	/**
19
	 * Collect all home pages from module joints
20
	 * 
21
	 * @return array
22
	 */
23
	public static function getAvailableHomePages()
24
	{
25
		static $cache;
26
		
27
		if (! isset($cache)) {
28
			$cache = [];
29
			foreach (HomePageJoint::collect() as $joint) {
30
				$cache[$joint->link()] = $joint->caption();
31
			}
32
		}
33
		
34
		return $cache;
35
	}
36
37
	/**
38
	 * Get the current user home page
39
	 * 
40
	 * @return HomePage
41
	 */
42
	public static function getUserHomePage()
43
	{
44
		if (! $user = Auth::user()) return;
45
46
		return HomePage::whereIn('role', $user->roles()->pluck('name'))->orderBy('priority')->first();
47
	}
48
49
	/**
50
	 * Get the current user home page path
51
	 * 
52
	 * @return HomePage
53
	 */
54
	public static function getUserHomePagePath()
55
	{
56
		$homepage = self::getUserHomePage();
57
		
58
		return $homepage? $homepage->path: self::$defaultPath;
0 ignored issues
show
introduced by
$homepage is of type Epesi\Core\HomePage\Database\Models\HomePage, thus it always evaluated to true.
Loading history...
Bug Best Practice introduced by
The expression return $homepage ? $home...ath : self::defaultPath returns the type string which is incompatible with the documented return type Epesi\Core\HomePage\Database\Models\HomePage.
Loading history...
59
	}
60
}
61