| Conditions | 22 |
| Paths | 333 |
| Total Lines | 99 |
| Code Lines | 68 |
| Lines | 17 |
| Ratio | 17.17 % |
| 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 |
||
| 56 | public function getBlock($block_id, $template = true, $cfg = []): string { |
||
| 57 | global $ctype, $WT_TREE; |
||
| 58 | |||
| 59 | $sendmail = $this->getBlockSetting($block_id, 'sendmail', '1'); |
||
| 60 | $days = $this->getBlockSetting($block_id, 'days', '1'); |
||
| 61 | |||
| 62 | foreach (['days', 'sendmail'] as $name) { |
||
| 63 | if (array_key_exists($name, $cfg)) { |
||
| 64 | $$name = $cfg[$name]; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | $changes = Database::prepare( |
||
| 69 | "SELECT 1" . |
||
| 70 | " FROM `##change`" . |
||
| 71 | " WHERE status='pending'" . |
||
| 72 | " LIMIT 1" |
||
| 73 | )->fetchOne(); |
||
| 74 | |||
| 75 | if ($changes === '1' && $sendmail === '1') { |
||
| 76 | // There are pending changes - tell moderators/managers/administrators about them. |
||
| 77 | if (WT_TIMESTAMP - (int) Site::getPreference('LAST_CHANGE_EMAIL') > (60 * 60 * 24 * $days)) { |
||
| 78 | // Which users have pending changes? |
||
| 79 | foreach (User::all() as $user) { |
||
| 80 | if ($user->getPreference('contactmethod') !== 'none') { |
||
| 81 | foreach (Tree::getAll() as $tree) { |
||
| 82 | if ($tree->hasPendingEdit() && Auth::isManager($tree, $user)) { |
||
| 83 | I18N::init($user->getPreference('language')); |
||
| 84 | |||
| 85 | $sender = new User( |
||
| 86 | (object) [ |
||
| 87 | 'user_id' => null, |
||
| 88 | 'user_name' => '', |
||
| 89 | 'real_name' => $WT_TREE->getTitle(), |
||
| 90 | 'email' => $WT_TREE->getPreference('WEBTREES_EMAIL'), |
||
| 91 | ] |
||
| 92 | ); |
||
| 93 | |||
| 94 | Mail::send( |
||
| 95 | $sender, |
||
| 96 | $user, |
||
| 97 | $sender, |
||
| 98 | I18N::translate('Pending changes'), |
||
| 99 | View::make('emails/pending-changes-text', ['tree' => $tree, 'user' => $user]), |
||
| 100 | View::make('emails/pending-changes-html', ['tree' => $tree, 'user' => $user]) |
||
| 101 | ); |
||
| 102 | I18N::init(WT_LOCALE); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 | Site::setPreference('LAST_CHANGE_EMAIL', WT_TIMESTAMP); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | if (Auth::isEditor($WT_TREE) && $WT_TREE->hasPendingEdit()) { |
||
| 111 | $content = ''; |
||
| 112 | if (Auth::isModerator($WT_TREE)) { |
||
| 113 | $content .= '<a href="edit_changes.php">' . I18N::translate('There are pending changes for you to moderate.') . '</a><br>'; |
||
| 114 | } |
||
| 115 | if ($sendmail === '1') { |
||
| 116 | $content .= I18N::translate('Last email reminder was sent ') . FunctionsDate::formatTimestamp(Site::getPreference('LAST_CHANGE_EMAIL')) . '<br>'; |
||
|
|
|||
| 117 | $content .= I18N::translate('Next email reminder will be sent after ') . FunctionsDate::formatTimestamp((int) Site::getPreference('LAST_CHANGE_EMAIL') + (60 * 60 * 24 * $days)) . '<br><br>'; |
||
| 118 | } |
||
| 119 | $content .= '<ul>'; |
||
| 120 | $changes = Database::prepare( |
||
| 121 | "SELECT xref" . |
||
| 122 | " FROM `##change`" . |
||
| 123 | " WHERE status='pending'" . |
||
| 124 | " AND gedcom_id=?" . |
||
| 125 | " GROUP BY xref" |
||
| 126 | )->execute([$WT_TREE->getTreeId()])->fetchAll(); |
||
| 127 | foreach ($changes as $change) { |
||
| 128 | $record = GedcomRecord::getInstance($change->xref, $WT_TREE); |
||
| 129 | if ($record->canShow()) { |
||
| 130 | $content .= '<li><a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a></li>'; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | $content .= '</ul>'; |
||
| 134 | |||
| 135 | View Code Duplication | if ($template) { |
|
| 136 | if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { |
||
| 137 | $config_url = Html::url('block_edit.php', ['block_id' => $block_id, 'ged' => $WT_TREE->getName()]); |
||
| 138 | } else { |
||
| 139 | $config_url = ''; |
||
| 140 | } |
||
| 141 | |||
| 142 | return View::make('blocks/template', [ |
||
| 143 | 'block' => str_replace('_', '-', $this->getName()), |
||
| 144 | 'id' => $block_id, |
||
| 145 | 'config_url' => $config_url, |
||
| 146 | 'title' => $this->getTitle(), |
||
| 147 | 'content' => $content, |
||
| 148 | ]); |
||
| 149 | } else { |
||
| 150 | return $content; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | return ''; |
||
| 155 | } |
||
| 215 |