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