Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Build/ProjectBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace CommonDoc\Aggregate\Build;

use CommonDoc\Aggregate\Discovery\Project;
use CommonDoc\Aggregate\Exception\MissingDocDirectoryException;
use CommonDoc\Aggregate\Exception\SourceUnavailableException;
use CommonDoc\Aggregate\Render\SiteRendererInterface;
use CommonDoc\Aggregate\Source\MissingDocDirectory;
use CommonDoc\Aggregate\Source\SourceInterface;
use CommonDoc\Aggregate\Source\SourceUnavailable;
use CommonDoc\Aggregate\Version\Strategy;
use CommonDoc\Aggregate\Version\StrategyFactory;
use CommonDoc\Aggregate\Version\Target;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function outcome(Project $project, Strategy $strategy): ProjectOutcome
$targets = $this->strategies
->create($strategy, $project)
->resolve($this->source->candidates($project));
} catch (SourceUnavailable $sourceUnavailable) {
} catch (SourceUnavailableException $sourceUnavailable) {
return ProjectOutcome::failed($project, $sourceUnavailable->reasonCode);
}

Expand All @@ -68,7 +68,7 @@ private function render(Project $project, array $targets): ProjectOutcome
foreach ($targets as $target) {
try {
$documents = $this->source->documents($target);
} catch (MissingDocDirectory|SourceUnavailable $unavailable) {
} catch (MissingDocDirectoryException|SourceUnavailableException $unavailable) {
$reasons[] = $unavailable->reasonCode;

continue;
Expand Down
4 changes: 2 additions & 2 deletions src/Build/SiteBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use CommonDoc\Aggregate\Config\SiteConfig;
use CommonDoc\Aggregate\Discovery\Project;
use CommonDoc\Aggregate\Discovery\ProjectSourceInterface;
use CommonDoc\Aggregate\Exception\MissingCnameException;
use CommonDoc\Aggregate\Output\CnameFile;
use CommonDoc\Aggregate\Output\MissingCname;
use CommonDoc\Aggregate\Output\OutputTree;
use CommonDoc\Aggregate\Render\SiteRendererInterface;
use CommonDoc\Aggregate\Report\ReportFile;
Expand Down Expand Up @@ -46,7 +46,7 @@
*
* @throws InvalidArgumentException When the output tree, the totals or the report path refuse the build
* @throws JsonException When the report cannot be encoded
* @throws MissingCname When the site address file does not hold the configured hostname
* @throws MissingCnameException When the site address file does not hold the configured hostname
* @throws RuntimeException When the output tree or the report cannot be written
* @throws TemplateExceptionInterface When a page cannot be rendered
*/
Expand All @@ -66,14 +66,14 @@
array_push($rendered, ...$outcome->targets);
}

usort($rendered, Target::compare(...));

Check warning on line 69 in src/Build/SiteBuild.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ array_push($rendered, ...$outcome->targets); } - usort($rendered, Target::compare(...)); + $this->renderer->writeSiteIndex($rendered); $this->renderer->writeNotFoundPage();

Check warning on line 69 in src/Build/SiteBuild.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ array_push($rendered, ...$outcome->targets); } - usort($rendered, Target::compare(...)); + $this->renderer->writeSiteIndex($rendered); $this->renderer->writeNotFoundPage();

$this->renderer->writeSiteIndex($rendered);
$this->renderer->writeNotFoundPage();

$cname = new CnameFile($tree, $config->hostname);
$cname->write();
$cname->verify();

