| Total Lines | 104 |
| 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 |
||
| 47 | public function createKernel(array $options = []): IAuthenticationKernel |
||
| 48 | { |
||
| 49 | if (!isset($options[self::KEY_U2F_CERTIFICATES])) { |
||
| 50 | $options[self::KEY_U2F_CERTIFICATES] = null; |
||
| 51 | } |
||
| 52 | if (!isset($options[self::KEY_PWD_SETTINGS])) { |
||
| 53 | $options[self::KEY_PWD_SETTINGS] = [ |
||
| 54 | 'min_length' => 0, |
||
| 55 | 'enforce_min_length' => false, |
||
| 56 | 'uppercase' => false, |
||
| 57 | 'special_chars' => false, |
||
| 58 | 'numbers' => false, |
||
| 59 | ]; |
||
| 60 | } |
||
| 61 | if (!isset($options[self::KEY_USER_ID])) { |
||
| 62 | $options[self::KEY_USER_ID] = self::USER_ID; |
||
| 63 | } |
||
| 64 | if (!isset($options[self::KEY_USER_PWD])) { |
||
| 65 | $options[self::KEY_USER_PWD] = self::USER_PWD; |
||
| 66 | } |
||
| 67 | return new AuthenticationKernel( |
||
| 68 | new class($options[self::KEY_U2F_CERTIFICATES], $options[self::KEY_PWD_SETTINGS], $options[self::KEY_USER_ID], $options[self::KEY_USER_PWD]) implements IApplicationConfiguration { |
||
| 69 | private $cas; |
||
| 70 | |||
| 71 | private $hashedPassword; |
||
| 72 | |||
| 73 | private $tokenStorage; |
||
| 74 | |||
| 75 | private $username; |
||
| 76 | |||
| 77 | public function __construct( |
||
| 78 | ?array $cas, |
||
| 79 | array $pwdSettings, |
||
| 80 | string $username, |
||
| 81 | string $password |
||
| 82 | ) { |
||
| 83 | $this->cas = $cas; |
||
| 84 | $this->hashedPassword = password_hash($password, PASSWORD_DEFAULT); |
||
| 85 | $this->pwdSettings = $pwdSettings; |
||
|
|
|||
| 86 | $this->tokenStorage = new SessionTokenStorage(new Session( |
||
| 87 | new MockArraySessionStorage() |
||
| 88 | )); |
||
| 89 | $this->username = $username; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function getAssetUri(string $assetId): string |
||
| 93 | { |
||
| 94 | return 'https://example.org'; |
||
| 95 | } |
||
| 96 | |||
| 97 | public function getAppId(): string |
||
| 98 | { |
||
| 99 | return 'https://example.org'; |
||
| 100 | } |
||
| 101 | |||
| 102 | public function getComposerDir(): string |
||
| 103 | { |
||
| 104 | return realpath(__DIR__.'/../../../../vendor'); |
||
| 105 | } |
||
| 106 | |||
| 107 | public function getCustomTwigDir(): ?string |
||
| 108 | { |
||
| 109 | return null; |
||
| 110 | } |
||
| 111 | |||
| 112 | public function getLibDir(): string |
||
| 113 | { |
||
| 114 | return realpath(__DIR__.'/../../../..'); |
||
| 115 | } |
||
| 116 | |||
| 117 | public function getMember(string $username): IMember |
||
| 118 | { |
||
| 119 | if ($this->username !== $username) { |
||
| 120 | throw new InvalidArgumentException(); |
||
| 121 | } |
||
| 122 | return new Member( |
||
| 123 | $this->hashedPassword, |
||
| 124 | $this->username |
||
| 125 | ); |
||
| 126 | } |
||
| 127 | |||
| 128 | public function getU2fCertificates(): ?array |
||
| 129 | { |
||
| 130 | return $this->cas; |
||
| 131 | } |
||
| 132 | |||
| 133 | public function getU2fRegistrations(string $username): array |
||
| 134 | { |
||
| 135 | return (new U2fMocker($this))->getU2fRegistrationsOnly(); |
||
| 136 | } |
||
| 137 | |||
| 138 | public function getPwdSettings(): array |
||
| 139 | { |
||
| 140 | return $this->pwdSettings; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function getTokenStorage(): TokenStorageInterface |
||
| 144 | { |
||
| 145 | return $this->tokenStorage; |
||
| 146 | } |
||
| 147 | |||
| 148 | public function isExistingMember(string $username): bool |
||
| 149 | { |
||
| 150 | return $this->username === $username; |
||
| 151 | } |
||
| 156 |