Skip to content

Commit

Permalink
report
Browse files Browse the repository at this point in the history
  • Loading branch information
oliwierptak committed Aug 8, 2021
1 parent 19e7e5c commit bed38f6
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 181 deletions.
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@
"test": [
"vendor/bin/phpunit --no-coverage --testdox --testsuite functional,unit"
],
"report": [
"bin/popo report -s tests/fixtures/popo.yml",
"bin/popo report -s tests/fixtures/popo-namespace-root.yml",
"bin/popo report -s tests/fixtures/popo-readme.yml",
"bin/popo report -c tests/fixtures/bundles/project.config.yml -s tests/fixtures/bundles/"
],
"popo": [
"bin/popo generate -q -s tests/fixtures/popo.yml",
"bin/popo generate -q -s tests/fixtures/popo-namespace-root.yml",
"bin/popo generate -q -s tests/fixtures/popo-readme.yml",
"bin/popo generate -q -c tests/fixtures/bundles/shared.config.yml -s tests/fixtures/bundles/"
"bin/popo generate -q -c tests/fixtures/bundles/project.config.yml -s tests/fixtures/bundles/"
],
"test-c": [
"vendor/bin/phpunit --testdox --testsuite functional,unit"
Expand Down
71 changes: 1 addition & 70 deletions src/Popo/Builder/SchemaBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function build(PopoConfigurator $configurator): array
{
$result = [];
$data = $this->loader->load($configurator);
$sharedSchemaFile = $this->loadSharedConfig($configurator);
$sharedSchemaFile = $this->loader->loadSharedConfig($configurator->getSchemaConfigFilename());
$tree = $this->generateSchemaTree($data, $sharedSchemaFile);

foreach ($tree as $schemaName => $popoCollection) {
Expand Down Expand Up @@ -52,22 +52,6 @@ public function build(PopoConfigurator $configurator): array
return $result;
}

protected function loadSharedConfig(PopoConfigurator $configurator): SchemaFile
{
$file = (new SchemaFile)->setFileConfig(PopoDefinesInterface::SCHEMA_DEFAULT_DATA);

$schemaConfigFilename = trim((string) $configurator->getSchemaConfigFilename());
if ($schemaConfigFilename === '') {
return $file;
}

return current(
$this->loader->load(
(new PopoConfigurator)->setSchemaPath($configurator->getSchemaConfigFilename())
)
);
}

/**
* @param SchemaFile[] $data
* @param \Popo\Schema\SchemaFile $sharedSchemaFile
Expand Down Expand Up @@ -100,59 +84,6 @@ protected function loadSharedConfig(PopoConfigurator $configurator): SchemaFile
return $result;
}

public function generateSchemaReport(PopoConfigurator $configurator): array
{
$sharedSchemaFile = $this->loadSharedConfig($configurator);
$data = $this->loader->load($configurator);

return $this->generateReport($data, $sharedSchemaFile);
}

/**
* @param SchemaFile[] $data
* @param \Popo\Schema\SchemaFile $sharedSchemaFile
*
* @return array
*/
protected function generateReport(array $data, SchemaFile $sharedSchemaFile): array
{
$result = [];

foreach ($data as $schemaFile) {
$fileConfig = $schemaFile->getFileConfig()['property'] ?? [];
$schemaCollection = array_merge($sharedSchemaFile->getData(), $schemaFile->getData());

foreach ($schemaCollection as $schemaName => $popoCollection) {
$schemaConfigData = array_merge(
$sharedSchemaFile->getSchemaConfig()[$schemaName]['property'] ?? [],
$schemaFile->getSchemaConfig()[$schemaName]['property'] ?? []
);

foreach ($popoCollection as $popoName => $popoData) {
foreach ($popoData['property'] as $propertyData) {
$result[$schemaName][$popoName][$propertyData['name']][] = 'property-config:' . $schemaFile
->getFilename()
->getPathname();
}

foreach ($fileConfig as $dataItem) {
$result[$schemaName][$popoName][$dataItem['name']][] = 'file-config:' . $schemaFile
->getFilename()
->getPathname();
}

foreach ($schemaConfigData as $dataItem) {
$result[$schemaName][$popoName][$dataItem['name']][] = 'schema-config:' . $schemaFile
->getFilename()
->getPathname();
}
}
}
}

return $result;
}

public function updateSchemaConfigFromCommandConfiguration(
Schema $popoSchema,
PopoConfigurator $configurator
Expand Down
10 changes: 4 additions & 6 deletions src/Popo/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,14 @@ protected function configure(): void

protected function executeCommand(InputInterface $input, OutputInterface $output): int
{
$configurator = $this->buildConfigurator($input);

$output->writeln('Generating POPO files... ');

$result = $this->facade->generate($configurator);

if ($output->getVerbosity() <= OutputInterface::VERBOSITY_QUIET) {
return 0;
}

$configurator = $this->buildConfigurator($input);
$output->writeln('Generating POPO files... ');
$result = $this->facade->generate($configurator);

$data = [];
foreach ($result->getGeneratedFiles() as $item) {
$data[] = sprintf(
Expand Down
55 changes: 28 additions & 27 deletions src/Popo/Command/ReportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use function implode;

class ReportCommand extends AbstractCommand
{
Expand Down Expand Up @@ -47,7 +46,7 @@ protected function configure(): void
InputOption::VALUE_OPTIONAL,
'Path filter to match POPO schema files.',
null
)
),
]
);
}
Expand All @@ -60,32 +59,30 @@ protected function executeCommand(InputInterface $input, OutputInterface $output

$configurator = $this->buildConfigurator($input);
$output->writeln('POPO Schema Report');
$result = $this->facade->report($configurator);

foreach ($result->getData() as $schemaName => $popoCollection) {
foreach ($popoCollection as $popoName => $propertyCollection) {
foreach ($propertyCollection as $propertyName => $propertyLocations) {
$colorSchemaName = (count($propertyLocations) === 1) ? 'yellow' : 'bright-yellow';
$colorPropertyName = (count($propertyLocations) === 1) ? 'yellow' : 'bright-yellow';
$output->writeln('');

$output->writeln(sprintf(
"<fg=${colorSchemaName}>%s::%s::</><fg=${colorPropertyName}>%s</>",
$schemaName,
$popoName,
$propertyName,
));
$result = $this->facade->report($configurator);

foreach ($propertyLocations as $index => $location) {
$tokens = explode(':',$location);
$output->writeln(sprintf(
' - <fg=cyan>%s</><fg=gray>:</> <fg=green>%s</>',
$tokens[0],
$tokens[1],
));
}
/**
* @var \Popo\Model\Report\ReportResultItem[] $reportItems
*/
foreach ($result->getData() as $propertyName => $reportItems) {
$output->writeln(
sprintf(
"<fg=yellow>%s</>",
$propertyName,
)
);

$output->writeln('');
}
foreach ($reportItems as $reportItem) {
$output->writeln(
sprintf(
" <fg=gray>%s</> <fg=green>%s</> - <fg=cyan>%s</>",
$reportItem->getType(),
$reportItem->getSchemaName() . ($reportItem->getPopoName() ? '::' . $reportItem->getPopoName() : ''),
$reportItem->getSchemaFilename()
)
);
}
}

Expand All @@ -97,10 +94,14 @@ protected function buildConfigurator(InputInterface $input): PopoConfigurator
return (new PopoConfigurator())
->setSchemaPath($input->getOption(static::OPTION_SCHEMA_PATH))
->setSchemaPathFilter(
$input->hasOption(static::OPTION_SCHEMA_PATH_FILTER) ? $input->getOption(static::OPTION_SCHEMA_PATH_FILTER) : null
$input->hasOption(static::OPTION_SCHEMA_PATH_FILTER) ? $input->getOption(
static::OPTION_SCHEMA_PATH_FILTER
) : null
)
->setSchemaConfigFilename(
$input->hasOption(static::OPTION_SCHEMA_CONFIG_FILENAME) ? $input->getOption(static::OPTION_SCHEMA_CONFIG_FILENAME) : null
$input->hasOption(static::OPTION_SCHEMA_CONFIG_FILENAME) ? $input->getOption(
static::OPTION_SCHEMA_CONFIG_FILENAME
) : null
);
}
}
50 changes: 50 additions & 0 deletions src/Popo/Loader/SchemaLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,56 @@ public function __construct(protected FileLocator $fileLocator, protected Loader
{
}

/**
* @param \Popo\PopoConfigurator $configurator
*
* @return SchemaFile[]
*/
#[ArrayShape([SchemaFile::class])] public function loadReport(PopoConfigurator $configurator): array
{
$result = [];
$files = $this->loadSchemaFiles($configurator);

foreach ($files as $configurationFile) {
$schemaConfig = [];
$data = $this->loader->load($configurationFile);
$fileConfig = $data[PopoDefinesInterface::CONFIGURATION_SCHEMA_OPTION_SYMBOL] ?? [];
$data = $this->removeOptionSymbol($data);

foreach ($data as $schemaName => $schemaData) {
if ($this->hasSchemaConfigOption($schemaData)) {
$schemaConfig[$schemaName] = $schemaData[PopoDefinesInterface::CONFIGURATION_SCHEMA_OPTION_SYMBOL] ?? [];
$data[$schemaName] = $this->removeOptionSymbol($schemaData);
}
}

$result[] = (new SchemaFile)
->setFilename($configurationFile)
->setFileConfig($fileConfig)
->setSchemaConfig($schemaConfig)
->setData(
$data
);
}

return $result;
}

public function loadSharedConfig(?string $schemaConfigFilename): SchemaFile
{
$file = (new SchemaFile)->setFileConfig(PopoDefinesInterface::SCHEMA_DEFAULT_DATA);

if (trim((string)$schemaConfigFilename) === '') {
return $file;
}

return current(
$this->load(
(new PopoConfigurator)->setSchemaPath($schemaConfigFilename)
)
);
}

/**
* @param \Popo\PopoConfigurator $configurator
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

declare(strict_types = 1);

namespace Popo\Model;
namespace Popo\Model\Generate;

use Popo\Builder\PopoBuilder;
use Popo\Builder\SchemaBuilder;
use Popo\Model\Generate\GenerateResult;
use Popo\PopoConfigurator;

class PopoModel
class GenerateModel
{
public function __construct(
protected SchemaBuilder $schemaBuilder,
protected PopoBuilder $popoBuilder
) {
}

public function generate(PopoConfigurator $configurator): PopoGenerateResult
public function generate(PopoConfigurator $configurator): GenerateResult
{
$result = new PopoGenerateResult;
$result = new GenerateResult;

$data = $this->schemaBuilder->build($configurator);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types = 1);

namespace Popo\Model;
namespace Popo\Model\Generate;

use JetBrains\PhpStorm\ArrayShape;

class PopoGenerateResult
class GenerateResult
{
protected const ITEM_SHAPE = [
'filename' => 'string',
Expand Down
26 changes: 0 additions & 26 deletions src/Popo/Model/PopoReportResult.php

This file was deleted.

Loading

0 comments on commit bed38f6

Please sign in to comment.