Skip to content

Commit

Permalink
Condig style + Helper command fix
Browse files Browse the repository at this point in the history
- updated Php-Cs-Fixer config
- updated coding style
- fixed `help` command for cli script
  • Loading branch information
tg666 committed Aug 26, 2023
1 parent fa82db0 commit 59dc3d7
Show file tree
Hide file tree
Showing 71 changed files with 2,276 additions and 2,234 deletions.
130 changes: 90 additions & 40 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,100 @@

declare(strict_types=1);

$finder = PhpCsFixer\Finder::create()
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->name(['*.php', '*.phpt'])
->append([
__DIR__ . '/tracy-git-version',
]);

return (new PhpCsFixer\Config())
->setUsingCache(false)
->setIndent("\t")
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'trailing_comma_in_multiline' => true,
'constant_case' => [
'case' => 'lower',
],
'declare_strict_types' => true,
'phpdoc_align' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => ['break', 'continue', 'declare', 'return'],
],
'blank_line_after_namespace' => true,
'single_blank_line_before_namespace' => true,
'return_type_declaration' => [
'space_before' => 'none',
],
'ordered_imports' => [
'sort_algorithm' => 'length',
'imports_order' => ['class', 'function', 'const'],
],
'no_unused_imports' => true,
'single_line_after_imports' => true,
'no_leading_import_slash' => true,
'global_namespace_import' => [
'import_constants' => true,
'import_functions' => true,
'import_classes' => true,
],
'concat_space' => [
'spacing' => 'one',
],
])
->setRiskyAllowed(true)
->setFinder($finder);
return (new Config())
->setUsingCache(false)
->setIndent(" ")
->setRules([
'@PSR2' => true,
'array_syntax' => [
'syntax' => 'short'
],
'trailing_comma_in_multiline' => [
'elements' => [
'arguments',
'arrays',
'match',
'parameters',
],
],
'constant_case' => [
'case' => 'lower',
],
'declare_strict_types' => true,
'phpdoc_align' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => [
'break',
'continue',
'declare',
'return'
],
],
'blank_line_after_namespace' => true,
'single_blank_line_before_namespace' => true,
'return_type_declaration' => [
'space_before' => 'none',
],
'ordered_imports' => [
'sort_algorithm' => 'alpha',
'imports_order' => [
'class',
'function',
'const'
],
],
'no_unused_imports' => true,
'single_line_after_imports' => true,
'no_leading_import_slash' => true,
'global_namespace_import' => [
'import_constants' => true,
'import_functions' => true,
'import_classes' => true,
],
'fully_qualified_strict_types' => true,
'concat_space' => [
'spacing' => 'one',
],
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => false,
'remove_inheritdoc' => true,
'allow_unused_params' => false,
],
'no_empty_phpdoc' => true,
'no_blank_lines_after_phpdoc' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_trim' => true,
'no_extra_blank_lines' => [
'tokens' => [
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'return',
'square_brace_block',
'throw',
'use',
],
],
'single_trait_insert_per_statement' => true,
'single_class_element_per_statement' => [
'elements' => [
'const',
'property',
]
],
'function_typehint_space' => true,
])
->setRiskyAllowed(true)
->setFinder($finder);
8 changes: 4 additions & 4 deletions src/Bridge/Nette/DI/TracyGitVersionConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

final class TracyGitVersionConfig
{
public string $source_name;
public string $source_name;

/** @var array<class-string, Statement> */
public array $command_handlers;
/** @var array<class-string, Statement> */
public array $command_handlers;

public TracyGitVersionPanelConfig $panel;
public TracyGitVersionPanelConfig $panel;
}
8 changes: 4 additions & 4 deletions src/Bridge/Nette/DI/TracyGitVersionExportConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

final class TracyGitVersionExportConfig
{
public string $source_name;
public string $source_name;

public string $export_filename;
public string $export_filename;

/** @var array<Statement> */
public array $command_handlers;
/** @var array<Statement> */
public array $command_handlers;
}
96 changes: 48 additions & 48 deletions src/Bridge/Nette/DI/TracyGitVersionExportExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,67 +4,67 @@

namespace SixtyEightPublishers\TracyGitVersion\Bridge\Nette\DI;

