Completed
Pull Request — master (#1)
by Gaël
01:15
created

it_can_subscribe_or_update_someone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26

Duplication

Lines 26
Ratio 100 %

Importance

Changes 0
Metric Value
dl 26
loc 26
c 0
b 0
f 0
rs 9.504
cc 1
nc 1
nop 0
1
<?php
2
3
namespace DansMaCulotte\Newsletter\Test;
4
5
use Mockery;
6
use DrewM\MailChimp\MailChimp;
7
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DansMaCulotte\Newsletter\Test\TestCase.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
8
use DansMaCulotte\Newsletter\Drivers\MailchimpDriver;
9
use DansMaCulotte\Newsletter\Exceptions\ApiError;
10
use DansMaCulotte\Newsletter\Newsletter;
11
12
class NewsletterTest extends TestCase
13
{
14
    protected $driver;
15
16
    /** @var Mockery\Mock */
17
    protected $client;
18
19
    /** @var \DansMaCulotte\Newsletter\Newsletter */
20
    protected $newsletter;
21
22
    public function setUp() : void
23
    {
24
        $this->client = Mockery::mock(MailChimp::class);
25
26
        $this->driver = new MailchimpDriver([
27
            'apiKey' => 'test-ApiKey',
28
            'ssl' => false,
29
        ], [
30
            'lists' => [
31
                'list1' => ['id' => 123],
32
                'list2' => ['id' => 456],
33
            ],
34
            'defaultList' => 'list1',
35
        ]);
36
37
        $this->driver->client = $this->client;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->client of type object<Mockery\LegacyMockInterface> is incompatible with the declared type object<DrewM\MailChimp\MailChimp> of property $client.

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...
38
39
        $this->newsletter = new Newsletter($this->driver);
40
    }
41
42
    public function tearDown() : void
43
    {
44
        parent::tearDown();
45
46
        if ($container = Mockery::getContainer()) {
47
            $this->addToAssertionCount($container->mockery_getExpectationCount());
48
        }
49
50
        Mockery::close();
51
    }
52
53
    /** @test */
54
    public function it_can_subscribe_someone()
55
    {
56
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
57
58
        $email = '[email protected]';
59
60
        $url = 'lists/123/members';
61
62
        $this->client->shouldReceive('post')->withArgs([
0 ignored issues
show
Bug introduced by
The method withArgs does only exist in Mockery\HigherOrderMessage, but not in Mockery\CompositeExpectation.

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...
63
            $url,
64
            [
65
                'email_address' => $email,
66
                'status' => 'subscribed',
67
                'email_type' => 'html',
68
            ],
69
        ]);
70
71
        $this->newsletter->subscribe($email);
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
72
    }
73
74
    /** @test */
75
    public function it_will_throw_an_error_when_subscribe_someone()
76
    {
77
        $this->client->shouldReceive('success')->andReturn(false);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
78
        $this->client->shouldReceive('getLastError')->andReturn('Error');
79
80
        $email = 'freekspatie.be';
81
82
        $url = 'lists/123/members';
83
84
        $this->client->shouldReceive('post')->withArgs([
0 ignored issues
show
Bug introduced by
The method withArgs does only exist in Mockery\HigherOrderMessage, but not in Mockery\CompositeExpectation.

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...
85
            $url,
86
            [
87
                'email_address' => $email,
88
                'status' => 'subscribed',
89
                'email_type' => 'html',
90
            ],
91
        ]);
92
93
        $this->expectExceptionObject(ApiError::responseError('Error', 'mailchimp'));
94
        $this->newsletter->subscribe($email);
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
95
    }
96
97
    /** @test */
98 View Code Duplication
    public function it_can_subscribe_someone_as_pending()
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...
99
    {
100
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
101
102
        $email = '[email protected]';
103
104
        $url = 'lists/123/members';
105
106
        $options = [
107
            'status' => 'pending'
108
        ];
109
110
        $this->client->shouldReceive('post')->withArgs([
0 ignored issues
show
Bug introduced by
The method withArgs does only exist in Mockery\HigherOrderMessage, but not in Mockery\CompositeExpectation.

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...
111
            $url,
112
            [
113
                'email_address' => $email,
114
                'status' => 'pending',
115
                'email_type' => 'html',
116
            ],
117
        ]);
118
119
        $this->newsletter->subscribe($email, $options);
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
120
    }
121
122
    /** @test */
123 View Code Duplication
    public function it_can_subscribe_or_update_someone()
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...
124
    {
125
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
126
127
        $email = '[email protected]';
128
129
        $url = 'lists/123/members';
130
131
        $subscriberHash = 'abc123';
132
133
        $this->client->shouldReceive('subscriberHash')
134
            ->once()
135
            ->withArgs([$email])
136
            ->andReturn($subscriberHash);
137
138
        $this->client->shouldReceive('put')->withArgs([
0 ignored issues
show
Bug introduced by
The method withArgs does only exist in Mockery\HigherOrderMessage, but not in Mockery\CompositeExpectation.

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...
139
            "{$url}/{$subscriberHash}",
140
            [
141
                'email_address' => $email,
142
                'status' => 'subscribed',
143
                'email_type' => 'html',
144
            ],
145
        ]);
146
147
        $this->newsletter->subscribeOrUpdate($email);
0 ignored issues
show
Documentation Bug introduced by
The method subscribeOrUpdate does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
148
    }
149
150
    /** @test */
151
    public function it_can_subscribe_someone_with_merge_fields()
152
    {
153
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
154
155
        $email = '[email protected]';
156
157
        $options = [
158
            'merge_fields' => [
159
                'FNAME' => 'Freek'
160
            ]
161
        ];
162
163
        $url = 'lists/123/members';
164
165
        $this->client->shouldReceive('post')
166
            ->once()
167
            ->withArgs([
168
                $url,
169
                [
170
                    'email_address' => $email,
171
                    'status' => 'subscribed',
172
                    'merge_fields' => $options['merge_fields'],
173
                    'email_type' => 'html',
174
                ],
175
            ]);
176
177
        $this->newsletter->subscribe($email, $options);
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
178
    }
179
180
    /** @test */
181
    public function it_can_subscribe_or_update_someone_with_merge_fields()
182
    {
183
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
184
185
        $email = '[email protected]';
186
187
        $options = [
188
            'merge_fields' => [
189
                'FNAME' => 'Freek'
190
            ]
191
        ];
192
193
        $url = 'lists/123/members';
194
195
        $subscriberHash = 'abc123';
196
197
        $this->client->shouldReceive('subscriberHash')
198
            ->once()
199
            ->withArgs([$email])
200
            ->andReturn($subscriberHash);
201
202
        $this->client->shouldReceive('put')
203
            ->once()
204
            ->withArgs([
205
                "{$url}/{$subscriberHash}",
206
                [
207
                    'email_address' => $email,
208
                    'status' => 'subscribed',
209
                    'merge_fields' => $options['merge_fields'],
210
                    'email_type' => 'html',
211
                ],
212
            ]);
213
214
        $this->newsletter->subscribeOrUpdate($email, $options);
0 ignored issues
show
Documentation Bug introduced by
The method subscribeOrUpdate does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
215
    }
216
217
    /** @test */
218
    public function it_will_throw_an_error_when_subscribe_or_update_someone_with_merge_fields()
219
    {
220
        $this->client->shouldReceive('success')->andReturn(false);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
221
        $this->client->shouldReceive('getLastError')->andReturn('Error');
222
223
        $email = 'freekspatie.be';
224
225
        $options = [
226
            'merge_fields' => [
227
                'FNAME' => 'Freek'
228
            ]
229
        ];
230
231
        $url = 'lists/123/members';
232
233
        $subscriberHash = 'abc123';
234
235
        $this->client->shouldReceive('subscriberHash')
236
            ->once()
237
            ->withArgs([$email])
238
            ->andReturn($subscriberHash);
239
240
        $this->client->shouldReceive('put')
241
            ->once()
242
            ->withArgs([
243
                "{$url}/{$subscriberHash}",
244
                [
245
                    'email_address' => $email,
246
                    'status' => 'subscribed',
247
                    'merge_fields' => $options['merge_fields'],
248
                    'email_type' => 'html',
249
                ],
250
            ]);
251
252
        $this->expectExceptionObject(ApiError::responseError('Error', 'mailchimp'));
253
        $this->newsletter->subscribeOrUpdate($email, $options);
0 ignored issues
show
Documentation Bug introduced by
The method subscribeOrUpdate does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
254
    }
255
256
    /** @test */
257 View Code Duplication
    public function it_can_subscribe_someone_to_an_alternative_list()
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...
258
    {
259
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
260
261
        $email = '[email protected]';
262
263
        $url = 'lists/456/members';
264
265
        $this->client->shouldReceive('post')
266
            ->once()
267
            ->withArgs([
268
                $url,
269
                [
270
                    'email_address' => $email,
271
                    'status' => 'subscribed',
272
                    'email_type' => 'html',
273
                ],
274
            ]);
275
276
        $this->newsletter->subscribe($email, [], 'list2');
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
277
    }
278
279
    /** @test */
280 View Code Duplication
    public function it_can_subscribe_or_update_someone_to_an_alternative_list()
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...
281
    {
282
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
283
284
        $email = '[email protected]';
285
286
        $url = 'lists/456/members';
287
288
        $subscriberHash = 'abc123';
289
290
        $this->client->shouldReceive('subscriberHash')
291
            ->once()
292
            ->withArgs([$email])
293
            ->andReturn($subscriberHash);
294
295
        $this->client->shouldReceive('put')
296
            ->once()
297
            ->withArgs([
298
                "{$url}/{$subscriberHash}",
299
                [
300
                    'email_address' => $email,
301
                    'status' => 'subscribed',
302
                    'email_type' => 'html',
303
                ],
304
            ]);
305
306
        $this->newsletter->subscribeOrUpdate($email, [], 'list2');
0 ignored issues
show
Documentation Bug introduced by
The method subscribeOrUpdate does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
307
    }
308
309
    /** @test */
310
    public function it_can_override_the_defaults_when_subscribing_someone()
311
    {
312
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
313
314
        $email = '[email protected]';
315
316
        $url = 'lists/123/members';
317
318
        $this->client->shouldReceive('post')
319
            ->once()
320
            ->withArgs([
321
                $url,
322
                [
323
                    'email_address' => $email,
324
                    'status' => 'pending',
325
                    'email_type' => 'text',
326
                ],
327
            ]);
328
329
        $this->newsletter->subscribe($email, ['email_type' => 'text', 'status' => 'pending']);
0 ignored issues
show
Documentation Bug introduced by
The method subscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
330
    }
331
332
    /** @test */
333
    public function it_can_override_the_defaults_when_subscribing_or_updating_someone()
334
    {
335
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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
        $email = '[email protected]';
338
339
        $url = 'lists/123/members';
340
341
        $subscriberHash = 'abc123';
342
343
        $this->client->shouldReceive('subscriberHash')
344
            ->once()
345
            ->withArgs([$email])
346
            ->andReturn($subscriberHash);
347
348
        $this->client->shouldReceive('put')
349
            ->once()
350
            ->withArgs([
351
                "{$url}/{$subscriberHash}",
352
                [
353
                    'email_address' => $email,
354
                    'status' => 'pending',
355
                    'email_type' => 'text',
356
                ],
357
            ]);
358
359
        $this->newsletter->subscribeOrUpdate($email, ['email_type' => 'text', 'status' => 'pending']);
0 ignored issues
show
Documentation Bug introduced by
The method subscribeOrUpdate does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
360
    }
361
362
363
    /** @test */
364
    public function it_can_unsubscribe_someone()
365
    {
366
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
367
368
        $email = '[email protected]';
369
370
        $subscriberHash = 'abc123';
371
372
        $this->client->shouldReceive('subscriberHash')
373
            ->once()
374
            ->withArgs([$email])
375
            ->andReturn($subscriberHash);
376
377
        $this->client
378
            ->shouldReceive('patch')
379
            ->once()
380
            ->withArgs([
381
                "lists/123/members/{$subscriberHash}",
382
                [
383
                    'status' => 'unsubscribed',
384
                ],
385
            ]);
386
387
        $this->newsletter->unsubscribe('[email protected]');
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
388
    }
389
390
    /** @test */
391
    public function it_will_throw_an_error_when_unsubscribe_someone()
392
    {
393
        $this->client->shouldReceive('success')->andReturn(false);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
394
        $this->client->shouldReceive('getLastError')->andReturn('Error');
395
396
        $email = '[email protected]';
397
398
        $subscriberHash = 'abc123';
399
400
        $this->client->shouldReceive('subscriberHash')
401
            ->once()
402
            ->withArgs([$email])
403
            ->andReturn($subscriberHash);
404
405
        $this->client
406
            ->shouldReceive('patch')
407
            ->once()
408
            ->withArgs([
409
                "lists/123/members/{$subscriberHash}",
410
                [
411
                    'status' => 'unsubscribed',
412
                ],
413
            ]);
414
415
        $this->expectExceptionObject(ApiError::responseError('Error', 'mailchimp'));
416
        $this->newsletter->unsubscribe('[email protected]');
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
417
    }
418
419
    /** @test */
420
    public function it_can_unsubscribe_someone_from_a_specific_list()
421
    {
422
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
423
424
        $email = '[email protected]';
425
426
        $subscriberHash = 'abc123';
427
428
        $this->client->shouldReceive('subscriberHash')
429
            ->once()
430
            ->withArgs([$email])
431
            ->andReturn($subscriberHash);
432
433
        $this->client
434
            ->shouldReceive('patch')
435
            ->once()
436
            ->withArgs([
437
                "lists/456/members/{$subscriberHash}",
438
                [
439
                    'status' => 'unsubscribed',
440
                ],
441
            ]);
442
443
        $this->newsletter->unsubscribe('[email protected]', 'list2');
0 ignored issues
show
Documentation Bug introduced by
The method unsubscribe does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
444
    }
445
446
    /** @test */
447 View Code Duplication
    public function it_can_delete_someone()
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...
448
    {
449
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
450
451
        $email = '[email protected]';
452
453
        $subscriberHash = 'abc123';
454
455
        $this->client->shouldReceive('subscriberHash')
456
            ->once()
457
            ->withArgs([$email])
458
            ->andReturn($subscriberHash);
459
460
        $this->client
461
            ->shouldReceive('delete')
462
            ->once()
463
            ->withArgs(["lists/123/members/{$subscriberHash}"]);
464
465
        $this->newsletter->delete('[email protected]');
0 ignored issues
show
Documentation Bug introduced by
The method delete does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
466
    }
467
468
    /** @test */
469 View Code Duplication
    public function it_can_delete_someone_from_a_specific_list()
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...
470
    {
471
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
472
473
        $email = '[email protected]';
474
475
        $subscriberHash = 'abc123';
476
477
        $this->client->shouldReceive('subscriberHash')
478
            ->once()
479
            ->withArgs([$email])
480
            ->andReturn($subscriberHash);
481
482
        $this->client
483
            ->shouldReceive('delete')
484
            ->once()
485
            ->withArgs(["lists/456/members/{$subscriberHash}"]);
486
487
        $this->newsletter->delete('[email protected]', 'list2');
0 ignored issues
show
Documentation Bug introduced by
The method delete does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
488
    }
489
490
    /** @test */
491
    public function it_exposes_the_api()
492
    {
493
        $api = $this->newsletter->getApi();
0 ignored issues
show
Documentation Bug introduced by
The method getApi does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
494
495
        $this->assertSame($this->client, $api);
496
    }
497
498
    /** @test */
499
    public function it_can_get_the_list_members()
500
    {
501
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
502
503
        $this->client
504
            ->shouldReceive('get')
505
            ->once()
506
            ->withArgs(['lists/123/members', []]);
507
508
        $this->newsletter->getMembers();
0 ignored issues
show
Documentation Bug introduced by
The method getMembers does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
509
    }
510
511
    /** @test */
512 View Code Duplication
    public function it_can_get_the_member()
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...
513
    {
514
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
515
516
        $email = '[email protected]';
517
518
        $subscriberHash = 'abc123';
519
520
        $this->client->shouldReceive('subscriberHash')
521
            ->once()
522
            ->withArgs([$email])
523
            ->andReturn($subscriberHash);
524
525
        $this->client
526
            ->shouldReceive('get')
527
            ->once()
528
            ->withArgs(["lists/123/members/{$subscriberHash}"]);
529
530
        $this->newsletter->getMember($email);
0 ignored issues
show
Documentation Bug introduced by
The method getMember does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
531
    }
532
533
534
    /** @test */
535 View Code Duplication
    public function it_can_get_the_member_from_a_specific_list()
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...
536
    {
537
        $this->client->shouldReceive('success')->andReturn(true);
0 ignored issues
show
Bug introduced by
The method andReturn does only exist in Mockery\CompositeExpectation, 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...
538
539
        $email = '[email protected]';
540
541
        $subscriberHash = 'abc123';
542
543
        $this->client->shouldReceive('subscriberHash')
544
            ->once()
545
            ->withArgs([$email])
546
            ->andReturn($subscriberHash);
547
548
        $this->client
549
            ->shouldReceive('get')
550
            ->once()
551
            ->withArgs(["lists/456/members/{$subscriberHash}"]);
552
553
        $this->newsletter->getMember($email, 'list2');
0 ignored issues
show
Documentation Bug introduced by
The method getMember does not exist on object<DansMaCulotte\Newsletter\Newsletter>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
554
    }
555
}
556