Skip to content

Commit ad31e46

Browse files
jaapiolinawolf
authored andcommitted
Allow warnings because we use phpdoc
1 parent 9ea3714 commit ad31e46

File tree

8 files changed

+43
-10
lines changed

8 files changed

+43
-10
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ jobs:
3737
dependency-versions: "highest"
3838

3939
- name: "Run guides-cli"
40-
run: "vendor/bin/guides -vvv --no-progress docs --output='/tmp/test' --fail-on-log"
40+
run: "vendor/bin/guides -vvv --no-progress docs --output='/tmp/test' --fail-on-error"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ test-xml: ## Lint all guides.xml
4848

4949
.PHONY: test-docs
5050
test-docs: ## Generate projects docs without warnings
51-
$(PHP_BIN) vendor/bin/guides -vvv --no-progress docs --output="/tmp/test" --fail-on-log
51+
$(PHP_BIN) vendor/bin/guides -vvv --no-progress docs --output="/tmp/test" --fail-on-error
5252

5353
.PHONY: cleanup
5454
cleanup: cleanup-tests cleanup-build cleanup-cache

packages/guides-cli/resources/schema/guides.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<xsd:attribute name="input-format" type="xsd:string"/>
2525
<xsd:attribute name="log-path" type="xsd:string"/>
2626
<xsd:attribute name="fail-on-log" type="xsd:string"/>
27+
<xsd:attribute name="fail-on-error" type="xsd:string"/>
2728
<xsd:attribute name="show-progress" type="xsd:string"/>
2829
<xsd:attribute name="theme" type="xsd:string"/>
2930
<xsd:attribute name="default-code-language" type="xsd:string"/>

packages/guides-cli/src/Command/Run.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use phpDocumentor\Guides\Settings\SettingsManager;
4141
use phpDocumentor\Guides\Twig\Theme\ThemeManager;
4242
use Psr\Clock\ClockInterface;
43+
use Psr\Log\LogLevel;
4344
use RuntimeException;
4445
use Symfony\Component\Console\Command\Command;
4546
use Symfony\Component\Console\Helper\ProgressBar;
@@ -117,6 +118,13 @@ public function __construct(
117118
'If set, returns a non-zero exit code as soon as any warnings/errors occur',
118119
);
119120

121+
$this->addOption(
122+
'fail-on-error',
123+
null,
124+
InputOption::VALUE_NONE,
125+
'If set, returns a non-zero exit code as soon as any errors occur',
126+
);
127+
120128
$this->addOption(
121129
'theme',
122130
null,
@@ -240,8 +248,12 @@ private function getSettingsOverriddenWithInput(InputInterface $input): ProjectS
240248
$settings->setLogPath((string) $input->getOption('log-path'));
241249
}
242250

251+
if ($input->getOption('fail-on-error')) {
252+
$settings->setFailOnError(LogLevel::ERROR);
253+
}
254+
243255
if ($input->getOption('fail-on-log')) {
244-
$settings->setFailOnError(true);
256+
$settings->setFailOnError(LogLevel::WARNING);
245257
}
246258

247259
if (count($input->getOption('output-format')) > 0) {
@@ -290,7 +302,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
290302
}
291303

292304
if ($settings->isFailOnError()) {
293-
$spyProcessor = new SpyProcessor();
305+
$spyProcessor = new SpyProcessor($settings->getFailOnError());
294306
$this->logger->pushProcessor($spyProcessor);
295307
}
296308

packages/guides-cli/src/Logger/SpyProcessor.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
use Monolog\LogRecord;
1717
use Monolog\Processor\ProcessorInterface;
18+
use Psr\Log\LogLevel;
19+
20+
use function strtolower;
1821

1922
/**
2023
* This decorator has an extra method to check whether anything was logged
@@ -25,14 +28,20 @@ final class SpyProcessor implements ProcessorInterface
2528
{
2629
private bool $hasBeenCalled = false;
2730

31+
public function __construct(private string|null $level = LogLevel::WARNING)
32+
{
33+
}
34+
2835
public function hasBeenCalled(): bool
2936
{
3037
return $this->hasBeenCalled;
3138
}
3239

3340
public function __invoke(array|LogRecord $record): array|LogRecord
3441
{
35-
$this->hasBeenCalled = true;
42+
if (strtolower($record['level_name']) === $this->level) {
43+
$this->hasBeenCalled = true;
44+
}
3645

3746
return $record;
3847
}

packages/guides-cli/tests/unit/Logger/SpyProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function testHasBeenCalledReturnsFalseByDefault(): void
2727
public function testItKnowsWhenALogIsEmitted(): void
2828
{
2929
$process = new SpyProcessor();
30-
$process(['channel' => 'test']);
30+
$process(['channel' => 'test', 'level_name' => 'warning']);
3131
self::assertTrue($process->hasBeenCalled());
3232
}
3333
}

packages/guides/src/DependencyInjection/GuidesExtension.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use phpDocumentor\Guides\Settings\SettingsManager;
2222
use phpDocumentor\Guides\Twig\Theme\ThemeConfig;
2323
use phpDocumentor\Guides\Twig\Theme\ThemeManager;
24+
use Psr\Log\LogLevel;
2425
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
2526
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
2627
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -105,6 +106,7 @@ static function ($value) {
105106
->end()
106107
->scalarNode('log_path')->end()
107108
->scalarNode('fail_on_log')->end()
109+
->scalarNode('fail_on_error')->end()
108110
->scalarNode('show_progress')->end()
109111
->scalarNode('links_are_relative')->end()
110112
->scalarNode('max_menu_depth')->end()
@@ -223,8 +225,12 @@ public function load(array $configs, ContainerBuilder $container): void
223225
$projectSettings->setShowProgressBar((bool) $config['show_progress']);
224226
}
225227

228+
if (isset($config['fail_on_error'])) {
229+
$projectSettings->setFailOnError(LogLevel::ERROR);
230+
}
231+
226232
if (isset($config['fail_on_log'])) {
227-
$projectSettings->setFailOnError((bool) $config['show_progress']);
233+
$projectSettings->setFailOnError(LogLevel::WARNING);
228234
}
229235

230236
if (isset($config['max_menu_depth'])) {

packages/guides/src/Settings/ProjectSettings.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final class ProjectSettings
2929
/** @var string[] */
3030
private array $outputFormats = ['html'];
3131
private string $logPath = 'php://stder';
32-
private bool $failOnError = false;
32+
private string|null $failOnError = null;
3333
private bool $showProgressBar = true;
3434
private bool $linksRelative = false;
3535
private string $defaultCodeLanguage = '';
@@ -118,13 +118,18 @@ public function setLogPath(string $logPath): void
118118
}
119119

120120
public function isFailOnError(): bool
121+
{
122+
return $this->failOnError !== null;
123+
}
124+
125+
public function getFailOnError(): string|null
121126
{
122127
return $this->failOnError;
123128
}
124129

125-
public function setFailOnError(bool $failOnError): void
130+
public function setFailOnError(string $logLevel): void
126131
{
127-
$this->failOnError = $failOnError;
132+
$this->failOnError = $logLevel;
128133
}
129134

130135
public function isShowProgressBar(): bool

0 commit comments

Comments
 (0)