use RuntimeException;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\Statement;
use SixtyEightPublishers\TracyGitVersion\Repository\ExportedGitRepository;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use RuntimeException;
use SixtyEightPublishers\TracyGitVersion\Repository\Command\GetHeadCommand;
use SixtyEightPublishers\TracyGitVersion\Repository\GitRepositoryInterface;
use SixtyEightPublishers\TracyGitVersion\Repository\Command\GetLatestTagCommand;
use SixtyEightPublishers\TracyGitVersion\Repository\Export\CommandHandler\GetHeadCommandHandler;
use SixtyEightPublishers\TracyGitVersion\Repository\Export\CommandHandler\GetLatestTagCommandHandler;
use function count;
use SixtyEightPublishers\TracyGitVersion\Repository\ExportedGitRepository;
use SixtyEightPublishers\TracyGitVersion\Repository\GitRepositoryInterface;
use function array_map;
use function assert;
use function count;
use function sprintf;
use function array_map;

final class TracyGitVersionExportExtension extends CompilerExtension
{
public function getConfigSchema(): Schema
{
$tempDir = $this->getContainerBuilder()->parameters['tempDir'] ?? null;
public function getConfigSchema(): Schema
{
$tempDir = $this->getContainerBuilder()->parameters['tempDir'] ?? null;

return Expect::structure([
'source_name' => Expect::string(GitRepositoryInterface::SOURCE_EXPORT),
'export_filename' => Expect::string($tempDir ? $tempDir . '/git-version/repository.json' : null)->required(null === $tempDir),
'command_handlers' => Expect::arrayOf(Expect::anyOf(Expect::type(Statement::class), Expect::string()), 'string')
->default([
GetHeadCommand::class => new Statement(GetHeadCommandHandler::class),
GetLatestTagCommand::class => new Statement(GetLatestTagCommandHandler::class),
])
->mergeDefaults()
->before(static function (array $items) {
return array_map(static function ($item) {
return $item instanceof Statement ? $item : new Statement($item);
}, $items);
}),
])->castTo(TracyGitVersionExportConfig::class);
}
return Expect::structure([
'source_name' => Expect::string(GitRepositoryInterface::SOURCE_EXPORT),
'export_filename' => Expect::string($tempDir ? $tempDir . '/git-version/repository.json' : null)->required(null === $tempDir),
'command_handlers' => Expect::arrayOf(Expect::anyOf(Expect::type(Statement::class), Expect::string()), 'string')
->default([
GetHeadCommand::class => new Statement(GetHeadCommandHandler::class),
GetLatestTagCommand::class => new Statement(GetLatestTagCommandHandler::class),
])
->mergeDefaults()
->before(static function (array $items) {
return array_map(static function ($item) {
return $item instanceof Statement ? $item : new Statement($item);
}, $items);
}),
])->castTo(TracyGitVersionExportConfig::class);
}

public function loadConfiguration(): void
{
if (0 >= count($this->compiler->getExtensions(TracyGitVersionExtension::class))) {
throw new RuntimeException(sprintf(
'The extension %s can be used only with %s.',
self::class,
TracyGitVersionExtension::class
));
}
public function loadConfiguration(): void
{
if (0 >= count($this->compiler->getExtensions(TracyGitVersionExtension::class))) {
throw new RuntimeException(sprintf(
'The extension %s can be used only with %s.',
self::class,
TracyGitVersionExtension::class,
));
}

$builder = $this->getContainerBuilder();
$config = $this->getConfig();
assert($config instanceof TracyGitVersionExportConfig);
$builder = $this->getContainerBuilder();
$config = $this->getConfig();
assert($config instanceof TracyGitVersionExportConfig);

# exported git repository
$builder->addDefinition($this->prefix('git_repository.exported'))
->setAutowired(false)
->setFactory(ExportedGitRepository::class, [
'file' => $config->export_filename,
'handlers' => $config->command_handlers,
'source' => $config->source_name,
])
->addTag(TracyGitVersionExtension::TAG_GIT_REPOSITORY, 50);
}
# exported git repository
$builder->addDefinition($this->prefix('git_repository.exported'))
->setAutowired(false)
->setFactory(ExportedGitRepository::class, [
'file' => $config->export_filename,
'handlers' => $config->command_handlers,
'source' => $config->source_name,
])
->addTag(TracyGitVersionExtension::TAG_GIT_REPOSITORY, 50);
}
}
Loading

0 comments on commit 59dc3d7

Please sign in to comment.