Passed
Push — main ( a115e2...ed9b12 )
by Marc
04:17 queued 13s
created

AdminModelFactory::createAdminContentObject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 10
1
<?php declare(strict_types=1);
2
namespace html_go\model;
3
4
abstract class AdminModelFactory
5
{
6
    protected Config $config;
7
8
    public function __construct(Config $config) {
9
        $this->config = $config;
10
    }
11
12
    /**
13
     * Create a content object (stdClass) specifically for the admin console.
14
     * @param array<int, string> $params When populating with variable arguments, use the following
15
     * <b>named parameters<b>:
16
     * <ul>
17
     *   <li>title:</li>
18
     * </ul>
19
     * @return \stdClass
20
     */
21
    public function createAdminContentObject(array $params): \stdClass {
22
        $contentObject = new \stdClass();
23
        $contentObject->site = $this->getSiteObject();
24
        if (empty($params['title'])) {
25
            throw new \InvalidArgumentException("The 'title:' parameter has not been set!");
26
        }
27
        $contentObject->title = $params['title'];
28
        return $contentObject;
29
    }
30
31
    protected function getSiteObject(): \stdClass {
32
        static $site = null;
33
        if (empty($site)) {
34
            $site = new \stdClass();
35
            $site->url = $this->config->getString(Config::KEY_SITE_URL);
36
            $site->name = $this->config->getString(Config::KEY_SITE_NAME);
37
            $site->title = $this->config->getString(Config::KEY_SITE_TITLE);
38
            $site->description = $this->config->getString(Config::KEY_SITE_DESCRIPTION);
39
            $site->tagline = $this->config->getString(Config::KEY_SITE_TAGLINE);
40
            $site->copyright = $this->config->getString(Config::KEY_SITE_COPYRIGHT);
41
            $site->language = $this->config->getString(Config::KEY_LANG);
42
            $site->theme = $this->config->getString(Config::KEY_THEME_NAME);
43
            $site->tpl_engine = $this->config->getString(Config::KEY_TPL_ENGINE);
44
        }
45
        return $site;
46
    }
47
48
}
49