| Conditions | 12 |
| Paths | 79 |
| Total Lines | 81 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 53 | public function transform($item, $parentObject, $strategy) |
||
| 54 | { |
||
| 55 | $this->utils->log("START page-transform for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 56 | |||
| 57 | if (!$item->checkIsType('sitetree')) { |
||
| 58 | $this->utils->log(" - Item not of type \'sitetree\'. for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 59 | $this->utils->log("END page-transform for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 60 | |||
| 61 | return false; |
||
| 62 | } |
||
| 63 | |||
| 64 | $source = $item->getSource(); |
||
| 65 | // Sleep to reduce load on the remote server |
||
| 66 | usleep((int) self::$sleep_multiplier * 1000); |
||
| 67 | // Extract content from the page |
||
| 68 | $contentFields = $this->getContentFieldsAndSelectors($item, 'SiteTree'); |
||
| 69 | |||
| 70 | // Default value for Title |
||
| 71 | if (is_array($contentFields)) { |
||
| 72 | if (empty($contentFields['Title'])) { |
||
| 73 | $contentFields['Title'] = ['content' => $item->Name]; |
||
| 74 | } |
||
| 75 | |||
| 76 | // Default value for URLSegment |
||
| 77 | if (empty($contentFields['URLSegment'])) { |
||
| 78 | // $item->Name comes from StaticSiteContentItem::init() and is a URL |
||
| 79 | $name = ($item->Name == '/' ? self::$import_root : $item->Name); |
||
| 80 | $urlSegment = preg_replace('#\.[^.]*$#', '', $name); // Lose file-extensions e.g .html |
||
| 81 | $contentFields['URLSegment'] = ['content' => $urlSegment]; |
||
| 82 | } |
||
| 83 | |||
| 84 | // Default value for Content (Useful for during unit-testing) |
||
| 85 | if (empty($contentFields['Content'])) { |
||
| 86 | $contentFields['Content'] = ['content' => 'No content found']; |
||
| 87 | $this->utils->log(" - No content found for 'Content' field.", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | // Get a user-defined schema suited to this URL and Mime |
||
| 92 | $schema = $source->getSchemaForURL($item->AbsoluteURL, $item->ProcessedMIME); |
||
| 93 | |||
| 94 | if (!$schema) { |
||
| 95 | $this->utils->log(" - Couldn't find an import schema for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 96 | $this->utils->log("END page-transform for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 97 | |||
| 98 | return false; |
||
| 99 | } |
||
| 100 | |||
| 101 | // TODO Exception vs return false?? |
||
| 102 | if (!$schema->DataType) { |
||
| 103 | $this->utils->log(" - DataType for migration schema is empty for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 104 | $this->utils->log("END page-transform for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 105 | throw new \Exception('DataType for migration schema is empty!'); |
||
| 106 | } |
||
| 107 | |||
| 108 | // Process incoming according to user-selected duplication strategy |
||
| 109 | if (!$page = $this->duplicationStrategy($schema->DataType, $item, $source->BaseUrl, $strategy, $parentObject)) { |
||
| 110 | $this->utils->log("END page-transform for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 111 | |||
| 112 | return false; |
||
| 113 | } |
||
| 114 | |||
| 115 | $page->StaticSiteContentSourceID = $source->ID; |
||
| 116 | $page->StaticSiteURL = $item->AbsoluteURL; |
||
| 117 | $page->StaticSiteImportID = $this->getCurrentImportID(); |
||
| 118 | $page->Status = 'Published'; |
||
| 119 | |||
| 120 | foreach ($contentFields as $property => $map) { |
||
| 121 | // Don't write anything new, if we have nothing new to write (useful during unit-testing) |
||
| 122 | if (!empty($map['content'])) { |
||
| 123 | $page->$property = $map['content']; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | Versioned::set_reading_mode('Stage.Stage'); |
||
| 128 | $page->write(); |
||
| 129 | $page->publishRecursive(); |
||
| 130 | |||
| 131 | $this->utils->log("END page-transform for: ", $item->AbsoluteURL, $item->ProcessedMIME); |
||
| 132 | |||
| 133 | return StaticSiteTransformResult::create($page, $item->stageChildren()); |
||
| 134 | } |
||
| 136 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths