| Conditions | 8 |
| Paths | 14 |
| Total Lines | 52 |
| 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 |
||
| 82 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 83 | { |
||
| 84 | $domain = $input->getArgument($this->arguments[0]); |
||
| 85 | $subdomain = $input->getArgument($this->arguments[1]); |
||
| 86 | $name = $input->getArgument($this->arguments[2]); |
||
| 87 | $organizationCode = $input->getArgument($this->arguments[3]); |
||
| 88 | $default = $input->getOption('default'); |
||
| 89 | $disabled = $input->getOption('disabled'); |
||
| 90 | |||
| 91 | if ($default) { |
||
| 92 | $name = TenantInterface::DEFAULT_TENANT_NAME; |
||
| 93 | $domain = $this->swpDomain; |
||
| 94 | $organization = $this->organizationRepository->findOneByName(OrganizationInterface::DEFAULT_NAME); |
||
| 95 | if (null === $organization) { |
||
| 96 | throw new \InvalidArgumentException('Default organization doesn\'t exist!'); |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | $organization = $this->organizationRepository->findOneByCode($organizationCode); |
||
|
|
|||
| 100 | |||
| 101 | if (null === $organization) { |
||
| 102 | throw new \InvalidArgumentException(sprintf('Organization with "%s" code doesn\'t exist!', $organizationCode)); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | if (null !== $subdomain) { |
||
| 107 | $tenant = $this->tenantRepository->findOneBySubdomainAndDomain($subdomain, $domain); |
||
| 108 | } else { |
||
| 109 | $tenant = $this->tenantRepository->findOneByDomain($domain); |
||
| 110 | } |
||
| 111 | |||
| 112 | if (null !== $tenant) { |
||
| 113 | throw new \InvalidArgumentException(sprintf('Tenant with domain %s and subdomain "%s" already exists!', $domain, $subdomain)); |
||
| 114 | } |
||
| 115 | |||
| 116 | $tenant = $this->createTenant($domain, $subdomain, $name, $disabled, $organization); |
||
| 117 | if ($default) { |
||
| 118 | $tenant->setCode(TenantInterface::DEFAULT_TENANT_CODE); |
||
| 119 | } |
||
| 120 | $this->tenantObjectManager->persist($tenant); |
||
| 121 | $this->tenantObjectManager->flush(); |
||
| 122 | |||
| 123 | $output->writeln( |
||
| 124 | sprintf( |
||
| 125 | 'Tenant <info>%s</info> (code: <info>%s</info>) has been created and <info>%s</info>!', |
||
| 126 | $name, |
||
| 127 | $tenant->getCode(), |
||
| 128 | $tenant->isEnabled() ? 'enabled' : 'disabled' |
||
| 129 | ) |
||
| 130 | ); |
||
| 131 | |||
| 132 | return 1; |
||
| 133 | } |
||
| 134 | |||
| 176 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.