| Conditions | 7 |
| Paths | 20 |
| Total Lines | 64 |
| Code Lines | 43 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 117 | protected function sendEmail($reminder, $recordOrEmail, $isTestOnly) |
||
| 118 | { |
||
| 119 | $filter = array( |
||
| 120 | 'EmailReminder_NotificationScheduleID' => $reminder->ID, |
||
| 121 | ); |
||
| 122 | if ($recordOrEmail instanceof DataObject) { |
||
| 123 | $email_field = $reminder->EmailField; |
||
| 124 | $email = $recordOrEmail->$email_field; |
||
| 125 | $record = $recordOrEmail; |
||
| 126 | $filter['ExternalRecordClassName'] = $recordOrEmail->ClassName; |
||
| 127 | $filter['ExternalRecordID'] = $recordOrEmail->ID; |
||
| 128 | } else { |
||
| 129 | $email = strtolower(trim($recordOrEmail)); |
||
| 130 | $record = Injector::inst()->get($reminder->DataObject); |
||
| 131 | } |
||
| 132 | $filter['EmailTo'] = $email; |
||
| 133 | if (Email::validEmailAddress($email)) { |
||
| 134 | $send = true; |
||
| 135 | $logs = EmailReminder_EmailRecord::get()->filter($filter); |
||
| 136 | $send = true; |
||
| 137 | foreach ($logs as $log) { |
||
| 138 | if (! $log->canSendAgain()) { |
||
| 139 | $send = false; |
||
| 140 | break; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | if ($send) { |
||
| 144 | $log = EmailReminder_EmailRecord::create($filter); |
||
| 145 | |||
| 146 | $subject = $reminder->EmailSubject; |
||
| 147 | $email_content = $reminder->Content; |
||
| 148 | if ($replacerObject = $this->getReplacerObject()) { |
||
| 149 | $email_content = $replacerObject->replace($reminder, $record, $email_content); |
||
| 150 | $subject = $replacerObject->replace($reminder, $record, $subject); |
||
| 151 | } |
||
| 152 | $email_content = $this->getParsedContent($record, $email_content); |
||
| 153 | |||
| 154 | /* Parse HTML like a template, and translate any internal links */ |
||
| 155 | $data = ArrayData::create(array( |
||
| 156 | 'Content' => $email_content |
||
| 157 | )); |
||
| 158 | |||
| 159 | // $email_body = $record->renderWith(SSViewer::fromString($reminder->Content)); |
||
| 160 | // echo $record->renderWith('Email_Reminder_Standard_Template');//$email_body; |
||
| 161 | $email = new Email( |
||
| 162 | $reminder->EmailFrom, |
||
| 163 | $email, |
||
| 164 | $subject |
||
| 165 | ); |
||
| 166 | |||
| 167 | $email->setTemplate('Email_Reminder_Standard_Template'); |
||
| 168 | |||
| 169 | $email->populateTemplate($data); |
||
| 170 | |||
| 171 | // $email->send(); |
||
| 172 | $log->IsTestOnly = $isTestOnly; |
||
| 173 | $log->Result = $email->send(); |
||
| 174 | $log->EmailReminder_NotificationScheduleID = $reminder->ID; |
||
| 175 | $log->EmailContent = $email->body; |
||
| 176 | $log->write(); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | return false; |
||
| 180 | } |
||
| 181 | |||
| 215 |
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.