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

DIServiceSetBaseTrait   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 60
Duplicated Lines 20 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 29.73%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 0
dl 12
loc 60
ccs 11
cts 37
cp 0.2973
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createDefaultServices() 12 52 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
 * 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