Passed
Push — master ( 93b237...f60264 )
by Mikael
01:25
created

DIServiceSetBaseTrait::createDefaultServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 52
Code Lines 36

Duplication

Lines 12
Ratio 23.08 %

Code Coverage

Tests 11
CRAP Score 1.3469

Importance

Changes 0
Metric Value
dl 12
loc 52
ccs 11
cts 37
cp 0.2973
rs 9.4929
c 0
b 0
f 0
cc 1
eloc 36
nc 1
nop 0
crap 1.3469

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
 * Trait to create a set of base services.
7
 */
8
trait DIServiceSetBaseTrait
9
{
10
   /**
11
     * Create a set of basic services useful for a website.
12
     *
13
     * @return self
14
     */
15 2
    public function createDefaultServices()
16
    {
17
        $this->setShared("request", function () {
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
18
            $request = new \Anax\Request\Request();
19
            $request->init();
20
            return $request;
21 2
        });
22
23 2
        $this->setShared("response", "\Anax\Response\Response");
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
24
25 View Code Duplication
        $this->setShared("url", function () {
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
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...
26
            $url = new \Anax\Url\Url();
27
            $request = $this->get("request");
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
28
            $url->setSiteUrl($request->getSiteUrl());
29
            $url->setBaseUrl($request->getBaseUrl());
30
            $url->setStaticSiteUrl($request->getSiteUrl());
31
            $url->setStaticBaseUrl($request->getBaseUrl());
32
            $url->setScriptName($request->getScriptName());
33
            $url->configure("url.php");
34
            $url->setDefaultsFromConfiguration();
35
            return $url;
36 2
        });
37
38
        $this->setShared("router", function () {
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
39
            $router = new \Anax\Route\Router();
40
            $router->setDI($this);
41
            return $router;
42 2
        });
43
44
        $this->setShared("view", function () {
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
45
            $view = new \Anax\View\ViewContainer();
46
            $view->configure("view.php");
47
            $view->setDI($this);
48
            return $view;
49 2
        });
50
51
        $this->setShared("viewRenderFile", function () {
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
52
            $viewRender = new \Anax\View\ViewRenderFile2();
53
            $viewRender->setDI($this);
54
            return $viewRender;
55 2
        });
56
57 2
        $this->setShared("session", function () {
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
58
            $session = new \Anax\Session\SessionConfigurable();
59
            $session->configure("session.php");
60
            return $session;
61 2
        });
62
63 2
        $this->setShared("textfilter", "\Anax\TextFilter\TextFilter");
0 ignored issues
show
Bug introduced by
It seems like setShared() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
64
65 2
        return $this;
66
    }
67
}
68