Pyrech\ComposerChangelogs\Config\ConfigBuilder::build PHP Метод

build() публичный Метод

public build ( array $extra, string $baseDir ) : Config
$extra array
$baseDir string
Результат Config
    public function build(array $extra, $baseDir)
    {
        $this->reset();
        $commitAuto = 'never';
        $commitBinFile = null;
        $commitMessage = 'Update dependencies';
        $gitlabHosts = [];
        if (array_key_exists('commit-auto', $extra)) {
            if (in_array($extra['commit-auto'], self::$validCommitAutoValues, true)) {
                $commitAuto = $extra['commit-auto'];
            } else {
                $this->warnings[] = self::createWarningFromInvalidValue($extra, 'commit-auto', $commitAuto, sprintf('Valid options are "%s".', implode('", "', self::$validCommitAutoValues)));
            }
        }
        if (array_key_exists('commit-bin-file', $extra)) {
            if ($commitAuto === 'never') {
                $this->warnings[] = '"commit-bin-file" is specified but "commit-auto" option is set to "never". Ignoring.';
            } else {
                $file = realpath(FileSystemHelper::isAbsolute($extra['commit-bin-file']) ? $extra['commit-bin-file'] : $baseDir . '/' . $extra['commit-bin-file']);
                if (!file_exists($file)) {
                    $this->warnings[] = 'The file pointed by the option "commit-bin-file" was not found. Ignoring.';
                } else {
                    $commitBinFile = $file;
                }
            }
        } else {
            if ($commitAuto !== 'never') {
                $this->warnings[] = sprintf('"commit-auto" is set to "%s" but "commit-bin-file" was not specified.', $commitAuto);
            }
        }
        if (array_key_exists('commit-message', $extra)) {
            if (strlen(trim($extra['commit-message'])) === 0) {
                $this->warnings[] = '"commit-message" is specified but empty. Ignoring and using default commit message.';
            } else {
                $commitMessage = $extra['commit-message'];
            }
        }
        if (array_key_exists('gitlab-hosts', $extra)) {
            if (!is_array($extra['gitlab-hosts'])) {
                $this->warnings[] = '"gitlab-hosts" is specified but should be an array. Ignoring.';
            } else {
                $gitlabHosts = (array) $extra['gitlab-hosts'];
            }
        }
        return new Config($commitAuto, $commitBinFile, $commitMessage, $gitlabHosts);
    }

Usage Example

 public function test_it_accepts_valid_setup()
 {
     $extra = ['commit-auto' => 'ask', 'commit-bin-file' => self::COMMIT_BIN_FILE, 'gitlab-hosts' => ['gitlab.company1.com', 'gitlab.company2.com']];
     $config = $this->SUT->build($extra, __DIR__);
     static::assertInstanceOf('Pyrech\\ComposerChangelogs\\Config\\Config', $config);
     static::assertSame('ask', $config->getCommitAuto());
     static::assertSame($this->absoluteCommitBinFile, $config->getCommitBinFile());
     static::assertCount(2, $config->getGitlabHosts());
     static::assertCount(0, $this->SUT->getWarnings());
 }
All Usage Examples Of Pyrech\ComposerChangelogs\Config\ConfigBuilder::build