| Conditions | 8 |
| Paths | 60 |
| Total Lines | 61 |
| Code Lines | 35 |
| 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 |
||
| 64 | public function providesRequests(): array |
||
| 65 | { |
||
| 66 | $requestFactory = $this->getRequestFactory(); |
||
| 67 | |||
| 68 | $invalidOverrides = [ |
||
| 69 | 'foo', |
||
| 70 | 'FOO', // Still invalid |
||
| 71 | '__construct', // Something we've seen in the wild |
||
| 72 | ]; |
||
| 73 | |||
| 74 | $argLists = []; |
||
| 75 | |||
| 76 | // Invalid overrides should *always* yield `true` (i.e. "yes, suspicious") |
||
| 77 | foreach (InvalidSymfonyHttpMethodOverrideFilter::VALID_METHODS as $validRealMethod) { |
||
| 78 | foreach ($invalidOverrides as $invalidOverride) { |
||
| 79 | $argLists[] = [true, $this->createRequestWithMethodOverrideInTheBody($validRealMethod, $invalidOverride)]; |
||
| 80 | $argLists[] = [true, $this->createRequestWithMethodOverrideInTheQuery($validRealMethod, $invalidOverride)]; |
||
| 81 | $argLists[] = [true, $this->createRequestWithMethodOverrideInAHeader($validRealMethod, $invalidOverride)]; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | $incompatibleRealMethods = array_filter( |
||
| 86 | InvalidSymfonyHttpMethodOverrideFilter::VALID_METHODS, |
||
| 87 | fn (string $methodName) => Request::METHOD_POST !== $methodName |
||
| 88 | ); |
||
| 89 | |||
| 90 | // The method can be overridden only if the 'real' method is `POST`, so other types of request containing |
||
| 91 | // overrides are suspicious -- irrespective of the value submitted |
||
| 92 | foreach ($incompatibleRealMethods as $incompatibleRealMethod) { |
||
| 93 | foreach ($invalidOverrides as $invalidOverride) { |
||
| 94 | $argLists[] = [true, $this->createRequestWithMethodOverrideInTheBody($incompatibleRealMethod, $invalidOverride)]; |
||
| 95 | $argLists[] = [true, $this->createRequestWithMethodOverrideInTheQuery($incompatibleRealMethod, $invalidOverride)]; |
||
| 96 | $argLists[] = [true, $this->createRequestWithMethodOverrideInAHeader($incompatibleRealMethod, $invalidOverride)]; |
||
| 97 | } |
||
| 98 | |||
| 99 | foreach (InvalidSymfonyHttpMethodOverrideFilter::VALID_METHODS as $validOverride) { |
||
| 100 | $argLists[] = [true, $this->createRequestWithMethodOverrideInTheBody($incompatibleRealMethod, $validOverride)]; |
||
| 101 | $argLists[] = [true, $this->createRequestWithMethodOverrideInTheQuery($incompatibleRealMethod, $validOverride)]; |
||
| 102 | $argLists[] = [true, $this->createRequestWithMethodOverrideInAHeader($incompatibleRealMethod, $validOverride)]; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | $compatibleRealMethod = Request::METHOD_POST; |
||
| 107 | |||
| 108 | foreach (InvalidSymfonyHttpMethodOverrideFilter::VALID_METHODS as $validOverride) { |
||
| 109 | $argLists[] = [false, $this->createRequestWithMethodOverrideInTheBody($compatibleRealMethod, $validOverride)]; |
||
| 110 | $argLists[] = [false, $this->createRequestWithMethodOverrideInTheQuery($compatibleRealMethod, $validOverride)]; |
||
| 111 | $argLists[] = [false, $this->createRequestWithMethodOverrideInAHeader($compatibleRealMethod, $validOverride)]; |
||
| 112 | |||
| 113 | $anotherValidOverride = strtolower($validOverride); |
||
| 114 | $argLists[] = [false, $this->createRequestWithMethodOverrideInTheBody($compatibleRealMethod, $anotherValidOverride)]; |
||
| 115 | $argLists[] = [false, $this->createRequestWithMethodOverrideInTheQuery($compatibleRealMethod, $anotherValidOverride)]; |
||
| 116 | $argLists[] = [false, $this->createRequestWithMethodOverrideInAHeader($compatibleRealMethod, $anotherValidOverride)]; |
||
| 117 | } |
||
| 118 | |||
| 119 | // *Any* request without an override is okay, too :-) |
||
| 120 | foreach (InvalidSymfonyHttpMethodOverrideFilter::VALID_METHODS as $validRealMethod) { |
||
| 121 | $argLists[] = [false, $requestFactory->create(['method' => $validRealMethod])]; |
||
| 122 | } |
||
| 123 | |||
| 124 | return $argLists; |
||
| 125 | } |
||
| 245 |