Conditions | 5 |
Paths | 5 |
Total Lines | 26 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
1 | <?php |
||
38 | public static function resolve($site = null): SiteModel |
||
39 | { |
||
40 | if ($site instanceof SiteModel) { |
||
41 | return $site; |
||
42 | } |
||
43 | |||
44 | if (is_numeric($site)) { |
||
45 | return Craft::$app->getSites()->getSiteById($site); |
||
46 | } |
||
47 | |||
48 | if (is_string($site)) { |
||
49 | return Craft::$app->getSites()->getSiteByHandle($site); |
||
50 | } |
||
51 | |||
52 | try { |
||
53 | $object = Craft::createObject(SiteModel::class, [$site]); |
||
54 | } catch (\Exception $e) { |
||
55 | $object = new SiteModel(); |
||
56 | ObjectHelper::populate( |
||
57 | $object, |
||
58 | $site |
||
59 | ); |
||
60 | } |
||
61 | |||
62 | return $object; |
||
63 | } |
||
64 | |||
78 |