Passed
Push — master ( a97862...37982b )
by Alex
46s
created

TOperandTypeTest   D

Complexity

Total Complexity 61

Size/Duplication

Total Lines 567
Duplicated Lines 59.26 %

Coupling/Cohesion

Components 2
Dependencies 16

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 61
c 2
b 0
f 0
lcom 2
cbo 16
dl 336
loc 567
rs 4.054

43 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetStringNullString() 0 6 1
A testSetStringActualString() 0 6 1
A testSetStringEmptyArrayAsString() 0 13 2
A testSetStringNonEmptyArrayAsString() 0 13 2
A testSetStringObjectAsString() 0 13 2
A testSetGetBinaryRoundTrip() 0 7 1
A testSetGetIntRoundTrip() 0 7 1
A testSetGetFloatRoundTrip() 0 7 1
A testSetGetDecimalRoundTrip() 0 7 1
A testSetGetBoolRoundTrip() 0 6 1
A testSetGetDateTimeRoundTrip() 0 7 1
A testSetGetDateTimeOffsetRoundTrip() 0 7 1
A testSetBadIf() 17 17 2
A testSetGetIfRoundTrip() 11 11 1
A testSetBadRecord() 17 17 2
A testSetGetRecordRoundTrip() 11 11 1
A testSetBadCollection() 17 17 2
A testSetGetCollectionRoundTrip() 11 11 1
A testSetBadTypeAssert() 17 17 2
A testSetGetTypeAssertRoundTrip() 11 11 1
A testSetBadTypeTest() 17 17 2
A testSetGetTypeTestRoundTrip() 11 11 1
A testSetBadFunctionReference() 17 17 2
A testSetGetFunctionReferenceRoundTrip() 11 11 1
A testSetBadEntitySetReference() 17 17 2
A testSetGetEntitySetReferenceRoundTrip() 11 11 1
A testSetBadAnonymousFunction() 17 17 2
A testSetGetAnonymousFunctionRoundTrip() 11 11 1
A testSetBadParameterReference() 17 17 2
A testSetGetParameterReferenceRoundTrip() 11 11 1
A testSetBadApply() 17 17 2
A testSetGetApplyRoundTrip() 11 11 1
A testSetBadPropertyReference() 17 17 2
A testSetGetPropertyReferenceRoundTrip() 11 11 1
A testSetBadValueTermReference() 17 17 2
A testSetGetValueTermReferenceRoundTrip() 11 11 1
A testGExpressionNotValidWhenMoreThanOneBasicExpressionSet() 0 18 1
A testSetBadEnum() 0 13 2
A testSetGetEnumRoundTrip() 0 10 1
A testSetBadPath() 0 13 2
A testSetGetPathRoundTrip() 0 10 1
A testSetBadGuid() 0 13 2
A testSetGetGuidRoundTrip() 0 10 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TOperandTypeTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TOperandTypeTest, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace AlgoWeb\ODataMetadata\Tests\v3\edm;
4
5
use AlgoWeb\ODataMetadata\MetadataV3\edm\TAnonymousFunctionExpressionType;
6
use AlgoWeb\ODataMetadata\MetadataV3\edm\TApplyExpressionType;
7
use AlgoWeb\ODataMetadata\MetadataV3\edm\TCollectionExpressionType;
8
use AlgoWeb\ODataMetadata\MetadataV3\edm\TEntitySetReferenceExpressionType;
9
use AlgoWeb\ODataMetadata\MetadataV3\edm\TFunctionReferenceExpressionType;
10
use AlgoWeb\ODataMetadata\MetadataV3\edm\TIfExpressionType;
11
use AlgoWeb\ODataMetadata\MetadataV3\edm\TOperandType;
12
use AlgoWeb\ODataMetadata\MetadataV3\edm\TParameterReferenceExpressionType;
13
use AlgoWeb\ODataMetadata\MetadataV3\edm\TPropertyReferenceExpressionType;
14
use AlgoWeb\ODataMetadata\MetadataV3\edm\TRecordExpressionType;
15
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeAssertExpressionType;
16
use AlgoWeb\ODataMetadata\MetadataV3\edm\TTypeTestExpressionType;
17
use AlgoWeb\ODataMetadata\MetadataV3\edm\TValueTermReferenceExpressionType;
18
use AlgoWeb\ODataMetadata\Tests\TestCase;
19
use Mockery as m;
20
21
class TOperandTypeTest extends TestCase
22
{
23
    public function testSetStringNullString()
24
    {
25
        $foo = new TOperandType();
26
        $foo->setString(null);
27
        $this->assertEquals(null, $foo->getString());
28
    }
29
30
    public function testSetStringActualString()
31
    {
32
        $foo = new TOperandType();
33
        $foo->setString("string");
34
        $this->assertEquals('string', $foo->getString());
35
    }
36
37
    public function testSetStringEmptyArrayAsString()
38
    {
39
        $expected = "String must be a string";
40
        $actual = null;
41
42
        $foo = new TOperandType();
43
        try {
44
            $foo->setString([]);
1 ignored issue
show
Documentation introduced by
array() is of type array, but the function expects a string.

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...
45
        } catch (\InvalidArgumentException $e) {
46
            $actual = $e->getMessage();
47
        }
48
        $this->assertEquals($expected, $actual);
49
    }
50
51
    public function testSetStringNonEmptyArrayAsString()
52
    {
53
        $expected = "String must be a string";
54
        $actual = null;
55
56
        $foo = new TOperandType();
57
        try {
58
            $foo->setString(['a']);
1 ignored issue
show
Documentation introduced by
array('a') is of type array<integer,string,{"0":"string"}>, but the function expects a string.

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...
59
        } catch (\InvalidArgumentException $e) {
60
            $actual = $e->getMessage();
61
        }
62
        $this->assertEquals($expected, $actual);
63
    }
64
65
    public function testSetStringObjectAsString()
66
    {
67
        $expected = "String must be a string";
68
        $actual = null;
69
70
        $foo = new TOperandType();
71
        try {
72
            $foo->setString(new \DateTime());
1 ignored issue
show
Documentation introduced by
new \DateTime() is of type object<DateTime>, but the function expects a string.

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...
73
        } catch (\InvalidArgumentException $e) {
74
            $actual = $e->getMessage();
75
        }
76
        $this->assertEquals($expected, $actual);
77
    }
78
79
    public function testSetGetBinaryRoundTrip()
80
    {
81
        $expected = 'zyxvut';
82
        $foo = new TOperandType();
83
        $foo->setBinary("zyxvut");
84
        $this->assertEquals($expected, $foo->getBinary());
85
    }
86
87
    public function testSetGetIntRoundTrip()
88
    {
89
        $expected = 'zyxvut';
90
        $foo = new TOperandType();
91
        $foo->setInt("zyxvut");
92
        $this->assertEquals($expected, $foo->getInt());
93
    }
94
95
    public function testSetGetFloatRoundTrip()
96
    {
97
        $expected = 'zyxvut';
98
        $foo = new TOperandType();
99
        $foo->setFloat("zyxvut");
100
        $this->assertEquals($expected, $foo->getFloat());
101
    }
102
103
    public function testSetGetDecimalRoundTrip()
104
    {
105
        $expected = 'zyxvut';
106
        $foo = new TOperandType();
107
        $foo->setDecimal("zyxvut");
108
        $this->assertEquals($expected, $foo->getDecimal());
109
    }
110
111
    public function testSetGetBoolRoundTrip()
112
    {
113
        $foo = new TOperandType();
114
        $foo->setBool(null);
1 ignored issue
show
Documentation introduced by
null is of type null, but the function expects a boolean.

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...
115
        $this->assertFalse($foo->getBool());
116
    }
117
118
    public function testSetGetDateTimeRoundTrip()
119
    {
120
        $expected = new \DateTime();
121
        $foo = new TOperandType();
122
        $foo->setDateTime($expected);
123
        $this->assertEquals($expected, $foo->getDateTime());
124
    }
125
126
    public function testSetGetDateTimeOffsetRoundTrip()
127
    {
128
        $expected = new \DateTime();
129
        $foo = new TOperandType();
130
        $foo->setDateTimeOffset($expected);
131
        $this->assertEquals($expected, $foo->getDateTimeOffset());
132
    }
133
134 View Code Duplication
    public function testSetBadIf()
0 ignored issues
show
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...
135
    {
136
        $expected = "";
137
        $actual = null;
138
139
        $if = m::mock(TIfExpressionType::class);
140
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
141
142
        $foo = new TOperandType();
143
144
        try {
145
            $foo->setIf($if);
146
        } catch (\InvalidArgumentException $e) {
147
            $actual = $e->getMessage();
148
        }
149
        $this->assertEquals($expected, $actual);
150
    }
151
152 View Code Duplication
    public function testSetGetIfRoundTrip()
0 ignored issues
show
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...
153
    {
154
        $if = m::mock(TIfExpressionType::class);
155
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
156
157
        $foo = new TOperandType();
158
        $foo->setIf($if);
159
        $result = $foo->getIf();
160
        $this->assertTrue($result instanceof TIfExpressionType, get_class($result));
161
        $this->assertTrue($result->isOK());
162
    }
163
164 View Code Duplication
    public function testSetBadRecord()
0 ignored issues
show
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...
165
    {
166
        $expected = "";
167
        $actual = null;
168
169
        $if = m::mock(TRecordExpressionType::class);
170
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
171
172
        $foo = new TOperandType();
173
174
        try {
175
            $foo->setRecord($if);
176
        } catch (\InvalidArgumentException $e) {
177
            $actual = $e->getMessage();
178
        }
179
        $this->assertEquals($expected, $actual);
180
    }
181
182 View Code Duplication
    public function testSetGetRecordRoundTrip()
0 ignored issues
show
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...
183
    {
184
        $if = m::mock(TRecordExpressionType::class);
185
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
186
187
        $foo = new TOperandType();
188
        $foo->setRecord($if);
189
        $result = $foo->getRecord();
190
        $this->assertTrue($result instanceof TRecordExpressionType, get_class($result));
191
        $this->assertTrue($result->isOK());
192
    }
193
194 View Code Duplication
    public function testSetBadCollection()
0 ignored issues
show
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...
195
    {
196
        $expected = "";
197
        $actual = null;
198
199
        $if = m::mock(TCollectionExpressionType::class);
200
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
201
202
        $foo = new TOperandType();
203
204
        try {
205
            $foo->setCollection($if);
206
        } catch (\InvalidArgumentException $e) {
207
            $actual = $e->getMessage();
208
        }
209
        $this->assertEquals($expected, $actual);
210
    }
211
212 View Code Duplication
    public function testSetGetCollectionRoundTrip()
0 ignored issues
show
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...
213
    {
214
        $if = m::mock(TCollectionExpressionType::class);
215
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
216
217
        $foo = new TOperandType();
218
        $foo->setCollection($if);
219
        $result = $foo->getCollection();
220
        $this->assertTrue($result instanceof TCollectionExpressionType, get_class($result));
221
        $this->assertTrue($result->isOK());
222
    }
223
224 View Code Duplication
    public function testSetBadTypeAssert()
0 ignored issues
show
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...
225
    {
226
        $expected = "";
227
        $actual = null;
228
229
        $if = m::mock(TTypeAssertExpressionType::class);
230
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
231
232
        $foo = new TOperandType();
233
234
        try {
235
            $foo->setTypeAssert($if);
236
        } catch (\InvalidArgumentException $e) {
237
            $actual = $e->getMessage();
238
        }
239
        $this->assertEquals($expected, $actual);
240
    }
241
242 View Code Duplication
    public function testSetGetTypeAssertRoundTrip()
0 ignored issues
show
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...
243
    {
244
        $if = m::mock(TTypeAssertExpressionType::class);
245
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
246
247
        $foo = new TOperandType();
248
        $foo->setTypeAssert($if);
249
        $result = $foo->getTypeAssert();
250
        $this->assertTrue($result instanceof TTypeAssertExpressionType, get_class($result));
251
        $this->assertTrue($result->isOK());
252
    }
253
254 View Code Duplication
    public function testSetBadTypeTest()
0 ignored issues
show
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...
255
    {
256
        $expected = "";
257
        $actual = null;
258
259
        $if = m::mock(TTypeTestExpressionType::class);
260
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
261
262
        $foo = new TOperandType();
263
264
        try {
265
            $foo->setTypeTest($if);
266
        } catch (\InvalidArgumentException $e) {
267
            $actual = $e->getMessage();
268
        }
269
        $this->assertEquals($expected, $actual);
270
    }
271
272 View Code Duplication
    public function testSetGetTypeTestRoundTrip()
0 ignored issues
show
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...
273
    {
274
        $if = m::mock(TTypeTestExpressionType::class);
275
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
276
277
        $foo = new TOperandType();
278
        $foo->setTypeTest($if);
279
        $result = $foo->getTypeTest();
280
        $this->assertTrue($result instanceof TTypeTestExpressionType, get_class($result));
281
        $this->assertTrue($result->isOK());
282
    }
283
284 View Code Duplication
    public function testSetBadFunctionReference()
0 ignored issues
show
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...
285
    {
286
        $expected = "";
287
        $actual = null;
288
289
        $if = m::mock(TFunctionReferenceExpressionType::class);
290
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
291
292
        $foo = new TOperandType();
293
294
        try {
295
            $foo->setFunctionReference($if);
296
        } catch (\InvalidArgumentException $e) {
297
            $actual = $e->getMessage();
298
        }
299
        $this->assertEquals($expected, $actual);
300
    }
301
302 View Code Duplication
    public function testSetGetFunctionReferenceRoundTrip()
0 ignored issues
show
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...
303
    {
304
        $if = m::mock(TFunctionReferenceExpressionType::class);
305
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
306
307
        $foo = new TOperandType();
308
        $foo->setFunctionReference($if);
309
        $result = $foo->getFunctionReference();
310
        $this->assertTrue($result instanceof TFunctionReferenceExpressionType, get_class($result));
311
        $this->assertTrue($result->isOK());
312
    }
313
314 View Code Duplication
    public function testSetBadEntitySetReference()
0 ignored issues
show
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...
315
    {
316
        $expected = "";
317
        $actual = null;
318
319
        $if = m::mock(TEntitySetReferenceExpressionType::class);
320
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
321
322
        $foo = new TOperandType();
323
324
        try {
325
            $foo->setEntitySetReference($if);
326
        } catch (\InvalidArgumentException $e) {
327
            $actual = $e->getMessage();
328
        }
329
        $this->assertEquals($expected, $actual);
330
    }
331
332 View Code Duplication
    public function testSetGetEntitySetReferenceRoundTrip()
0 ignored issues
show
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...
333
    {
334
        $if = m::mock(TEntitySetReferenceExpressionType::class);
335
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
336
337
        $foo = new TOperandType();
338
        $foo->setEntitySetReference($if);
339
        $result = $foo->getEntitySetReference();
340
        $this->assertTrue($result instanceof TEntitySetReferenceExpressionType, get_class($result));
341
        $this->assertTrue($result->isOK());
342
    }
343
344 View Code Duplication
    public function testSetBadAnonymousFunction()
0 ignored issues
show
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...
345
    {
346
        $expected = "";
347
        $actual = null;
348
349
        $if = m::mock(TAnonymousFunctionExpressionType::class);
350
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
351
352
        $foo = new TOperandType();
353
354
        try {
355
            $foo->setAnonymousFunction($if);
356
        } catch (\InvalidArgumentException $e) {
357
            $actual = $e->getMessage();
358
        }
359
        $this->assertEquals($expected, $actual);
360
    }
361
362 View Code Duplication
    public function testSetGetAnonymousFunctionRoundTrip()
0 ignored issues
show
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...
363
    {
364
        $if = m::mock(TAnonymousFunctionExpressionType::class);
365
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
366
367
        $foo = new TOperandType();
368
        $foo->setAnonymousFunction($if);
369
        $result = $foo->getAnonymousFunction();
370
        $this->assertTrue($result instanceof TAnonymousFunctionExpressionType, get_class($result));
371
        $this->assertTrue($result->isOK());
372
    }
373
374 View Code Duplication
    public function testSetBadParameterReference()
0 ignored issues
show
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...
375
    {
376
        $expected = "";
377
        $actual = null;
378
379
        $if = m::mock(TParameterReferenceExpressionType::class);
380
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
381
382
        $foo = new TOperandType();
383
384
        try {
385
            $foo->setParameterReference($if);
386
        } catch (\InvalidArgumentException $e) {
387
            $actual = $e->getMessage();
388
        }
389
        $this->assertEquals($expected, $actual);
390
    }
391
392 View Code Duplication
    public function testSetGetParameterReferenceRoundTrip()
0 ignored issues
show
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...
393
    {
394
        $if = m::mock(TParameterReferenceExpressionType::class);
395
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
396
397
        $foo = new TOperandType();
398
        $foo->setParameterReference($if);
399
        $result = $foo->getParameterReference();
400
        $this->assertTrue($result instanceof TParameterReferenceExpressionType, get_class($result));
401
        $this->assertTrue($result->isOK());
402
    }
403
404 View Code Duplication
    public function testSetBadApply()
0 ignored issues
show
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...
405
    {
406
        $expected = "";
407
        $actual = null;
408
409
        $if = m::mock(TApplyExpressionType::class);
410
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
411
412
        $foo = new TOperandType();
413
414
        try {
415
            $foo->setApply($if);
416
        } catch (\InvalidArgumentException $e) {
417
            $actual = $e->getMessage();
418
        }
419
        $this->assertEquals($expected, $actual);
420
    }
421
422 View Code Duplication
    public function testSetGetApplyRoundTrip()
0 ignored issues
show
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...
423
    {
424
        $if = m::mock(TApplyExpressionType::class);
425
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
426
427
        $foo = new TOperandType();
428
        $foo->setApply($if);
429
        $result = $foo->getApply();
430
        $this->assertTrue($result instanceof TApplyExpressionType, get_class($result));
431
        $this->assertTrue($result->isOK());
432
    }
433
434 View Code Duplication
    public function testSetBadPropertyReference()
0 ignored issues
show
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...
435
    {
436
        $expected = "";
437
        $actual = null;
438
439
        $if = m::mock(TPropertyReferenceExpressionType::class);
440
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
441
442
        $foo = new TOperandType();
443
444
        try {
445
            $foo->setPropertyReference($if);
446
        } catch (\InvalidArgumentException $e) {
447
            $actual = $e->getMessage();
448
        }
449
        $this->assertEquals($expected, $actual);
450
    }
451
452 View Code Duplication
    public function testSetGetPropertyReferenceRoundTrip()
0 ignored issues
show
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...
453
    {
454
        $if = m::mock(TPropertyReferenceExpressionType::class);
455
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
456
457
        $foo = new TOperandType();
458
        $foo->setPropertyReference($if);
459
        $result = $foo->getPropertyReference();
460
        $this->assertTrue($result instanceof TPropertyReferenceExpressionType, get_class($result));
461
        $this->assertTrue($result->isOK());
462
    }
463
464 View Code Duplication
    public function testSetBadValueTermReference()
0 ignored issues
show
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...
465
    {
466
        $expected = "";
467
        $actual = null;
468
469
        $if = m::mock(TValueTermReferenceExpressionType::class);
470
        $if->shouldReceive('isOK')->andReturn(false);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
471
472
        $foo = new TOperandType();
473
474
        try {
475
            $foo->setValueTermReference($if);
476
        } catch (\InvalidArgumentException $e) {
477
            $actual = $e->getMessage();
478
        }
479
        $this->assertEquals($expected, $actual);
480
    }
481
482 View Code Duplication
    public function testSetGetValueTermReferenceRoundTrip()
0 ignored issues
show
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...
483
    {
484
        $if = m::mock(TValueTermReferenceExpressionType::class);
485
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
486
487
        $foo = new TOperandType();
488
        $foo->setValueTermReference($if);
489
        $result = $foo->getValueTermReference();
490
        $this->assertTrue($result instanceof TValueTermReferenceExpressionType, get_class($result));
491
        $this->assertTrue($result->isOK());
492
    }
493
494
    public function testGExpressionNotValidWhenMoreThanOneBasicExpressionSet()
495
    {
496
        $expected = '2 fields not null.  Need maximum of 1: AlgoWeb\ODataMetadata\MetadataV3\edm\TOperandType';
497
        $actual = null;
498
499
        $if = m::mock(TValueTermReferenceExpressionType::class);
500
        $if->shouldReceive('isOK')->andReturn(true);
1 ignored issue
show
Bug introduced by
The method andReturn does only exist in Mockery\ExpectationInterface, but not in Mockery\HigherOrderMessage.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
501
502
        $apply = m::mock(TApplyExpressionType::class);
503
        $apply->shouldReceive('isOK')->andReturn(true);
504
505
        $foo = new TOperandType();
506
        $foo->setValueTermReference($if);
507
        $foo->setApply($apply);
508
509
        $this->assertFalse($foo->isGExpressionValid($actual));
510
        $this->assertEquals($expected, $actual);
511
    }
512
513
    public function testSetBadEnum()
514
    {
515
        $expected = "Enum must be a valid TQualifiedName";
516
        $actual = null;
517
518
        $foo = new TOperandType();
519
        try {
520
            $foo->setEnum(' _ ');
521
        } catch (\InvalidArgumentException $e) {
522
            $actual = $e->getMessage();
523
        }
524
        $this->assertEquals($expected, $actual);
525
    }
526
527
    public function testSetGetEnumRoundTrip()
528
    {
529
        $expected = "Org.OData.Publication.V1.DocumentationUrl";
530
531
        $foo = new TOperandType();
532
        $foo->setEnum($expected);
533
        $actual = $foo->getEnum();
534
535
        $this->assertEquals($expected, $actual);
536
    }
537
538
    public function testSetBadPath()
539
    {
540
        $expected = "Path must be a valid TQualifiedName";
541
        $actual = null;
542
543
        $foo = new TOperandType();
544
        try {
545
            $foo->setPath(' _ ');
546
        } catch (\InvalidArgumentException $e) {
547
            $actual = $e->getMessage();
548
        }
549
        $this->assertEquals($expected, $actual);
550
    }
551
552
    public function testSetGetPathRoundTrip()
553
    {
554
        $expected = "Org.OData.Publication.V1.DocumentationUrl";
555
556
        $foo = new TOperandType();
557
        $foo->setPath($expected);
558
        $actual = $foo->getPath();
559
560
        $this->assertEquals($expected, $actual);
561
    }
562
563
    public function testSetBadGuid()
564
    {
565
        $expected = "Guid must be a valid TGuidLiteral";
566
        $actual = null;
567
568
        $foo = new TOperandType();
569
        try {
570
            $foo->setGuid(' _ ');
571
        } catch (\InvalidArgumentException $e) {
572
            $actual = $e->getMessage();
573
        }
574
        $this->assertEquals($expected, $actual);
575
    }
576
577
    public function testSetGetGuidRoundTrip()
578
    {
579
        $expected = "00000000-0000-0000-0000-000000000000";
580
        $actual = null;
0 ignored issues
show
Unused Code introduced by
$actual is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
581
582
        $foo = new TOperandType();
583
        $foo->setGuid($expected);
584
        $actual = $foo->getGuid();
585
        $this->assertEquals($expected, $actual);
586
    }
587
}
588