This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use \DrewM\MailChimp\MailChimp; |
||
4 | |||
5 | class ChimpifyAdmin extends ModelAdmin |
||
0 ignored issues
–
show
|
|||
6 | { |
||
7 | private static $managed_models = [ |
||
0 ignored issues
–
show
|
|||
8 | 'ChimpifyCampaign', |
||
9 | ]; |
||
10 | |||
11 | private static $url_segment = 'mailchimp-campaigns'; |
||
0 ignored issues
–
show
|
|||
12 | |||
13 | private static $menu_title = 'MailChimp Campaigns'; |
||
0 ignored issues
–
show
|
|||
14 | |||
15 | public function getEditForm($id = null, $fields = null) |
||
16 | { |
||
17 | $form = parent::getEditForm($id, $fields); |
||
18 | |||
19 | $gridFieldName = $this->sanitiseClassName($this->modelClass); |
||
20 | $gridFieldConfig = $form->Fields()->fieldByName($gridFieldName)->getConfig(); |
||
21 | |||
22 | $gridFieldConfig->removeComponentsByType('GridFieldPrintButton'); |
||
23 | $gridFieldConfig->removeComponentsByType('GridFieldExportButton'); |
||
24 | $gridFieldConfig |
||
25 | ->getComponentByType('GridFieldAddNewButton') |
||
26 | ->setButtonName( |
||
27 | _t('Chimpify.ButtonLabelAddMailChimpCampaign', 'Add MailChimp Campaign') |
||
28 | ); |
||
29 | $gridFieldConfig |
||
30 | ->getComponentByType('GridFieldDetailForm') |
||
31 | ->setItemRequestClass('ChimpifyRequestHandler'); |
||
32 | |||
33 | return $form; |
||
34 | } |
||
35 | } |
||
36 | |||
37 | class ChimpifyRequestHandler extends GridFieldDetailForm_ItemRequest |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
38 | { |
||
39 | private static $allowed_actions = [ |
||
0 ignored issues
–
show
|
|||
40 | 'edit', |
||
41 | 'view', |
||
42 | 'ItemEditForm' |
||
43 | ]; |
||
44 | |||
45 | public function ItemEditForm() |
||
46 | { |
||
47 | $form = parent::ItemEditForm(); |
||
48 | |||
49 | if (!$this->record->ID) { |
||
50 | return $form; |
||
51 | } |
||
52 | |||
53 | $formActions = $form->Actions(); |
||
54 | |||
55 | if ($actions = $this->record->getCMSActions()) { |
||
56 | foreach ($actions as $action) { |
||
57 | $formActions->push($action); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | return $form; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Handles responses from the MailChimp API. |
||
66 | * |
||
67 | * @param MailChimp $mailChimp |
||
68 | * @return Array |
||
69 | */ |
||
70 | 1 | public function handleMailChimpResponse($mailChimp) |
|
71 | { |
||
72 | 1 | $response = $mailChimp->getLastResponse(); |
|
73 | |||
74 | 1 | View Code Duplication | if (!$mailChimp->success()) { |
0 ignored issues
–
show
This code seems to be duplicated across 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. ![]() |
|||
75 | 1 | $message = $response && array_key_exists($response['errors']) |
|
0 ignored issues
–
show
The expression
$response of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
76 | 1 | ? $response['errors'][0]['message'] |
|
77 | 1 | : 'Error connecting to MailChimp API'; |
|
78 | |||
79 | 1 | user_error($message, E_USER_ERROR); |
|
80 | } |
||
81 | |||
82 | 1 | return Convert::json2array($response['body']); |
|
83 | } |
||
84 | |||
85 | /** |
||
86 | * Creates a MailChimp campaign via the API. |
||
87 | * |
||
88 | * @param MailChimp $mailChimp |
||
89 | * @return Array |
||
90 | */ |
||
91 | public function createCampaign($mailChimp) |
||
92 | { |
||
93 | $mailChimp->post('campaigns', [ |
||
94 | 'type' => 'regular', |
||
95 | 'settings' => [ |
||
96 | 'subject_line' => $this->record->Title, |
||
97 | 'from_name' => $this->record->FromName, |
||
98 | 'reply_to' => $this->record->ReplyTo, |
||
99 | ], |
||
100 | ]); |
||
101 | |||
102 | return $this->handleMailChimpResponse($mailChimp); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * Populates a MailChimp Campaign with Blog content via the API. |
||
107 | * |
||
108 | * @param MailChimp $mailChimp |
||
109 | * @param Int $campaignID |
||
110 | * @return Array |
||
111 | */ |
||
112 | public function populateCampaignContent($mailChimp, $campaignID) |
||
113 | { |
||
114 | $mailChimp->put("campaigns/{$campaignID}/content", [ |
||
115 | 'template' => [ |
||
116 | 'id' => $this->record->TemplateID, |
||
117 | 'sections' => [ |
||
118 | 'chimpify' => $this->record->getCampaignContent(), |
||
119 | ], |
||
120 | ], |
||
121 | ]); |
||
122 | |||
123 | return $this->handleMailChimpResponse($mailChimp); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Creates and populates a MailChimp Campaign with blog content via the API. |
||
128 | * |
||
129 | * @param Array $data |
||
130 | * @param Form $form |
||
131 | */ |
||
132 | public function doGenerateCampaign($data, $form) |
||
0 ignored issues
–
show
|
|||
133 | { |
||
134 | if (!$api_key = $this->record->config()->get('api_key')) { |
||
135 | user_error( |
||
136 | 'Add a MailChimp API key to config (ChimpifyCampaign::api_key)', |
||
137 | E_USER_ERROR |
||
138 | ); |
||
139 | } |
||
140 | |||
141 | $controller = $this->getToplevelController(); |
||
142 | |||
143 | if (!$this->record || !$this->record->canEdit()) { |
||
144 | return $controller->httpError(403); |
||
145 | } |
||
146 | |||
147 | $form->validate(); |
||
148 | |||
149 | $mailChimp = new MailChimp($api_key); |
||
150 | |||
151 | $response = $this->createCampaign($mailChimp); |
||
152 | $response = $this->populateCampaignContent($mailChimp, $response['id']); |
||
0 ignored issues
–
show
$response 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 ![]() |
|||
153 | |||
154 | $form->sessionMessage( |
||
155 | _t( |
||
156 | 'Chimpify.MessageGenerateCampaignSuccess', |
||
157 | 'Successfully created MailChimp Campaign' |
||
158 | ), |
||
159 | 'good' |
||
160 | ); |
||
161 | |||
162 | return $controller->redirectBack(); |
||
163 | } |
||
164 | } |
||
165 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.