Completed
Pull Request — master (#18)
by
unknown
01:02
created

ManagesLists::unsubscribe()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace TestMonitor\ActiveCampaign\Actions;
4
5
use TestMonitor\ActiveCampaign\Resources\Contact;
6
use TestMonitor\ActiveCampaign\Resources\ContactsList;
7
8
trait ManagesLists
9
{
10
    /**
11
     * Returns all lists
12
     *
13
     * @return ContactsList[]
14
     */
15
    public function lists()
16
    {
17
        return $this->transformCollection(
0 ignored issues
show
Bug introduced by
It seems like transformCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
18
            $this->get('lists'),
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
19
            ContactsList::class,
20
            'lists'
21
        );
22
    }
23
24
    /**
25
     * Returns list by ID
26
     *
27
     * @param string $name
0 ignored issues
show
Bug introduced by
There is no parameter named $name. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
28
     *
29
     * @return ContactsList|null
30
     */
31
    public function getList($id)
32
    {
33
        try
34
        {
35
            $lists = $this->get('lists/' . $id);
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
36
37
            if (isset($lists['list']) && count($lists['list']))
38
            {
39
                return new ContactsList($lists['list']);
40
            }
41
        }
42
        catch (\TestMonitor\ActiveCampaign\Exceptions\NotFoundException $e)
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
43
        {
44
        }
45
46
        return null;
47
    }
48
49
    /**
50
     * Finds list by it's name or URL-safe name
51
     *
52
     * @param string $name name of list to find
53
     *
54
     * @return null|ContactsList
55
     */
56
    public function findList($name)
57
    {
58
        $lists = $this->transformCollection(
0 ignored issues
show
Bug introduced by
It seems like transformCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
59
            $this->get('lists', ['query' => ['filters[name]' => $name]]),
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
60
            ContactsList::class,
61
            'lists'
62
        );
63
64
        return array_shift($lists);
65
    }
66
67
    /**
68
     * Creates a new list
69
     *
70
     * @param string $name Name of the list to create
71
     * @param string $senderUrl The website URL this list is for.
72
     * @param array  $params other options to create list
73
     *
74
     * @return ContactsList
75
     */
76
    public function createList($name, $senderUrl, $params = [])
77
    {
78
        $params['name'] = $name;
79
        if (!isset($params['stringid']))
80
        {
81
            $params['stringid'] = strtolower(preg_replace('/[^A-Z0-9]+/i', '-', $name));
82
        }
83
        $params['sender_url'] = $senderUrl;
84
        $params['sender_reminder'] = 'You signed up for my mailing list.';
85
86
        $lists = $this->transformCollection(
0 ignored issues
show
Bug introduced by
It seems like transformCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
87
            $this->post('lists', ['json' => ['list' => $params]]),
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
88
            ContactsList::class
89
        );
90
91
        return array_shift($lists);
92
93
    }
94
95
    /**
96
     * Removes list
97
     *
98
     * @param int $id ID of the list to delete
99
     *
100
     * @throws \TestMonitor\ActiveCampaign\Exceptions\NotFoundException
101
     */
102
    public function deleteList($id)
103
    {
104
        $this->delete('lists/' . $id);
0 ignored issues
show
Bug introduced by
The method delete() does not exist on TestMonitor\ActiveCampaign\Actions\ManagesLists. Did you maybe mean deleteList()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
105
    }
106
107
    /**
108
     * Adds contact to the list
109
     *
110
     * @param int $contactId ID of contact to add to list
111
     * @param int $listId    ID of list to add contact to
112
     */
113 View Code Duplication
    public function subscribe($contactId, $listId)
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...
114
    {
115
        $this->post('contactLists', ['json' => [
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
116
            'contactList' => [
117
                'list' => $listId,
118
                'contact' => $contactId,
119
                'status' => 1,
120
            ]]]);
121
    }
122
123
    /**
124
     * Remove contact from the list
125
     *
126
     * @param int $contactId ID of contact to remove from list
127
     * @param int $listId ID of list to remove contact from
128
     */
129 View Code Duplication
    public function unsubscribe($contactId, $listId)
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...
130
    {
131
        $this->post('contactLists', ['json' => [
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
132
            'contactList' => [
133
                'list' => $listId,
134
                'contact' => $contactId,
135
                'status' => 2,
136
            ]]]);
137
    }
138
139
    /**
140
     * Get all contacts related to the list.
141
     *
142
     * @return Contact[]
143
     */
144
    public function contactsByList($listId)
145
    {
146
        return $this->transformCollection(
0 ignored issues
show
Bug introduced by
It seems like transformCollection() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
147
            $this->get('contacts', ['query' => ['listid' => $listId]]),
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
148
            Contact::class,
149
            'contacts'
150
        );
151
    }
152
}