Conditions | 5 |
Paths | 22 |
Total Lines | 65 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
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 |
||
52 | public function preview(HTTPRequest $request) |
||
53 | { |
||
54 | // Ensure this URL doesn't get picked up by HTTP caches |
||
55 | HTTPCacheControlMiddleware::singleton()->disableCache(); |
||
56 | |||
57 | $key = $request->param('Key'); |
||
58 | $token = $request->param('Token'); |
||
59 | try { |
||
60 | $session = $this->getRequest()->getSession(); |
||
61 | } catch (BadMethodCallException $e) { |
||
62 | // Create a new session |
||
63 | $session = $this->getRequest() |
||
64 | ->setSession(Injector::inst()->create(Session::class, [])) |
||
65 | ->getSession(); |
||
66 | } |
||
67 | /** @var ShareToken $shareToken */ |
||
68 | $shareToken = ShareToken::get()->filter('Token', $token)->first(); |
||
69 | |||
70 | if (!$shareToken) { |
||
71 | return $this->errorPage(); |
||
72 | } |
||
73 | |||
74 | /** @var SiteTree|ShareDraftContentSiteTreeExtension $page */ |
||
75 | $page = Versioned::get_by_stage(SiteTree::class, Versioned::DRAFT) |
||
76 | ->byID($shareToken->PageID); |
||
77 | |||
78 | $latest = Versioned::get_latest_version(SiteTree::class, $shareToken->PageID); |
||
79 | |||
80 | $controller = $this->getControllerFor($page); |
||
81 | |||
82 | if (!$shareToken->isExpired() && $page->generateKey($shareToken->Token) === $key) { |
||
83 | Requirements::css('silverstripe/sharedraftcontent: client/dist/styles/bundle-frontend.css'); |
||
84 | |||
85 | // Temporarily un-secure the draft site and switch to draft |
||
86 | $oldSecured = $this->getIsDraftSecured($session); |
||
87 | $oldMode = Versioned::get_reading_mode(); |
||
88 | |||
89 | // Process page inside an unsecured draft container |
||
90 | try { |
||
91 | $this->setIsDraftSecured($session, false); |
||
92 | Versioned::set_stage('Stage'); |
||
93 | |||
94 | // Hack to get around ContentController::init() redirecting on home page |
||
95 | $_FILES = array(array()); |
||
96 | |||
97 | // Create mock request; Simplify request to single top level request |
||
98 | $pageRequest = new HTTPRequest('GET', $page->URLSegment); |
||
99 | $pageRequest->match('$URLSegment//$Action/$ID/$OtherID', true); |
||
100 | $pageRequest->setSession($session); |
||
101 | $rendered = $controller->handleRequest($pageRequest); |
||
102 | |||
103 | // Render draft heading |
||
104 | $data = new ArrayData(array( |
||
105 | 'Page' => $page, |
||
106 | 'Latest' => $latest, |
||
107 | )); |
||
108 | $include = (string) $data->renderWith('Includes/TopBar'); |
||
109 | } finally { |
||
110 | $this->setIsDraftSecured($session, $oldSecured); |
||
111 | Versioned::set_reading_mode($oldMode); |
||
112 | } |
||
113 | |||
114 | return str_replace('</body>', $include . '</body>', (string) $rendered->getBody()); |
||
115 | } else { |
||
116 | return $this->errorPage(); |
||
117 | } |
||
172 |
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