| Conditions | 13 |
| Paths | 9 |
| Total Lines | 47 |
| Code Lines | 26 |
| Lines | 15 |
| Ratio | 31.91 % |
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 |
||
| 49 | public function __construct(GedcomRecord $record = null) { |
||
| 50 | $this->record = $record; |
||
| 51 | |||
| 52 | // Automatically fix broken links |
||
| 53 | if ($this->record && $this->record->canEdit()) { |
||
| 54 | $broken_links = 0; |
||
| 55 | View Code Duplication | foreach ($this->record->getFacts('HUSB|WIFE|CHIL|FAMS|FAMC|REPO') as $fact) { |
|
| 56 | if (!$fact->isPendingDeletion() && $fact->getTarget() === null) { |
||
| 57 | $this->record->deleteFact($fact->getFactId(), false); |
||
| 58 | FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ I18N::translate('The link from ā%1$sā to ā%2$sā has been deleted.', $this->record->getFullName(), $fact->getValue())); |
||
| 59 | $broken_links = true; |
||
| 60 | } |
||
| 61 | } |
||
| 62 | View Code Duplication | foreach ($this->record->getFacts('NOTE|SOUR|OBJE') as $fact) { |
|
| 63 | // These can be links or inline. Only delete links. |
||
| 64 | if (!$fact->isPendingDeletion() && $fact->getTarget() === null && preg_match('/^@.*@$/', $fact->getValue())) { |
||
| 65 | $this->record->deleteFact($fact->getFactId(), false); |
||
| 66 | FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ I18N::translate('The link from ā%1$sā to ā%2$sā has been deleted.', $this->record->getFullName(), $fact->getValue())); |
||
| 67 | $broken_links = true; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | if ($broken_links) { |
||
| 71 | // Reload the updated family |
||
| 72 | $this->record = GedcomRecord::getInstance($this->record->getXref(), $this->record->getTree()); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | parent::__construct(); |
||
| 77 | |||
| 78 | // We want robots to index this page |
||
| 79 | $this->setMetaRobots('index,follow'); |
||
| 80 | |||
| 81 | // Set a page title |
||
| 82 | if ($this->record) { |
||
| 83 | if ($this->record->canShowName()) { |
||
| 84 | // e.g. "John Doe" or "1881 Census of Wales" |
||
| 85 | $this->setPageTitle($this->record->getFullName()); |
||
| 86 | } else { |
||
| 87 | // e.g. "Individual" or "Source" |
||
| 88 | $record = $this->record; |
||
| 89 | $this->setPageTitle(GedcomTag::getLabel($record::RECORD_TYPE)); |
||
| 90 | } |
||
| 91 | } else { |
||
| 92 | // No such record |
||
| 93 | $this->setPageTitle(I18N::translate('Private')); |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 125 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: