Completed
Pull Request — 1.0 (#109)
by
unknown
11:05
created

FakeManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 25.71 %

Coupling/Cohesion

Components 0
Dependencies 2
Metric Value
wmc 4
lcom 0
cbo 2
dl 9
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 9 9 2
A setDb() 0 3 1
A getDb() 0 3 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
 * The "Fake-Manager" instantiates fake objects, mainly to replace webservices with
4
 * faked implementations. It also provides shortcuts for creating complex fake datasets
5
 * through {@link FakeDatabase}.
6
 *
7
 * This class needs to be instantiated early in the application bootstrap process.
8
 * By default that's implemented through the {@link TestSessionExtension}
9
 * and config.yml.
10
 *
11
 * The instantiation is conditional on there being a Behat test actually running
12
 * (by virtue of there being a TestSession instantiated) by a 'useFakeManager' flag
13
 * set through the "TestSession" module (@see {@link App\Test\Behaviour\FeatureContext->getTestSessionState()}).
14
 *
15
 * Since both the FeatureContext and actual application bootstrap share the same
16
 * {@link FakeDatabase} persisted on disk, they can share state.
17
 *
18
 * In terms of mock-data, at time of writing we're using the same sources as unit-test
19
 * mocks do.
20
 *
21
 * @author SilverStripe Iterators <[email protected]>
22
 * @author SilverStripe Science Ninjas <[email protected]>
23
 */
24
class FakeManager {
25
26
    /**
27
     *
28
     * @var type
29
     */
30
    protected $db;
31
32
    /**
33
     *
34
     * @var type
35
     */
36
    protected $addressRightGateway;
37
38
    /**
39
     *
40
     * @param FakeDatabase $db
41
     */
42 View Code Duplication
    function __construct($db = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in 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...
43
        $testState = Injector::inst()->get('TestSessionEnvironment')->getState();
44
45
        if(!$db) {
46
            $db = new FakeDatabase($testState->fakeDatabasePath);
47
        }
48
49
        $this->db = $db;
0 ignored issues
show
Documentation Bug introduced by
It seems like $db of type object<FakeDatabase> is incompatible with the declared type object<type> of property $db.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
    }
51
52
    public function setDb($db) {
53
        $this->db = $db;
54
    }
55
    public function getDb() {
56
        return $this->db;
57
    }
58
}