ManagesOrganizations::findOrCreateOrganization()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 7
Ratio 70 %

Importance

Changes 0
Metric Value
dl 7
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace TestMonitor\ActiveCampaign\Actions;
4
5
use TestMonitor\ActiveCampaign\Resources\Organization;
6
7
/** @deprecated use ManageAccounts instead */
8 View Code Duplication
trait ManagesOrganizations
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    use ImplementsActions;
11
12
    /**
13
     * Get all organizations.
14
     *
15
     * @deprecated use accounts() instead
16
     * @return array
17
     */
18
    public function organizations()
19
    {
20
        return $this->transformCollection(
21
            $this->get('organizations'),
22
            Organization::class,
23
            'organizations'
24
        );
25
    }
26
27
    /**
28
     * Find organization by name.
29
     *
30
     * @param string $name
31
     *
32
     * @deprecated use findAccount() instead
33
     * @return Organization|null
34
     */
35
    public function findOrganization($name)
36
    {
37
        $organizations = $this->transformCollection(
38
            $this->get('organizations', ['query' => ['filters' => ['name' => $name]]]),
39
            Organization::class,
40
            'organizations'
41
        );
42
43
        return array_shift($organizations);
44
    }
45
46
    /**
47
     * Create new organization.
48
     *
49
     * @param array $data
50
     *
51
     * @deprecated use createAccount() instead
52
     * @return Organization|null
53
     */
54
    public function createOrganization(array $data = [])
55
    {
56
        $organizations = $this->transformCollection(
57
            $this->post('organizations', ['json' => ['organization' => $data]]),
58
            Organization::class
59
        );
60
61
        return array_shift($organizations);
62
    }
63
64
    /**
65
     * Find or create an organization.
66
     *
67
     * @param $name
68
     *
69
     * @deprecated use findOrCreateAccount() instead
70
     * @return Organization
71
     */
72
    public function findOrCreateOrganization($name)
73
    {
74
        $organization = $this->findOrganization($name);
0 ignored issues
show
Deprecated Code introduced by
The method TestMonitor\ActiveCampai...ons::findOrganization() has been deprecated with message: use findAccount() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
75
76
        if ($organization instanceof Organization) {
77
            return $organization;
78
        }
79
80
        return $this->createOrganization(['name' => $name]);
0 ignored issues
show
Deprecated Code introduced by
The method TestMonitor\ActiveCampai...s::createOrganization() has been deprecated with message: use createAccount() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
81
    }
82
}
83