Completed
Push — master ( 3eedc0...aee843 )
by Mikael
02:40
created

CDIFactoryDefault::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 141
Code Lines 98

Duplication

Lines 20
Ratio 14.18 %

Code Coverage

Tests 22
CRAP Score 1.4785

Importance

Changes 17
Bugs 1 Features 1
Metric Value
c 17
b 1
f 1
dl 20
loc 141
ccs 22
cts 101
cp 0.2178
rs 8.2857
cc 1
eloc 98
nc 1
nop 0
crap 1.4785

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
 */
10
class CDIFactoryDefault extends CDI
11
{
12
   /**
13
     * Construct.
14
     *
15
     */
16 1
    public function __construct()
17
    {
18 1
        parent::__construct();
19
20 1
        require ANAX_APP_PATH . 'config/error_reporting.php';
21
22
        $this->set('response', function () {
23
            $response = new \Anax\Response\CResponseBasic();
24
            $response->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...
25
            return $response;
26 1
        });
27
28 1
        $this->setShared('validate', '\Anax\Validate\CValidate');
29 1
        $this->setShared('flash', '\Anax\Flash\CFlashBasic');
30
        
31 1
        $this->set('route', '\Anax\Route\CRouteBasic');
32 1
        $this->set('view', '\Anax\View\CViewBasic');
33
34
        $this->set('ErrorController', function () {
35
            $controller = new \Anax\MVC\ErrorController();
36
            $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...
37
            return $controller;
38 1
        });
39
40
        $this->setShared('log', function () {
41
            $log = new \Anax\Log\CLogger();
42
            $log->setContext('development');
43
            return $log;
44 1
        });
45
46
        $this->setShared('request', function () {
47
            $request = new \Anax\Request\CRequestBasic();
48
            $request->init();
49
            return $request;
50 1
        });
51
52
        $this->setShared('url', function () {
53
            $url = new \Anax\Url\CUrl();
54
            $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...
55
            $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...
56
            $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...
57
            $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...
58
            $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...
59
            $url->setUrlType($url::URL_APPEND);
60
            return $url;
61 1
        });
62
63
        $this->setShared('views', function () {
64
            $views = new \Anax\View\CViewContainerBasic();
65
            $views->setBasePath(ANAX_APP_PATH . 'view');
66
            $views->setFileSuffix('.tpl.php');
67
            $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...
68
            return $views;
69 1
        });
70
71
        $this->setShared('router', function () {
72
            
73
            $router = new \Anax\Route\CRouterBasic();
74
            $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...
75
76 View Code Duplication
            $router->addInternal('403', function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
77
                $this->dispatcher->forward([
0 ignored issues
show
Documentation introduced by
The property dispatcher 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...
78
                    'controller' => 'error',
79
                    'action' => 'statusCode',
80
                    'params' => [
81
                        'code' => 403,
82
                        'message' => "HTTP Status Code 403: This is a forbidden route.",
83
                    ],
84
                ]);
85
            })->setName('403');
86
            
87
            $router->addInternal('404', function () {
88
                $this->dispatcher->forward([
0 ignored issues
show
Documentation introduced by
The property dispatcher 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...
89
                    'controller' => 'error',
90
                    'action' => 'statusCode',
91
                    'params' => [
92
                        'code' => 404,
93
                        'message' => "HTTP Status Code 404: This route is not found.",
94
                    ],
95
                ]);
96
                $this->dispatcher->forward([
0 ignored issues
show
Documentation introduced by
The property dispatcher 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...
97
                    'controller' => 'error',
98
                    'action' => 'displayValidRoutes',
99
                ]);
100
            })->setName('404');
101
            
102 View Code Duplication
            $router->addInternal('500', function () {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
                $this->dispatcher->forward([
0 ignored issues
show
Documentation introduced by
The property dispatcher 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...
104
                    'controller' => 'error',
105
                    'action' => 'statusCode',
106
                    'params' => [
107
                        'code' => 500,
108
                        'message' => "HTTP Status Code 500: There was an internal server or processing error.",
109
                    ],
110
                ]);
111
            })->setName('500');
112
            
113
            return $router;
114 1
        });
115
116
        $this->setShared('dispatcher', function () {
117
            $dispatcher = new \Anax\MVC\CDispatcherBasic();
118
            $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...
119
            return $dispatcher;
120 1
        });
121
122
        $this->setShared('session', function () {
123
            $session = new \Anax\Session\CSession();
124
            $session->configure(ANAX_APP_PATH . 'config/session.php');
125
            $session->name();
126
            $session->start();
127
            return $session;
128 1
        });
129
130
        $this->setShared('theme', function () {
131
            $themeEngine = new \Anax\ThemeEngine\CThemeBasic();
132
            $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...
133
            $themeEngine->configure(ANAX_APP_PATH . 'config/theme.php');
134
            return $themeEngine;
135 1
        });
136
137
        $this->setShared('navbar', function () {
138
            $navbar = new \Anax\Navigation\CNavbar();
139
            $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...
140
            $navbar->configure(ANAX_APP_PATH . 'config/navbar.php');
141
            return $navbar;
142 1
        });
143
144
        $this->set('fileContent', function () {
145
            $fc = new \Anax\Content\CFileContent();
146
            $fc->setBasePath(ANAX_APP_PATH . 'content/');
147
            return $fc;
148 1
        });
149
150 1
        $this->setShared('textFilter', function () {
151
            $filter = new \Anax\Content\CTextFilter();
152
            $filter->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...
153
            $filter->configure(ANAX_APP_PATH . 'config/text_filter.php');
154
            return $filter;
155 1
        });
156 1
    }
157
}
158