Passed
Branch ci (072b24)
by litefeel
05:02
created

Writing_On_GitHub_TestCase::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 57
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 62
rs 9.4743

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
abstract class Writing_On_GitHub_TestCase extends WP_HTTP_TestCase {
4
5
    /**
6
     * @var string
7
     */
8
    protected $data_dir;
9
10
    /**
11
     * @var Writing_On_GitHub|Mockery\Mock
12
     */
13
    protected $app;
14
15
    /**
16
     * @var Writing_On_GitHub_Controller|Mockery\Mock
17
     */
18
    protected $controller;
19
20
    /**
21
     * @var Writing_On_GitHub_Request|Mockery\Mock
22
     */
23
    protected $request;
24
25
    /**
26
     * @var Writing_On_GitHub_Import|Mockery\Mock
27
     */
28
    protected $import;
29
30
    /**
31
     * @var Writing_On_GitHub_Export|Mockery\Mock
32
     */
33
    protected $export;
34
35
    /**
36
     * @var Writing_On_GitHub_Response|Mockery\Mock
37
     */
38
    protected $response;
39
40
    /**
41
     * @var Writing_On_GitHub_Payload|Mockery\Mock
42
     */
43
    protected $payload;
44
45
    /**
46
     * @var Writing_On_GitHub_Api|Mockery\Mock
47
     */
48
    protected $api;
49
50
    /**
51
     * @var Writing_On_GitHub_Semaphore|Mockery\Mock
52
     */
53
    protected $semaphore;
54
55
    /**
56
     * @var Writing_On_GitHub_Database|Mockery\Mock
57
     */
58
    protected $database;
59
60
    /**
61
     * @var Writing_On_GitHub_Post|Mockery\Mock
62
     */
63
    protected $post;
64
65
    /**
66
     * @var Writing_On_GitHub_Blob|Mockery\Mock
67
     */
68
    protected $blob;
69
70
    /**
71
     * @var Writing_On_GitHub_Fetch_Client|Mockery\Mock
72
     */
73
    protected $fetch;
74
75
    /**
76
     * @var Writing_On_GitHub_Persist_Client|Mockery\Mock
77
     */
78
    protected $persist;
79
80
    public function setUp() {
0 ignored issues
show
Coding Style introduced by
The function name setUp is in camel caps, but expected set_up instead as per the coding standard.
Loading history...
81
        parent::setUp();
82
83
        $this->data_dir = dirname( __DIR__ ) . '/data/';
84
85
        $this->app        = Mockery::mock( 'Writing_On_GitHub' );
86
        $this->controller = Mockery::mock( 'Writing_On_GitHub_Controller' );
87
        $this->request    = Mockery::mock( 'Writing_On_GitHub_Request' );
88
        $this->import     = Mockery::mock( 'Writing_On_GitHub_Import' );
89
        $this->export     = Mockery::mock( 'Writing_On_GitHub_Export' );
90
        $this->response   = Mockery::mock( 'Writing_On_GitHub_Response' );
91
        $this->payload    = Mockery::mock( 'Writing_On_GitHub_Payload' );
92
        $this->api        = Mockery::mock( 'Writing_On_GitHub_Api' );
93
        $this->semaphore  = Mockery::mock( 'Writing_On_GitHub_Semaphore' );
94
        $this->database   = Mockery::mock( 'Writing_On_GitHub_Database' );
95
        $this->post       = Mockery::mock( 'Writing_On_GitHub_Post' );
96
        $this->blob       = Mockery::mock( 'Writing_On_GitHub_Blob' );
97
        $this->fetch      = Mockery::mock( 'Writing_On_GitHub_Fetch_Client' );
98
        $this->persist    = Mockery::mock( 'Writing_On_GitHub_Persist_Client' );
99
100
        Writing_On_GitHub::$instance = $this->app;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->app of type Mockery\MockInterface is incompatible with the declared type Writing_On_GitHub of property $instance.

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...
Documentation Bug introduced by
$this->app is of type Mockery\MockInterface, but the property $app was declared to be of type Mockery\Mock|Writing_On_GitHub. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
101
102
        $this->app
103
            ->shouldReceive( 'request' )
0 ignored issues
show
Unused Code introduced by
The call to Mockery\MockInterface::shouldReceive() has too many arguments starting with 'request'. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

103
            ->/** @scrutinizer ignore-call */ 
104
              shouldReceive( 'request' )

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
104
            ->andReturn( $this->request )
105
            ->byDefault();
106
        $this->app
107
            ->shouldReceive( 'import' )
108
            ->andReturn( $this->import )
109
            ->byDefault();
110
        $this->app
111
            ->shouldReceive( 'export' )
112
            ->andReturn( $this->export )
113
            ->byDefault();
114
        $this->app
115
            ->shouldReceive( 'response' )
116
            ->andReturn( $this->response )
117
            ->byDefault();
118
        $this->app
119
            ->shouldReceive( 'api' )
120
            ->andReturn( $this->api )
121
            ->byDefault();
122
        $this->app
123
            ->shouldReceive( 'semaphore' )
124
            ->andReturn( $this->semaphore )
125
            ->byDefault();
126
        $this->app
127
            ->shouldReceive( 'database' )
128
            ->andReturn( $this->database )
129
            ->byDefault();
130
        $this->app
131
            ->shouldReceive( 'blob' )
132
            ->andReturn( $this->blob )
133
            ->byDefault();
134
        $this->api
135
            ->shouldReceive( 'fetch' )
136
            ->andReturn( $this->fetch )
137
            ->byDefault();
138
        $this->api
139
            ->shouldReceive( 'persist' )
140
            ->andReturn( $this->persist )
141
            ->byDefault();
142
    }
143
144
    public function tearDown() {
0 ignored issues
show
Coding Style introduced by
The function name tearDown is in camel caps, but expected tear_down instead as per the coding standard.
Loading history...
145
        Mockery::close();
146
    }
147
}
148