Skip to content

Commit b7d93a9

Browse files
committed
Rename validation prefix ton validate, initialize to configure, add source code urls configuration and validation
1 parent 53dd44f commit b7d93a9

30 files changed

+628
-160
lines changed

docker/phpcs.bootstrap.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
Steevanb_Sniffs_Uses_GroupUsesSniff::addSymfonyPrefixs();
99

1010
Steevanb_Sniffs_Functions_DisallowMultipleReturnSniff::addAllowedFunction(
11-
'/var/phpcs/Command/InitializeBranchCommand.php',
12-
'createComponentConfiguration'
11+
'/var/phpcs/Command/Configure/ConfigureComponentCommand.php',
12+
'createConfiguration'
1313
);
1414
Steevanb_Sniffs_Functions_DisallowMultipleReturnSniff::addAllowedFunction(
15-
'/var/phpcs/Command/InitializeBranchCommand.php',
16-
'defineAbstractComponentConfigurationCodeDependencyName'
15+
'/var/phpcs/Command/Configure/ConfigureComponentCommand.php',
16+
'defineCodeDependencyName'
17+
);
18+
Steevanb_Sniffs_Functions_DisallowMultipleReturnSniff::addAllowedFunction(
19+
'/var/phpcs/Command/Configure/ConfigureComponentCommand.php',
20+
'defineSourceCodeUrls'
1721
);

src/Command/AbstractCommand.php

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,42 @@ abstract protected function doExecute(): self;
2929
/** @var OutputInterface */
3030
private $output;
3131

32-
/** @var ?string */
33-
private $validationPrefix;
34-
3532
private $validateProd = true;
3633

37-
private $repositoriesCreated = true;
34+
private $skipBranchName = true;
35+
36+
private $skipSourceCodeUrls = false;
3837

39-
public function isValidateProd()
38+
public function validateProd(): bool
4039
{
4140
return $this->validateProd;
4241
}
4342

44-
public function isRepositoriesCreated()
43+
public function skipBranchName(): bool
44+
{
45+
return $this->skipBranchName;
46+
}
47+
48+
public function skipSourceCodeUrls(): bool
4549
{
46-
return $this->repositoriesCreated;
50+
return $this->skipSourceCodeUrls;
4751
}
4852

4953
protected function configure()
5054
{
5155
$this
5256
->addOption('validate-prod', 'p', null, 'Validate data for prod instead of dev')
53-
->addOption('skip-branch-name', 'sbn', null, 'Do not validate branch name');
57+
->addOption('skip-branch-name', null, null, 'Do not validate branch name')
58+
->addOption('skip-source-code-urls', null, null, 'Do not validate source code urls');
5459
}
5560

