| Conditions | 1 |
| Paths | 1 |
| Total Lines | 71 |
| Code Lines | 28 |
| 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 |
||
| 23 | public function testShareTokenLink() |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * First we check if both pages generate new ShareTokenSalt values. Then we check that |
||
| 27 | * these values are not the same. |
||
| 28 | */ |
||
| 29 | |||
| 30 | Page::add_extension(ShareDraftContentSiteTreeExtension::class); |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var Page $firstSharedPage |
||
| 34 | */ |
||
| 35 | $firstSharedPage = $this->objFromFixture(Page::class, 'FirstSharedPage'); |
||
| 36 | |||
| 37 | $firstShareLink = $firstSharedPage->ShareTokenLink(); |
||
| 38 | |||
| 39 | $this->assertNotEmpty($firstSharedPage->ShareTokenSalt); |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var page $secondSharedPage |
||
| 43 | */ |
||
| 44 | $secondSharedPage = $this->objFromFixture(Page::class, 'SecondSharedPage'); |
||
| 45 | |||
| 46 | $secondShareLink = $secondSharedPage->ShareTokenLink(); |
||
| 47 | |||
| 48 | $this->assertNotEmpty($secondSharedPage->ShareTokenSalt); |
||
| 49 | |||
| 50 | $this->assertNotEquals($firstShareLink, $secondShareLink); |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Then we get the underlying token and send a preview request. With a valid key and token, |
||
| 54 | * this will return a draft page. With an invalid key or token, this will return an expired |
||
| 55 | * link page. |
||
| 56 | */ |
||
| 57 | |||
| 58 | $firstSharedPageToken = $firstSharedPage->ShareTokens()->first(); |
||
| 59 | |||
| 60 | $this->assertNotEmpty($firstSharedPageToken); |
||
| 61 | |||
| 62 | $parts = explode('/', $firstShareLink); |
||
| 63 | |||
| 64 | $token = array_pop($parts); |
||
| 65 | $key = array_pop($parts); |
||
| 66 | |||
| 67 | $this->assertEquals($token, $firstSharedPageToken->Token); |
||
| 68 | |||
| 69 | $request = new HTTPRequest('GET', $firstShareLink); |
||
| 70 | |||
| 71 | $request->setRouteParams(array( |
||
| 72 | 'Token' => $token, |
||
| 73 | 'Key' => $key, |
||
| 74 | )); |
||
| 75 | |||
| 76 | $controller = new ShareDraftController($firstSharedPage); |
||
| 77 | |||
| 78 | $response = $controller->preview($request); |
||
| 79 | |||
| 80 | $this->assertContains('share-draft-content-message', $response); |
||
| 81 | |||
| 82 | $request = new HTTPRequest('GET', $firstShareLink); |
||
| 83 | |||
| 84 | $request->setRouteParams(array( |
||
| 85 | 'Token' => $token, |
||
| 86 | 'Key' => '', |
||
| 87 | )); |
||
| 88 | |||
| 89 | $controller = new ShareDraftController($firstSharedPage); |
||
| 90 | |||
| 91 | $response = $controller->preview($request); |
||
| 92 | |||
| 93 | $this->assertContains('share-draft-error-page', $response); |
||
| 94 | } |
||
| 96 |
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