| Conditions | 10 |
| Paths | 27 |
| Total Lines | 37 |
| Code Lines | 23 |
| 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 |
||
| 69 | private function getLinkData(SiteTree $page, array $includeIn) { |
||
| 70 | // Set a list of all fields that can have autolinks created in them |
||
| 71 | $page->AutomateableFields = ArrayList::create(); |
||
| 72 | |||
| 73 | foreach ($this->getAllDatabaseFields($page->class) as $field => $type) |
||
| 74 | if (in_array($field, $includeIn) && |
||
| 75 | !$page->AutomateableFields->find('DataField', $field) && |
||
| 76 | AutomatedLink::isFieldParsable($page, $field) |
||
| 77 | ) $page->AutomateableFields->push(DataObject::create(array('DataField' => $field))); |
||
| 78 | |||
| 79 | // Get data Pre-Automated Links creation |
||
| 80 | $withLinks = $this->getPageDOM($page, true); |
||
| 81 | if (!$withLinks) return false; |
||
| 82 | |||
| 83 | $links = $withLinks->getElementsByTagName('a'); |
||
| 84 | |||
| 85 | $page->TotalLinks = $links->length; |
||
| 86 | $page->OriginalLinkCount = $page->TotalLinks; |
||
|
1 ignored issue
–
show
|
|||
| 87 | $page->LinkCount = 0; |
||
| 88 | |||
| 89 | // List all automated links that were created in this $page |
||
| 90 | $linksUsed = array(); |
||
| 91 | foreach ($this->Links as $autolink) |
||
| 92 | foreach ($links as $link) { |
||
| 93 | if ($link->getAttribute('data-id') == $autolink->ID) { |
||
| 94 | $linksUsed[$autolink->ID] = $autolink->Phrase; |
||
| 95 | $page->OriginalLinkCount--; |
||
|
1 ignored issue
–
show
|
|||
| 96 | $page->LinkCount++; |
||
| 97 | } |
||
| 98 | } |
||
| 99 | |||
| 100 | $page->Links = implode(', ', $linksUsed); |
||
| 101 | |||
| 102 | if ($page->LinkCount < 1) return false; |
||
| 103 | |||
| 104 | return $page; |
||
| 105 | } |
||
| 106 | |||
| 189 |
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.