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 |
|
|
|
|
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); |
|
|
|
|
75
|
|
|
|
76
|
|
|
if ($organization instanceof Organization) { |
77
|
|
|
return $organization; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->createOrganization(['name' => $name]); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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.