Passed
Push — master ( 195422...889b95 )
by Georgi
03:03
created

HomePageCommon::getAvailableHomePages()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 12
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
	 * Collect all home pages from module joints
13
	 * 
14
	 * @return array
15
	 */
16
	public static function getAvailableHomePages()
17
	{
18
		static $cache;
19
		
20
		if (! isset($cache)) {
21
			$cache = [];
22
			foreach (HomePageJoint::collect() as $joint) {
23
				$cache[$joint->link()] = $joint->caption();
24
			}
25
		}
26
		
27
		return $cache;
28
	}
29
30
	/**
31
	 * Get the current user home page
32
	 * 
33
	 * @return HomePage
34
	 */
35
	public static function getUserHomePage()
36
	{
37
		if (! $user = Auth::user()) return;
38
39
		return HomePage::whereIn('role', $user->roles()->pluck('name'))->orderBy('priority')->first();
1 ignored issue
show
Bug introduced by
The method roles() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
		return HomePage::whereIn('role', $user->/** @scrutinizer ignore-call */ roles()->pluck('name'))->orderBy('priority')->first();
Loading history...
40
	}
41
}
42