Check warning on line 76 in src/Build/SiteBuild.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $cname = new CnameFile($tree, $config->hostname); $cname->write(); - $cname->verify(); + $totals = Total::of($results); $report = new BuildReport(

Check warning on line 76 in src/Build/SiteBuild.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "MethodCallRemoval": @@ @@ $cname = new CnameFile($tree, $config->hostname); $cname->write(); - $cname->verify(); + $totals = Total::of($results); $report = new BuildReport(

$totals = Total::of($results);
$report = new BuildReport(
Expand Down
22 changes: 12 additions & 10 deletions src/Config/Section.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace CommonDoc\Aggregate\Config;

use CommonDoc\Aggregate\Exception\InvalidSiteConfigException;

use function array_key_exists;
use function array_keys;
use function array_map;
Expand Down Expand Up @@ -50,26 +52,26 @@ public function keys(): array
}

/**
* @throws InvalidSiteConfig When the key is absent or does not hold an object
* @throws InvalidSiteConfigException When the key is absent or does not hold an object
*/
public function object(string $key): self
{
if (! array_key_exists($key, $this->members)) {
throw InvalidSiteConfig::at($this->pathFor($key), 'is required.');
throw InvalidSiteConfigException::at($this->pathFor($key), 'is required.');
}

/** @var mixed $value */
$value = $this->members[$key];

if (! is_array($value)) {
throw InvalidSiteConfig::at($this->pathFor($key), 'must be an object.');
throw InvalidSiteConfigException::at($this->pathFor($key), 'must be an object.');
}

return new self($value, $this->pathFor($key));
}

/**
* @throws InvalidSiteConfig When the key is present but does not hold an object
* @throws InvalidSiteConfigException When the key is present but does not hold an object
*/
public function optionalObject(string $key): ?self
{
Expand All @@ -79,7 +81,7 @@ public function optionalObject(string $key): ?self
/**
* @return non-empty-string|null
*
* @throws InvalidSiteConfig When the key is present but does not hold a non-empty string
* @throws InvalidSiteConfigException When the key is present but does not hold a non-empty string
*/
public function optionalString(string $key): ?string
{
Expand All @@ -97,7 +99,7 @@ public function pathFor(string $key): string
/**
* @param list<string> $allowed
*
* @throws InvalidSiteConfig When the section carries a key the schema does not declare
* @throws InvalidSiteConfigException When the section carries a key the schema does not declare
*/
public function rejectUnknownKeys(array $allowed): void
{
Expand All @@ -106,26 +108,26 @@ public function rejectUnknownKeys(array $allowed): void
continue;
}

throw InvalidSiteConfig::at($this->pathFor((string) $key), 'is not a known key.');
throw InvalidSiteConfigException::at($this->pathFor((string) $key), 'is not a known key.');
}
}

/**
* @return non-empty-string
*
* @throws InvalidSiteConfig When the key is absent or does not hold a non-empty string
* @throws InvalidSiteConfigException When the key is absent or does not hold a non-empty string
*/
public function string(string $key): string
{
if (! array_key_exists($key, $this->members)) {
throw InvalidSiteConfig::at($this->pathFor($key), 'is required.');
throw InvalidSiteConfigException::at($this->pathFor($key), 'is required.');
}

/** @var mixed $value */
$value = $this->members[$key];

if (! is_string($value) || '' === $value) {
throw InvalidSiteConfig::at($this->pathFor($key), 'must be a non-empty string.');
throw InvalidSiteConfigException::at($this->pathFor($key), 'must be a non-empty string.');
}

return $value;
Expand Down
25 changes: 13 additions & 12 deletions src/Config/SiteConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace CommonDoc\Aggregate\Config;

use CommonDoc\Aggregate\Exception\InvalidSiteConfigException;
use CommonDoc\Aggregate\Version\Strategy;
use JsonException;

Expand Down Expand Up @@ -48,7 +49,7 @@
private const string CACHE_DIRECTORY_DEFAULT = '.cache/multi-repo';

/**
* @throws InvalidSiteConfig When the file cannot be read or does not satisfy the schema
* @throws InvalidSiteConfigException When the file cannot be read or does not satisfy the schema
*/
public function read(string $path): SiteConfig
{
Expand Down Expand Up @@ -96,29 +97,29 @@
/**
* @return array<array-key, mixed>
*
* @throws InvalidSiteConfig When the file cannot be read or does not hold JSON
* @throws InvalidSiteConfigException When the file cannot be read or does not hold JSON
*/
private function decode(string $path): array
{
$contents = is_readable($path) ? file_get_contents($path) : false;

if (false === $contents) {
throw InvalidSiteConfig::at('site.json', sprintf('"%s" cannot be read.', $path));
throw InvalidSiteConfigException::at('site.json', sprintf('"%s" cannot be read.', $path));
}

try {
/** @var mixed $decoded */
$decoded = json_decode($contents, associative: true, depth: 512, flags: JSON_THROW_ON_ERROR);
} catch (JsonException $exception) {
throw InvalidSiteConfig::at('site.json', sprintf(
throw InvalidSiteConfigException::at('site.json', sprintf(
'"%s" is not valid JSON: %s',
$path,
$exception->getMessage(),
));
}

if (! is_array($decoded)) {
throw InvalidSiteConfig::at('site.json', 'the file does not hold a JSON object.');
throw InvalidSiteConfigException::at('site.json', 'the file does not hold a JSON object.');
}

return $decoded;
Expand All @@ -129,12 +130,12 @@
*
* @return non-empty-string
*
* @throws InvalidSiteConfig When the value is not a bare host name
* @throws InvalidSiteConfigException When the value is not a bare host name
*/
private function hostname(string $configured): string
{
if (preg_match(self::HOSTNAME_PATTERN, $configured) !== 1) {
throw InvalidSiteConfig::at(
throw InvalidSiteConfigException::at(
'site.hostname',
sprintf('"%s" is not a bare host name without a scheme or a slash.', $configured),
);
Expand All @@ -149,11 +150,11 @@
? $path
: $base . DIRECTORY_SEPARATOR . $path;

return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $joined);

Check warning on line 153 in src/Config/SiteConfigReader.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ ? $path : $base . DIRECTORY_SEPARATOR . $path; - return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $joined); + return str_replace(['\\'], DIRECTORY_SEPARATOR, $joined); } /**

Check warning on line 153 in src/Config/SiteConfigReader.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ ? $path : $base . DIRECTORY_SEPARATOR . $path; - return str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $joined); + return str_replace(['\\'], DIRECTORY_SEPARATOR, $joined); } /**
}

/**
* @throws InvalidSiteConfig When the configured strategy is not a member
* @throws InvalidSiteConfigException When the configured strategy is not a member
*/
private function strategy(Section $root): Strategy
{
Expand All @@ -173,7 +174,7 @@
/**
* @return array<string, non-empty-string>
*
* @throws InvalidSiteConfig When a mapped template is not a readable file
* @throws InvalidSiteConfigException When a mapped template is not a readable file
*/
private function templateMap(Section $root, string $base): array
{
Expand All @@ -198,7 +199,7 @@
$resolved = $this->resolved($templatePath, $base);

if (! is_file($resolved) || ! is_readable($resolved)) {
throw InvalidSiteConfig::at(
throw InvalidSiteConfigException::at(
$map->pathFor($name),
sprintf('"%s" is not a readable file.', $resolved),
);
Expand All @@ -215,12 +216,12 @@
*
* @return non-empty-string
*
* @throws InvalidSiteConfig When the value is not an environment variable name
* @throws InvalidSiteConfigException When the value is not an environment variable name
*/
private function tokenVariable(string $configured): string
{
if (preg_match(self::TOKEN_ENV_VAR_PATTERN, $configured) !== 1) {
throw InvalidSiteConfig::at(
throw InvalidSiteConfigException::at(
'organization.tokenEnvVar',
sprintf('"%s" is not an environment variable name.', $configured),
);
Expand Down
8 changes: 4 additions & 4 deletions src/Console/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

use CommonDoc\Aggregate\Build\BuildReport;
use CommonDoc\Aggregate\Build\SiteBuildFactoryInterface;
use CommonDoc\Aggregate\Config\InvalidSiteConfig;
use CommonDoc\Aggregate\Config\SiteConfigReader;
use CommonDoc\Aggregate\Output\MissingCname;
use CommonDoc\Aggregate\Exception\InvalidSiteConfigException;
use CommonDoc\Aggregate\Exception\MissingCnameException;
use CommonDoc\Aggregate\Report\ReportFile;
use CommonDoc\Aggregate\Report\ReportFileFactoryInterface;
use InvalidArgumentException;
Expand Down Expand Up @@ -90,7 +90,7 @@
* @throws ExceptionInterface When an option cannot be read
* @throws InvalidArgumentException When the report path or the report itself is refused
* @throws JsonException When the report cannot be encoded as JSON
* @throws MissingCname When the site address file does not hold the configured hostname
* @throws MissingCnameException When the site address file does not hold the configured hostname
* @throws RuntimeException When the output tree or the report cannot be written
* @throws AlreadyInitializedException When the markdown environment has already been configured
* @throws TemplateExceptionInterface When a page cannot be rendered
Expand All @@ -106,7 +106,7 @@

try {
$config = $this->reader->read($path);
} catch (InvalidSiteConfig $invalid) {
} catch (InvalidSiteConfigException $invalid) {
$this->errorsOf($output)->writeln(sprintf('<error>%s</error>', $invalid->getMessage()));

return self::EXIT_BLOCKED;
Expand Down Expand Up @@ -143,7 +143,7 @@
$output->writeln(sprintf(
'site:build: %d pages in %d projects (%d ok, %d partial, %d failed, %d skipped)',
$report->totals->pages,
$report->totals->ok + $report->totals->partial + $report->totals->failed + $report->totals->skipped,

Check warning on line 146 in src/Console/BuildCommand.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "Plus": @@ @@ $output->writeln(sprintf( 'site:build: %d pages in %d projects (%d ok, %d partial, %d failed, %d skipped)', $report->totals->pages, - $report->totals->ok + $report->totals->partial + $report->totals->failed + $report->totals->skipped, + $report->totals->ok + $report->totals->partial + $report->totals->failed - $report->totals->skipped, $report->totals->ok, $report->totals->partial, $report->totals->failed,

Check warning on line 146 in src/Console/BuildCommand.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "Plus": @@ @@ $output->writeln(sprintf( 'site:build: %d pages in %d projects (%d ok, %d partial, %d failed, %d skipped)', $report->totals->pages, - $report->totals->ok + $report->totals->partial + $report->totals->failed + $report->totals->skipped, + $report->totals->ok + $report->totals->partial + $report->totals->failed - $report->totals->skipped, $report->totals->ok, $report->totals->partial, $report->totals->failed,
$report->totals->ok,
$report->totals->partial,
$report->totals->failed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace CommonDoc\Aggregate\Source;
namespace CommonDoc\Aggregate\Exception;

use RuntimeException;

Expand All @@ -28,7 +28,7 @@
* where a credential would travel. Diagnostics are trimmed and truncated so a remote that echoes a
* long page cannot turn a failure into an unreadable report.
*/
final class GitFailure extends RuntimeException
final class GitFailureException extends RuntimeException
{
private const int DIAGNOSTIC_LIMIT = 400;

Expand Down Expand Up @@ -63,7 +63,7 @@
separator: ' ',
array : $arguments,
),
null === $exitCode ? 'no code' : (string) $exitCode,

Check warning on line 66 in src/Exception/GitFailureException.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "CastString": @@ @@ separator: ' ', array : $arguments, ), - null === $exitCode ? 'no code' : (string) $exitCode, + null === $exitCode ? 'no code' : $exitCode, self::diagnostic(diagnostic: $diagnostic), )); }

Check warning on line 66 in src/Exception/GitFailureException.php

View workflow job for this annotation

GitHub Actions / Mutation testing

Escaped Mutant for Mutator "CastString": @@ @@ separator: ' ', array : $arguments, ), - null === $exitCode ? 'no code' : (string) $exitCode, + null === $exitCode ? 'no code' : $exitCode, self::diagnostic(diagnostic: $diagnostic), )); }
self::diagnostic(diagnostic: $diagnostic),
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace CommonDoc\Aggregate\Config;
namespace CommonDoc\Aggregate\Exception;

use CommonDoc\Aggregate\Build\ReasonCode;
use RuntimeException;
Expand All @@ -27,7 +27,7 @@
* has to deduce the vocabulary from the message. Configuration is read before anything is rendered,
* so this always exits blocked and never produces a report.
*/
final class InvalidSiteConfig extends RuntimeException
final class InvalidSiteConfigException extends RuntimeException
{
private function __construct(
public readonly string $key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
* file that was distributed with this source code.
*/

namespace CommonDoc\Aggregate\Output;
namespace CommonDoc\Aggregate\Exception;

use CommonDoc\Aggregate\Build\ReasonCode;
use CommonDoc\Aggregate\Output\CnameFile;
use RuntimeException;

use function sprintf;
Expand All @@ -27,7 +28,7 @@
* travels with the exception so the report and the process exit code cannot disagree about why the
* build stopped.
*/
final class MissingCname extends RuntimeException
final class MissingCnameException extends RuntimeException
{
private function __construct(
public readonly ReasonCode $reasonCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace CommonDoc\Aggregate\Source;
namespace CommonDoc\Aggregate\Exception;

use CommonDoc\Aggregate\Build\ReasonCode;
use CommonDoc\Aggregate\Discovery\Project;
Expand All @@ -26,7 +26,7 @@
* This is a defect in the project rather than in the build, so it carries its own reason code: the
* repository custom property names a directory that the resolved ref does not have.
*/
final class MissingDocDirectory extends RuntimeException
final class MissingDocDirectoryException extends RuntimeException
{
private function __construct(
public readonly ReasonCode $reasonCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace CommonDoc\Aggregate\Source;
namespace CommonDoc\Aggregate\Exception;

use CommonDoc\Aggregate\Build\ReasonCode;
use CommonDoc\Aggregate\Discovery\Project;
Expand All @@ -27,7 +27,7 @@
* The reason code travels with the exception so the report and the process exit code cannot disagree
* about why the project was skipped.
*/
final class SourceUnavailable extends RuntimeException
final class SourceUnavailableException extends RuntimeException
{
private function __construct(
public readonly ReasonCode $reasonCode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* file that was distributed with this source code.
*/

namespace CommonDoc\Aggregate\Render;
namespace CommonDoc\Aggregate\Exception;

use CommonDoc\Aggregate\Build\ReasonCode;
use CommonDoc\Aggregate\Version\Target;
Expand All @@ -31,7 +31,7 @@
* The reason code is carried rather than assumed by the caller, so the report cannot disagree with
* what happened.
*/
final class UnaddressableDocument extends RuntimeException
final class UnaddressableDocumentException extends RuntimeException
{
private function __construct(
public readonly ReasonCode $reasonCode,
Expand Down
Loading
Loading