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

SiteHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 36
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 16 4
A resolveSiteId() 0 8 2
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