CDIFactoryDefault   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 139
Duplicated Lines 21.58 %

Coupling/Cohesion

Components 0
Dependencies 13

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 30
loc 139
rs 10
wmc 1
lcom 0
cbo 13

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 30 132 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
    public function __construct()
17
    {
18
        parent::__construct();
19
20
        require ANAX_APP_PATH . 'config/error_reporting.php';
21
22
        $this->setShared('response', '\Anax\Response\CResponseBasic');
23
        $this->setShared('validate', '\Anax\Validate\CValidate');
24
        $this->setShared('flash', '\Anax\Flash\CFlashBasic');
25
        
26
        $this->set('route', '\Anax\Route\CRouteBasic');
27
        $this->set('view', '\Anax\View\CViewBasic');
28
29
        $this->set('ErrorController', function () {
30
            $controller = new \Anax\MVC\ErrorController();
31
            $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...
32
            return $controller;
33
        });
34
35
        $this->setShared('log', function () {
36
            $log = new \Anax\Log\CLogger();
37
            $log->setContext('development');
38
            return $log;
39
        });
40
41
        $this->setShared('request', function () {
42
            $request = new \Anax\Request\CRequestBasic();
43
            $request->init();
44
            return $request;
45
        });
46
47
        $this->setShared('url', function () {
48
            $url = new \Anax\Url\CUrl();
49
            $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...
50
            $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...
51
            $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...
52
            $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...
53
            $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...
54
            $url->setUrlType($url::URL_APPEND);
55
            return $url;
56
        });
57
58
        $this->setShared('views', function () {
59
            $views = new \Anax\View\CViewContainerBasic();
60
            $views->setBasePath(ANAX_APP_PATH . 'view');
61
            $views->setFileSuffix('.tpl.php');
62
            $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...
63
            return $views;
64
        });
65
66
        $this->setShared('router', function () {
67
            
68
            $router = new \Anax\Route\CRouterBasic();
69
            $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...
70
71 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...
72
                $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...
73
                    'controller' => 'error',
74
                    'action' => 'statusCode',
75
                    'params' => [
76
                        'code' => 403,
77
                        'message' => "HTTP Status Code 403: This is a forbidden route.",
78
                    ],
79
                ]);
80
            })->setName('403');
81
            
82 View Code Duplication
            $router->addInternal('404', 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...
83
                $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...
84
                    'controller' => 'error',
85
                    'action' => 'statusCode',
86
                    'params' => [
87
                        'code' => 404,
88
                        'message' => "HTTP Status Code 404: This route is not found.",
89
                    ],
90
                ]);
91
            })->setName('404');
92
            
93 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...
94
                $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...
95
                    'controller' => 'error',
96
                    'action' => 'statusCode',
97
                    'params' => [
98
                        'code' => 500,
99
                        'message' => "HTTP Status Code 500: There was an internal server or processing error.",
100
                    ],
101
                ]);
102
            })->setName('500');
103
            
104
            return $router;
105
        });
106
107
        $this->setShared('dispatcher', function () {
108
            $dispatcher = new \Anax\MVC\CDispatcherBasic();
109
            $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...
110
            return $dispatcher;
111
        });
112
113
        $this->setShared('session', function () {
114
            $session = new \Anax\Session\CSession();
115
            $session->configure(ANAX_APP_PATH . 'config/session.php');
116
            $session->name();
117
            $session->start();
118
            return $session;
119
        });
120
121
        $this->setShared('theme', function () {
122
            $themeEngine = new \Anax\ThemeEngine\CThemeBasic();
123
            $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...
124
            $themeEngine->configure(ANAX_APP_PATH . 'config/theme.php');
125
            return $themeEngine;
126
        });
127
128
        $this->setShared('navbar', function () {
129
            $navbar = new \Anax\Navigation\CNavbar();
130
            $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...
131
            $navbar->configure(ANAX_APP_PATH . 'config/navbar.php');
132
            return $navbar;
133
        });
134
135
        $this->set('fileContent', function () {
136
            $fc = new \Anax\Content\CFileContent();
137
            $fc->setBasePath(ANAX_APP_PATH . 'content/');
138
            return $fc;
139
        });
140
141
        $this->setShared('textFilter', function () {
142
            $filter = new \Anax\Content\CTextFilter();
143
            $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...
144
            $filter->configure(ANAX_APP_PATH . 'config/text_filter.php');
145
            return $filter;
146
        });
147
    }
148
}
149