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