5661
protected function execute(InputInterface $input, OutputInterface $output)
5762
{
5863
$this->input = $input;
5964
$this->output = $output;
6065
$this->validateProd = $input->getOption('validate-prod');
61-
$this->repositoriesCreated = $input->getOption('skip-branch-name') === false;
66+
$this->skipBranchName = $input->getOption('skip-branch-name');
67+
$this->skipSourceCodeUrls = $input->getOption('skip-source-code-urls');
6268

6369
$return = 0;
6470
try {
@@ -90,13 +96,6 @@ protected function getOutput(): OutputInterface
9096
return $this->output;
9197
}
9298

93-
protected function setValidationPrefix(?string $prefix): self
94-
{
95-
$this->validationPrefix = $prefix;
96-
97-
return $this;
98-
}
99-
10099
/** @return $this */
101100
protected function title(string $title): self
102101
{
@@ -108,22 +107,23 @@ protected function title(string $title): self
108107
/** @return $this */
109108
protected function success(string $message): self
110109
{
111-
$this->output->writeln(" \e[42m > \e[00m " . $this->validationPrefix . $message);
110+
$this->output->writeln(" \e[42m > \e[00m " . $message);
112111

113112
return $this;
114113
}
115114

116115
/** @return $this */
117-
protected function warning(string $message): self
116+
protected function warning(string $message, bool $indent = true): self
118117
{
119-
$this->output->writeln(" \e[43m > \e[00m \e[43m " . $this->validationPrefix . $message . " \e[00m");
118+
$prefix = $indent ? " \e[43m > \e[00m " : null;
119+
$this->output->writeln($prefix . "\e[43m " . $message . " \e[00m");
120120

121121
return $this;
122122
}
123123

124124
protected function error(string $error = null): void
125125
{
126-
throw new ValidationException($this->validationPrefix . $error);
126+
throw new ValidationException($error);
127127
}
128128

129129
/** @return $this */
@@ -195,12 +195,15 @@ protected function definePhpCliVersion(string $version): self
195195
/** @return $this */
196196
protected function runCommand(string $name, array $arguments = []): self
197197
{
198-
if ($this->isValidateProd()) {
198+
if ($this->validateProd()) {
199199
$arguments['--validate-prod'] = true;
200200
}
201-
if ($this->isRepositoriesCreated() === false) {
201+
if ($this->skipBranchName()) {
202202
$arguments['--skip-branch-name'] = true;
203203
}
204+
if ($this->skipSourceCodeUrls()) {
205+
$arguments['--skip-source-code-urls'] = true;
206+
}
204207

205208
$returnCode = $this
206209
->getApplication()
@@ -267,21 +270,10 @@ protected function choiceQuestion(string $question, array $choices): string
267270
protected function assertFileExist(string $filePath, string $shortFilePath): self
268271
{
269272
if (is_readable($filePath) === false) {
270-
$this->error('File ' . $shortFilePath . ' does not exist. Use "phpbench initialize:branch" to create it.');
273+
$this->error('File ' . $shortFilePath . ' does not exist. Use "phpbench configure:all" to create it.');
271274
}
272275
$this->success('File ' . $shortFilePath . ' exist.');
273276

274277
return $this;
275278
}
276-
277-
protected function skipBranchNameWarning(): self
278-
{
279-
$this->warning(
280-
'Branch name is not validated.'
281-
. ' Don\'t forget to remove "--skip-branch-name"'
282-
. ' parameter to validate it.'
283-
);
284-
285-
return $this;
286-
}
287279
}

src/Command/ComposerUpdateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ protected function configure()
1414

1515
$this
1616
->setName('composer:update')
17-
->setDescription('Execute composer update for all enabled PHP versions, and create composer.lock.phpX.Y');
17+
->setDescription('Execute composer update for all enabled PHP versions and create composer.lock.phpX.Y');
1818
}
1919

2020
protected function doExecute(): parent

src/Command/AbstractInitializeConfigurationCommand.php renamed to src/Command/Configure/AbstractConfigureCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Command;
5+
namespace App\Command\Configure;
66

7-
abstract class AbstractInitializeConfigurationCommand extends AbstractCommand
7+
use App\Command\AbstractCommand;
8+
9+
abstract class AbstractConfigureCommand extends AbstractCommand
810
{
911
protected function copyDefaultConfigurationFile(
1012
string $file,
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Command\Configure;
6+
7+
abstract class AbstractConfigureComponentCommand extends AbstractConfigureCommand
8+
{
9+
protected function defineVariable(string $name, callable $getValue): self
10+
{
11+
$filePath = $this->getConfigurationPath() . '/AbstractComponentConfiguration.php';
12+
$content = file_get_contents($filePath);
13+
14+
if (strpos($content, $name) !== false) {
15+
$value = call_user_func($getValue);
16+
file_put_contents($filePath, str_replace($name, $value, $content));
17+
$this->success($name . ' defined to ' . $value . '.');
18+
}
19+
20+
return $this;
21+
}
22+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Command\Configure;
6+
7+
use App\Command\AbstractCommand;
8+
9+
class ConfigureAllCommand extends AbstractCommand
10+
{
11+
protected function configure()
12+
{
13+
parent::configure();
14+
15+
$this
16+
->setName('configure:all')
17+
->setDescription('Call all configure commands');
18+
}
19+
20+
protected function doExecute(): parent
21+
{
22+
return $this
23+
->runCommand('configure:directory')
24+
->runCommand('configure:component')
25+
->warningSourceCodeUrls()
26+
->runCommand('configure:component:sourceCodeUrls', ['--skip-component-creation' => true])
27+
->runCommand('configure:initBenchmark')
28+
->runCommand('configure:vhost')
29+
->runCommand('configure:responseBody');
30+
}
31+
32+
protected function warningSourceCodeUrls(): self
33+
{
34+
if ($this->skipSourceCodeUrls() === false) {
35+
$this->warning('You can skip source code urls configuration with --skip-source-code-urls parameter.', false);
36+
}
37+
38+
return $this;
39+
}
40+
}

src/Command/InitializeConfigurationComponentCommand.php renamed to src/Command/Configure/ConfigureComponentCommand.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22

33
declare(strict_types=1);
44

5-
namespace App\Command;
5+
namespace App\Command\Configure;
66

7+
use AbstractComponentConfiguration\AbstractComponentConfiguration;
78
use App\{
89
Benchmark\BenchmarkType,
910
Component\ComponentType,
1011
PhpVersion\PhpVersion
1112
};
1213

13-
class InitializeConfigurationComponentCommand extends AbstractInitializeConfigurationCommand
14+
class ConfigureComponentCommand extends AbstractConfigureComponentCommand
1415
{
1516
protected function configure()
1617
{
1718
parent::configure();
1819

1920
$this
20-
->setName('initialize:configuration:component')
21+
->setName('configure:component')
2122
->setDescription('Create .phpbenchmarks/AbstractComponentConfiguration.php and configure it');
2223
}
2324

@@ -44,7 +45,9 @@ protected function createConfiguration(): self
4445

4546
$this->defineVariable(
4647
'____NAMESPACE____',
47-
function () { return 'AbstractComponentConfiguration'; }
48+
function () {
49+
return 'AbstractComponentConfiguration';
50+
}
4851
);
4952

5053
$this->defineVariable(
@@ -182,16 +185,4 @@ protected function createFile(): self
182185

183186
return $this;
184187
}
185-
186-
protected function defineVariable(string $name, callable $getValue): self
187-
{
188-
$filePath = $this->getConfigurationPath() . '/AbstractComponentConfiguration.php';
189-
$content = file_get_contents($filePath);
190-
191-
if (strpos($content, $name) !== false) {
192-
file_put_contents($filePath, str_replace($name, call_user_func($getValue), $content));
193-
}
194-
195-
return $this;
196-
}
197188
}

0 commit comments

Comments
 (0)