| Conditions | 3 |
| Paths | 2 |
| Total Lines | 65 |
| 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 |
||
| 29 | public function create( |
||
| 30 | LogoutRequest $request, |
||
| 31 | AbstractProvider $theirProvider, |
||
| 32 | AbstractProvider $ourProvider |
||
| 33 | ) { |
||
| 34 | $logout = new SamlLogoutResponse(); |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Set remote destination |
||
| 38 | */ |
||
| 39 | $logout->setDestination( |
||
| 40 | $theirProvider->getType() === SettingsInterface::SP ? |
||
| 41 | $theirProvider->firstSpSloService( |
||
| 42 | )->getLocation() : |
||
| 43 | $theirProvider->firstIdpSloService( |
||
| 44 | )->getLocation() |
||
| 45 | ); |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Set session id |
||
| 49 | */ |
||
| 50 | $logout->setInResponseTo( |
||
| 51 | $request->getSessionIndex() |
||
| 52 | ); |
||
| 53 | |||
| 54 | $logout->setRelayState( |
||
| 55 | $request->getRelayState() |
||
| 56 | ); |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Set issuer |
||
| 60 | */ |
||
| 61 | $logout->setIssuer( |
||
| 62 | $issuer = new Issuer() |
||
| 63 | ); |
||
| 64 | $issuer->setValue( |
||
| 65 | $ourProvider->getEntityId() |
||
| 66 | ); |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Sign the message |
||
| 70 | */ |
||
| 71 | if ($ourProvider->keychain) { |
||
| 72 | $logout->setSignatureKey( |
||
| 73 | $ourProvider->keychainPrivateXmlSecurityKey() |
||
| 74 | ); |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Kick off event here so people can manipulate this object if needed |
||
| 79 | */ |
||
| 80 | $event = new Event(); |
||
| 81 | |||
| 82 | /** |
||
| 83 | * request |
||
| 84 | */ |
||
| 85 | $event->sender = $request; |
||
| 86 | /** |
||
| 87 | * response |
||
| 88 | */ |
||
| 89 | $event->data = $logout; |
||
| 90 | $this->trigger(static::EVENT_AFTER_MESSAGE_CREATED, $event); |
||
| 91 | |||
| 92 | return $logout; |
||
| 93 | } |
||
| 94 | } |
||
| 95 |
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: