Completed
Push — master ( 665577...6c1e3b )
by Mikael
02:27
created

CDIFactoryDefault   B

Complexity

Total Complexity 1

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 16

Test Coverage

Coverage 28.77%

Importance

Changes 15
Bugs 1 Features 2
Metric Value
c 15
b 1
f 2
dl 0
loc 124
rs 8.4614
ccs 21
cts 73
cp 0.2877
wmc 1
lcom 0
cbo 16

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 113 1
1
<?php
2
3
namespace Anax\DI;
4
5
/**
6
 * Anax base class implementing Dependency Injection / Service Locator
7
 * of the services used by the framework, using lazy loading.
8
 */
9
class CDIFactoryDefault extends CDI
10
{
11
    use \Anax\TLoadFile;
12
13
14
15
   /**
16
     * Construct.
17
     *
18
     */
19
    public function __construct()
20 1
    {
21
        parent::__construct();
22 1
23 1
        $this->loadFile("error_reporting.php");
24
25 1
        $this->setShared("response", "\Anax\Response\CResponseBasic");
26
        $this->setShared("validate", "\Anax\Validate\CValidate");
27
        $this->setShared("flash", "\Anax\Flash\CFlashBasic");
28 1
        $this->setShared("textFilter", "\Mos\TextFilter\CTextFilter");
29 1
30 1
        $this->set("route", "\Anax\Route\CRouteBasic");
31
        $this->set("view", "\Anax\View\CView");
32
33
        $this->set("ErrorController", function () {
34
            $controller = new \Anax\MVC\ErrorController();
35
            $controller->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
36
            return $controller;
37
        });
38
39
        $this->setShared("log", function () {
40
            $log = new \Anax\Log\CLogger();
41
            $log->setContext("development");
42 1
            return $log;
43
        });
44 1
45
        $this->setShared("cache", function () {
46 1
            $cache = new \Anax\Cache\CFileCache();
47
            $cache->configure("cache.php");
48 1
            return $cache;
49 1
        });
50 1
51
        $this->setShared("request", function () {
52 1
            $request = new \Anax\Request\CRequestBasic();
53 1
            $request->init();
54
            return $request;
55
        });
56
57
        $this->setShared("url", function () {
58
            $url = new \Anax\Url\CUrl();
59 1
            $url->setSiteUrl($this->request->getSiteUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\CDIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60
            $url->setBaseUrl($this->request->getBaseUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\CDIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
61
            $url->setStaticSiteUrl($this->request->getSiteUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\CDIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
62
            $url->setStaticBaseUrl($this->request->getBaseUrl());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\CDIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
63
            $url->setScriptName($this->request->getScriptName());
0 ignored issues
show
Documentation introduced by
The property request does not exist on object<Anax\DI\CDIFactoryDefault>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64
            $url->setUrlType($url::URL_APPEND);
65 1
            return $url;
66
        });
67
68
        $this->setShared("views", function () {
69
            $views = new \Anax\View\CViewContainer();
70
            $views->configure("views.php");
71 1
            $views->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
72
            return $views;
73
        });
74
75
        $this->setShared("router", function () {
76
            
77 1
            $router = new \Anax\Route\CRouterBasic();
78
            $router->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
            return $router;
80
        });
81
82
        $this->setShared("dispatcher", function () {
83
            $dispatcher = new \Anax\MVC\CDispatcherBasic();
84
            $dispatcher->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
85
            return $dispatcher;
86
        });
87
88 1
        $this->setShared("session", function () {
89
            $session = new \Anax\Session\CSession();
90
            $session->configure("session.php");
91
            $session->name();
92
            $session->start();
93
            return $session;
94
        });
95 1
96
        $this->setShared("theme", function () {
97
            $themeEngine = new \Anax\ThemeEngine\CThemeEngine();
98
            $themeEngine->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
99
            $themeEngine->configure("theme.php");
100
            return $themeEngine;
101
        });
102
103
        $this->setShared("navbar", function () {
104
            $navbar = new \Anax\Navigation\CNavbar();
105
            $navbar->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
106
            $navbar->configure("navbar.php");
107
            return $navbar;
108
        });
109
110
        $this->set("fileContent", function () {
111
            $fc = new \Anax\Content\CFileContent();
112
            $fc->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
113
            $fc->configure("file_content.php");
114
            return $fc;
115
        });
116
117
        $this->set("pageContent", function () {
118
            $pc = new \Anax\Content\CPageContent();
119
            $pc->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
120
            $pc->configure("page_content.php");
121
            return $pc;
122
        });
123
124
        $this->setShared("content", function () {
125
            $content = new \Anax\Content\CFileBasedContent();
126
            $content->setDI($this);
0 ignored issues
show
Documentation introduced by
$this is of type this<Anax\DI\CDIFactoryDefault>, but the function expects a object<Anax\DI\class>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
127
            $content->configure("content.php");
128
            $content->setDefaultsFromConfiguration();
129
            return $content;
130
        });
131
    }
132
}
133