Skip to content

Commit

Permalink
Codebase: add types, codesniffer + phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Nov 15, 2023
1 parent 5109875 commit 0842111
Show file tree
Hide file tree
Showing 29 changed files with 155 additions and 280 deletions.
57 changes: 15 additions & 42 deletions src/Console/GenerateDocuCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php

declare(strict_types=1);
<?php declare(strict_types = 1);

namespace Contributte\Anabelle\Console;

Expand All @@ -21,41 +19,19 @@
final class GenerateDocuCommand extends Command
{

/**
* @var ParamsValidator
*/
private $paramsValidator;

/**
* @var string
*/
private $inputDirectory;
private ParamsValidator $paramsValidator;

/**
* @var string|null
*/
private $addCss;
private string $inputDirectory;

/**
* @var string
*/
private $outputDirectory;
private ?string $addCss = null;

/**
* @var AuthCredentials
*/
private $authCredentials;
private string $outputDirectory;

/**
* @var bool
*/
private $overwriteOutputDir;
private AuthCredentials $authCredentials;

/**
* @var Logger
*/
private $logger;
private bool $overwriteOutputDir;

private Logger $logger;

public function __construct(string $binDir)
{
Expand All @@ -64,7 +40,6 @@ public function __construct(string $binDir)
$this->paramsValidator = new ParamsValidator($binDir);
}


public function initialize(InputInterface $input, OutputInterface $output): void
{
$input->validate();
Expand All @@ -77,27 +52,27 @@ public function initialize(InputInterface $input, OutputInterface $output): void
$addCss = $input->getOption('addCss');

if (!is_string($inputDirectory)) {
throw new \UnexpectedValueException;
throw new \UnexpectedValueException();
}

if (!is_string($outputDirectory)) {
throw new \UnexpectedValueException;
throw new \UnexpectedValueException();
}

if (!is_string($httpAuthUser) && $httpAuthUser !== null) {
throw new \UnexpectedValueException;
throw new \UnexpectedValueException();
}

if (!is_string($httpAuthPass) && $httpAuthPass !== null) {
throw new \UnexpectedValueException;
throw new \UnexpectedValueException();
}

if (!is_bool($overwriteOutputDir)) {
throw new \UnexpectedValueException;
throw new \UnexpectedValueException();
}

if (!is_string($addCss) && $addCss !== null) {
throw new \UnexpectedValueException;
throw new \UnexpectedValueException();
}

$this->inputDirectory = $inputDirectory;
Expand Down Expand Up @@ -130,7 +105,6 @@ public function initialize(InputInterface $input, OutputInterface $output): void
}
}


protected function configure(): void
{
$this->setName('anabelle')
Expand Down Expand Up @@ -178,7 +152,6 @@ protected function configure(): void
);
}


protected function execute(InputInterface $input, OutputInterface $output): int
{
$docuGenerator = new DocuGenerator(
Expand All @@ -204,7 +177,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 0;
}


private function printError(OutputInterface $output, string $message): void
{
$formatter = $this->getHelper('formatter');
Expand All @@ -215,4 +187,5 @@ private function printError(OutputInterface $output, string $message): void
$output->writeln("\n{$block}\n");
}
}

}
5 changes: 2 additions & 3 deletions src/Console/Utils/Exception/ParamsValidatorException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

declare(strict_types=1);
<?php declare(strict_types = 1);

namespace Contributte\Anabelle\Console\Utils\Exception;

class ParamsValidatorException extends \RuntimeException
{

}
10 changes: 5 additions & 5 deletions src/Console/Utils/Logger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php

declare(strict_types=1);
<?php declare(strict_types = 1);

namespace Contributte\Anabelle\Console\Utils;

Expand All @@ -9,13 +7,15 @@
final class Logger
{

public function __construct(private OutputInterface $output) {}

public function __construct(private OutputInterface $output)
{
}

public function logProcessingFile(string $path): void
{
$path = str_replace('/./', '/', $path);

$this->output->writeln("Processing file [$path]...");
}

}
22 changes: 9 additions & 13 deletions src/Console/Utils/ParamsValidator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php

declare(strict_types=1);
<?php declare(strict_types = 1);

namespace Contributte\Anabelle\Console\Utils;

Expand All @@ -10,8 +8,9 @@
final class ParamsValidator
{

public function __construct(private string $binDir) {}

public function __construct(private string $binDir)
{
}

/**
* Validate directory structure (== check for <directory>/index.md)
Expand All @@ -32,7 +31,6 @@ public function validateInputParams(
$this->validateSpecialCssFile($specialCssFile);
}


/**
* @throws ParamsValidatorException
*/
Expand All @@ -47,7 +45,6 @@ private function validateSpecialCssFile(?string $specialCssFile): void
}
}


/**
* @throws ParamsValidatorException
*/
Expand Down Expand Up @@ -80,13 +77,12 @@ private function validateInputDirectory(

if (file_exists($outputDirectory) && !$overwriteOutputDir) {
throw new ParamsValidatorException(
"Output directory path already exists."
. " Delete it or use option [-o] as for \"overwrite\" output directory"
'Output directory path already exists.'
. ' Delete it or use option [-o] as for "overwrite" output directory'
);
}
}


/**
* @throws ParamsValidatorException
*/
Expand All @@ -100,7 +96,6 @@ private function validateIndexFile(string $inputDirectory): void
}
}


/**
* @throws ParamsValidatorException
*/
Expand All @@ -110,11 +105,12 @@ private function validateAuthCredentials(AuthCredentials $authCredentials): void
* Validate HTTP AUTH
*/
if ($authCredentials->getPass() === null && $authCredentials->getUser() !== null) {
throw new ParamsValidatorException("Please set --httpAuthPass [-p]");
throw new ParamsValidatorException('Please set --httpAuthPass [-p]');
}

if ($authCredentials->getPass() !== null && $authCredentials->getUser() === null) {
throw new ParamsValidatorException("Please set --httpAuthUser [-u]");
throw new ParamsValidatorException('Please set --httpAuthUser [-u]');
}
}

}
Loading

0 comments on commit 0842111

Please sign in to comment.