| Conditions | 8 | 
| Paths | 7 | 
| Total Lines | 58 | 
| Code Lines | 37 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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 | ||
| 62 | public function handle() | ||
| 63 |     { | ||
| 64 |         if (!$entityId = $this->option('entityId')) { | ||
| 65 |             $this->error('Entity ID must be passed as an option --entityId'); | ||
| 66 | return; | ||
| 67 | } | ||
| 68 | |||
| 69 |         if (!$loginUrl = $this->option('loginUrl')) { | ||
| 70 |             $this->error('Login URL must be passed as an option --loginUrl'); | ||
| 71 | return; | ||
| 72 | } | ||
| 73 | |||
| 74 |         if (!$logoutUrl = $this->option('logoutUrl')) { | ||
| 75 |             $this->error('Logout URL must be passed as an option --logoutUrl'); | ||
| 76 | return; | ||
| 77 | } | ||
| 78 | |||
| 79 |         if (!$x509cert = $this->option('x509cert')) { | ||
| 80 |             $this->error('x509 certificate (base64) must be passed as an option --x509cert'); | ||
| 81 | return; | ||
| 82 | } | ||
| 83 | |||
| 84 |         $key = $this->option('key'); | ||
| 85 |         $metadata = ConsoleHelper::stringToArray($this->option('metadata')); | ||
| 86 | |||
| 87 |         if($key && ($tenant = $this->tenants->findByKey($key))) { | ||
| 88 | $this->renderTenants($tenant, 'Already found tenant(s) using this key'); | ||
| 89 | $this->error( | ||
| 90 | 'Cannot create a tenant because the key is already being associated with other tenants.' | ||
| 91 | . PHP_EOL . 'Firstly, delete tenant(s) or try to create with another with another key.' | ||
| 92 | ); | ||
| 93 | |||
| 94 | return; | ||
| 95 | } | ||
| 96 | |||
| 97 |         $class = config('saml2.tenantModel', Tenant::class); | ||
| 98 | $tenant = new $class([ | ||
| 99 | 'key' => $key, | ||
| 100 | 'uuid' => \Ramsey\Uuid\Uuid::uuid4(), | ||
| 101 | 'idp_entity_id' => $entityId, | ||
| 102 | 'idp_login_url' => $loginUrl, | ||
| 103 | 'idp_logout_url' => $logoutUrl, | ||
| 104 | 'idp_x509_cert' => $x509cert, | ||
| 105 |             'relay_state_url' => $this->option('relayStateUrl'), | ||
| 106 | 'name_id_format' => $this->resolveNameIdFormat(), | ||
| 107 | 'metadata' => $metadata, | ||
| 108 | ]); | ||
| 109 | |||
| 110 |         if(!$tenant->save()) { | ||
| 111 |             $this->error('Tenant cannot be saved.'); | ||
| 112 | return; | ||
| 113 | } | ||
| 114 | |||
| 115 |         $this->info("The tenant #{$tenant->id} ({$tenant->uuid}) was successfully created."); | ||
| 116 | |||
| 117 | $this->renderTenantCredentials($tenant); | ||
| 118 | |||
| 119 | $this->output->newLine(); | ||
| 120 | } | ||
| 121 | } |