Completed
Push — master ( 193c3c...281dde )
by Nate
07:20
created

SiteHelper::get()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 13
cp 0
rs 9.2
c 0
b 0
f 0
nc 4
cc 4
eloc 8
nop 1
crap 20
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://github.com/flipboxfactory/craft-ember/blob/master/LICENSE
6
 * @link       https://github.com/flipboxfactory/craft-ember
7
 */
8
9
namespace flipbox\ember\helpers;
10
11
use Craft;
12
use craft\models\Site;
13
14
/**
15
 * @author Flipbox Factory <[email protected]>
16
 * @since 1.0.0
17
 */
18
class SiteHelper
19
{
20
    /**
21
     * @param int|string|Site $site
22
     * @return Site
23
     */
24
    public static function get($site = null): Site
25
    {
26
        if ($site instanceof Site) {
27
            return $site;
28
        }
29
30
        if (is_numeric($site)) {
31
            return Craft::$app->getSites()->getSiteById($site);
32
        }
33
34
        if (is_string($site)) {
35
            return Craft::$app->getSites()->getSiteByHandle($site);
36
        }
37
38
        return Craft::$app->getSites()->currentSite;
39
    }
40
41
    /**
42
     * @param int|null $siteId
43
     * @return int
44
     */
45
    public static function resolveSiteId(int $siteId = null): int
46
    {
47
        if (is_null($siteId)) {
48
            $siteId = Craft::$app->getSites()->currentSite->id;
49
        }
50
51
        return $siteId;
52
    }
53
}
54