Gush\Helper\GitHelper::undefinedToDefault PHP Method

undefinedToDefault() public static method

public static undefinedToDefault ( string $value, string | null $default = null ) : null | string
$value string
$default string | null
return null | string
    public static function undefinedToDefault($value, $default = null)
    {
        if (false !== strpos($value, "")) {
            return $default;
        }
        return $value;
    }

Usage Example

Example #1
0
 /**
  * Use this for detecting the org and repo.
  *
  * Add the options to decorateDefinition.
  *
  * @param ConsoleEvent $event
  */
 public function initialize(ConsoleEvent $event)
 {
     $command = $event->getCommand();
     if (!$command instanceof InitCommand) {
         return;
     }
     if (!$this->gitHelper->isGitDir()) {
         throw new UserException(sprintf('You can only run the "%s" command when you are in a Git directory.', $command->getName()));
     }
     $input = $event->getInput();
     $input->setOption('repo-adapter', GitHelper::undefinedToDefault($input->getOption('repo-adapter'), $this->detectAdapterName()));
     $input->setOption('issue-adapter', GitHelper::undefinedToDefault($input->getOption('issue-adapter'), $input->getOption('repo-adapter')));
     if (!$this->application->getAdapterFactory()->supports($input->getOption('repo-adapter'), AdapterFactory::SUPPORT_REPOSITORY_MANAGER)) {
         return;
     }
     $org = GitHelper::undefinedToDefault($input->getOption('org'));
     $repo = GitHelper::undefinedToDefault($input->getOption('repo'));
     if (null === $org || null === $repo) {
         list($org, $repo) = $this->getRepositoryReference($this->getAdapter($input->getOption('repo-adapter')), $org, $repo);
         if (!$input->isInteractive()) {
             $this->styleHelper->note(['You did not provide an organization and/or repository name.', 'Gush automatically detected the missing information.', sprintf('Org: "%s" / repo: "%s"', $org, $repo)]);
         }
         $input->setOption('org', $org);
         $input->setOption('repo', $repo);
     }
     $input->setOption('issue-org', GitHelper::undefinedToDefault($input->getOption('issue-org'), $org));
     $input->setOption('issue-project', GitHelper::undefinedToDefault($input->getOption('issue-project'), $repo));
 }
All Usage Examples Of Gush\Helper\GitHelper::undefinedToDefault