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