| Conditions | 3 |
| Paths | 2 |
| Total Lines | 73 |
| 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 |
||
| 28 | public function create( |
||
| 29 | LogoutRequest $request, |
||
| 30 | AbstractProvider $theirProvider, |
||
| 31 | AbstractProvider $ourProvider |
||
| 32 | ) |
||
| 33 | { |
||
| 34 | $logout = new SamlLogoutResponse(); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Set remote destination |
||
| 38 | */ |
||
| 39 | $logout->setDestination( |
||
| 40 | |||
| 41 | $theirProvider->getType() === SettingsInterface::SP ? |
||
| 42 | $theirProvider->firstSpSloService( |
||
| 43 | /** |
||
| 44 | * We only support post right now |
||
| 45 | */ |
||
| 46 | Constants::BINDING_HTTP_POST |
||
| 47 | )->getResponseLocation() : |
||
| 48 | $theirProvider->firstIdpSloService( |
||
| 49 | |||
| 50 | /** |
||
| 51 | * We only support post right now |
||
| 52 | */ |
||
| 53 | Constants::BINDING_HTTP_POST |
||
| 54 | )->getResponseLocation() |
||
| 55 | ); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Set session id |
||
| 59 | */ |
||
| 60 | $logout->setInResponseTo( |
||
| 61 | $request->getSessionIndex() |
||
| 62 | ); |
||
| 63 | |||
| 64 | $logout->setRelayState( |
||
| 65 | $request->getRelayState() |
||
| 66 | ); |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Set issuer |
||
| 70 | */ |
||
| 71 | $logout->setIssuer( |
||
| 72 | $ourProvider->getEntityId() |
||
| 73 | ); |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Sign the message |
||
| 77 | */ |
||
| 78 | if ($ourProvider->keychain) { |
||
| 79 | $logout->setSignatureKey( |
||
| 80 | $ourProvider->keychainPrivateXmlSecurityKey() |
||
| 81 | ); |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Kick off event here so people can manipulate this object if needed |
||
| 86 | */ |
||
| 87 | $event = new Event(); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * request |
||
| 91 | */ |
||
| 92 | $event->sender = $request; |
||
| 93 | /** |
||
| 94 | * response |
||
| 95 | */ |
||
| 96 | $event->data = $logout; |
||
| 97 | $this->trigger(static::EVENT_AFTER_MESSAGE_CREATED, $event); |
||
| 98 | |||
| 99 | return $logout; |
||
| 100 | } |
||
| 101 | } |
||
| 102 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: