Completed
Push — master ( 4cb1ea...24446f )
by Christopher
13:20 queued 04:57
created

Site   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 50
rs 10
c 1
b 1
f 0
wmc 8
lcom 2
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSettings() 0 8 2
A getConfig() 0 4 1
A getMenu() 0 18 2
A getUrl() 0 11 3
1
<?php
2
3
namespace TechWilk\Rota;
4
5
use DateTime;
6
7
class Site
8
{
9
    private $settings;
10
    private $menu;
11
12
    public function getSettings()
13
    {
14
        if (!isset($this->settings)) {
15
            $this->settings = SettingsQuery::create()->findOne();
16
        }
17
18
        return $this->settings;
19
    }
20
21
    public function getConfig()
22
    {
23
        return getConfig();
24
    }
25
26
    public function getMenu()
27
    {
28
        if (!isset($this->menu)) {
29
            $this->menu['events']['type'] = EventTypeQuery::create()
30
                ->useEventQuery()
31
                    ->filterByRemoved(false)
32
                    ->filterByDate(['min' => new DateTime()])
33
                ->endUse()
34
                ->distinct()
35
                ->find();
36
37
            $this->menu['groups'] = GroupQuery::create()
38
                                        ->distinct()
39
                                        ->find();
40
        }
41
42
        return $this->menu;
43
    }
44
45
    public function getUrl()
0 ignored issues
show
Coding Style introduced by
getUrl uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
46
    {
47
        $http = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
48
        $hostname = $_SERVER['HTTP_HOST'];
49
50
        return [
51
            'base'     => $http.'://'.$hostname,
52
            'protocol' => $http,
53
            'host'     => $hostname,
54
        ];
55
    }
56
}
57