| Conditions | 6 |
| Paths | 22 |
| Total Lines | 71 |
| 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 |
||
| 49 | public function preview(HTTPRequest $request) |
||
| 50 | { |
||
| 51 | $key = $request->param('Key'); |
||
| 52 | $token = $request->param('Token'); |
||
| 53 | try { |
||
| 54 | $session = $this->getRequest()->getSession(); |
||
| 55 | } catch (BadMethodCallException $e) { |
||
| 56 | // Create a new session |
||
| 57 | $session = $this->getRequest() |
||
| 58 | ->setSession(Injector::inst()->create(Session::class, [])) |
||
| 59 | ->getSession(); |
||
| 60 | } |
||
| 61 | /** |
||
| 62 | * @var ShareToken $shareToken |
||
| 63 | */ |
||
| 64 | $shareToken = ShareToken::get()->filter('Token', $token)->first(); |
||
| 65 | |||
| 66 | if (!$shareToken) { |
||
| 67 | return $this->errorPage(); |
||
| 68 | } |
||
| 69 | |||
| 70 | $page = Versioned::get_one_by_stage( |
||
| 71 | SiteTree::class, |
||
| 72 | 'Stage', |
||
| 73 | sprintf('"SiteTree"."ID" = \'%d\'', $shareToken->PageID) |
||
| 74 | ); |
||
| 75 | |||
| 76 | $latest = Versioned::get_latest_version(SiteTree::class, $shareToken->PageID); |
||
| 77 | |||
| 78 | $controller = $this->getControllerFor($page); |
||
| 79 | |||
| 80 | if (!$shareToken->isExpired() && $page->generateKey($shareToken->Token) === $key) { |
||
| 81 | Requirements::css('silverstripe/sharedraftcontent:css/top-bar.css'); |
||
| 82 | |||
| 83 | // Temporarily un-secure the draft site and switch to draft |
||
| 84 | $oldSecured = $session->get('unsecuredDraftSite'); |
||
| 85 | $oldMode = Versioned::get_reading_mode(); |
||
| 86 | $restore = function () use ($oldSecured, $oldMode, $session) { |
||
| 87 | $session->set('unsecuredDraftSite', $oldSecured); |
||
| 88 | Versioned::set_reading_mode($oldMode); |
||
| 89 | }; |
||
| 90 | |||
| 91 | // Process page inside an unsecured draft container |
||
| 92 | try { |
||
| 93 | $session->set('unsecuredDraftSite', true); |
||
| 94 | Versioned::set_stage('Stage'); |
||
| 95 | |||
| 96 | // Hack to get around ContentController::init() redirecting on home page |
||
| 97 | $_FILES = array(array()); |
||
| 98 | |||
| 99 | // Create mock request; Simplify request to single top level request |
||
| 100 | $pageRequest = new HTTPRequest('GET', $page->URLSegment); |
||
| 101 | $pageRequest->match('$URLSegment//$Action/$ID/$OtherID', true); |
||
| 102 | $pageRequest->setSession($session); |
||
| 103 | $rendered = $controller->handleRequest($pageRequest, $this->model); |
||
| 104 | |||
| 105 | // Render draft heading |
||
| 106 | $data = new ArrayData(array( |
||
| 107 | 'Page' => $page, |
||
| 108 | 'Latest' => $latest, |
||
| 109 | )); |
||
| 110 | $include = (string) $data->renderWith('Includes/TopBar'); |
||
| 111 | } catch (Exception $ex) { |
||
| 112 | $restore(); |
||
| 113 | throw $ex; |
||
| 114 | } |
||
| 115 | $restore(); |
||
| 116 | |||
| 117 | return str_replace('</body>', $include . '</body>', (string) $rendered->getBody()); |
||
| 118 | } else { |
||
| 119 | return $this->errorPage(); |
||
| 120 | } |
||
| 143 |
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