CDIFactoryDefault::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 114

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 21
CRAP Score 1.3614

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 114
ccs 21
cts 73
cp 0.2877
crap 1.3614
rs 8
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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->configure("url.php");
60
            $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...
61
            $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...
62
            $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...
63
            $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...
64
            $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...
65 1
            $url->setDefaultsFromConfiguration();
66
            return $url;
67
        });
68
69
        $this->setShared("views", function () {
70
            $views = new \Anax\View\CViewContainer();
71 1
            $views->configure("views.php");
72
            $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...
73
            return $views;
74
        });
75
76
        $this->setShared("router", function () {
77 1
            
78
            $router = new \Anax\Route\CRouterBasic();
79
            $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...
80
            return $router;
81
        });
82
83
        $this->setShared("dispatcher", function () {
84
            $dispatcher = new \Anax\MVC\CDispatcherBasic();
85
            $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...
86
            return $dispatcher;
87
        });
88 1
89
        $this->setShared("session", function () {
90
            $session = new \Anax\Session\CSession();
91
            $session->configure("session.php");
92
            $session->name();
93
            $session->start();
94
            return $session;
95 1
        });
96
97
        $this->setShared("theme", function () {
98
            $themeEngine = new \Anax\ThemeEngine\CThemeEngine();
99
            $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...
100
            $themeEngine->configure("theme.php");
101
            return $themeEngine;
102
        });
103
104
        $this->setShared("navbar", function () {
105
            $navbar = new \Anax\Navigation\CNavbar();
106
            $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...
107
            $navbar->configure("navbar.php");
108
            return $navbar;
109
        });
110
111
        $this->set("fileContent", function () {
112
            $fc = new \Anax\Content\CFileContent();
113
            $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...
114
            $fc->configure("file_content.php");
115
            return $fc;
116
        });
117
118
        $this->set("pageContent", function () {
119
            $pc = new \Anax\Content\CPageContent();
120
            $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...
121
            $pc->configure("page_content.php");
122
            return $pc;
123
        });
124
125
        $this->setShared("content", function () {
126
            $content = new \Anax\Content\CFileBasedContent();
127
            $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...
128
            $content->configure("content.php");
129
            $content->setDefaultsFromConfiguration();
130
            return $content;
131
        });
132
    }
133
}
134