-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This command is designed to validate syntax in schema files. Files can be of YAML, JSON or PHP format and the path to these schema files can be defined. Errors in schema syntax are caught and reported.
- Loading branch information
Showing
17 changed files
with
535 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
/** | ||
* JBZoo Toolbox - Csv-Blueprint. | ||
* | ||
* This file is part of the JBZoo Toolbox project. | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @license MIT | ||
* @copyright Copyright (C) JBZoo.com, All rights reserved. | ||
* @see https://github.com/JBZoo/Csv-Blueprint | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace JBZoo\CsvBlueprint\Commands; | ||
|
||
use JBZoo\Cli\CliCommand; | ||
use JBZoo\CsvBlueprint\Exception; | ||
use JBZoo\CsvBlueprint\Utils; | ||
use JBZoo\CsvBlueprint\Validators\ErrorSuite; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
|
||
use function JBZoo\Utils\bool; | ||
|
||
/** | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
abstract class AbstractValidate extends CliCommand | ||
{ | ||
protected function configure(): void | ||
{ | ||
$this | ||
->addOption( | ||
'report', | ||
'r', | ||
InputOption::VALUE_REQUIRED, | ||
"Report output format. Available options:\n" . | ||
Utils::printList(ErrorSuite::getAvaiableRenderFormats(), 'info'), | ||
ErrorSuite::REPORT_DEFAULT, | ||
) | ||
->addOption( | ||
'quick', | ||
'Q', | ||
InputOption::VALUE_OPTIONAL, | ||
"Immediately terminate the check at the first error found.\n" . | ||
"Of course it will speed up the check, but you will get only 1 message out of many.\n" . | ||
"If any error is detected, the utility will return a non-zero exit code.\n" . | ||
'Empty value or "yes" will be treated as "true".', | ||
'no', | ||
) | ||
->addOption( | ||
'debug', | ||
null, | ||
InputOption::VALUE_NONE, | ||
"It's ONLY for debugging and advanced profiling!", | ||
); | ||
|
||
parent::configure(); | ||
} | ||
|
||
protected function preparation(): void | ||
{ | ||
if ($this->isHumanReadableMode()) { | ||
$this->_('CSV Blueprint: ' . Utils::getVersion(true)); | ||
} | ||
|
||
if ($this->getOptBool('debug')) { | ||
\define('DEBUG_MODE', true); | ||
} | ||
} | ||
|
||
protected function isHumanReadableMode(): bool | ||
{ | ||
return $this->getReportType() !== ErrorSuite::REPORT_GITLAB | ||
&& $this->getReportType() !== ErrorSuite::REPORT_JUNIT | ||
&& $this->getReportType() !== ErrorSuite::REPORT_TEAMCITY; | ||
} | ||
|
||
protected function getReportType(): string | ||
{ | ||
return $this->getOptString('report', ErrorSuite::RENDER_TABLE, ErrorSuite::getAvaiableRenderFormats()); | ||
} | ||
|
||
protected function isQuickMode(): bool | ||
{ | ||
$value = $this->getOptString('quick'); | ||
return $value === '' || bool($value); | ||
} | ||
|
||
protected function out(null|array|string $messge): void | ||
{ | ||
if ($this->isHumanReadableMode()) { | ||
$this->_($messge); | ||
} | ||
} | ||
|
||
/** | ||
* @return SplFileInfo[] | ||
*/ | ||
protected function findFiles(string $option, bool $throwException = true): array | ||
{ | ||
$patterns = $this->getOptArray($option); | ||
$filenames = \array_values(Utils::findFiles($patterns)); | ||
|
||
if ($throwException && \count($filenames) === 0) { | ||
throw new Exception('File(s) not found: ' . Utils::printList($patterns)); | ||
} | ||
|
||
return $filenames; | ||
} | ||
} |
Oops, something went wrong.