Skip to content

Commit d6eaaf2

Browse files
committed
Clean up unnecessary comments and docblocks
Remove obvious/redundant comments and docblocks that merely describe what the code already clearly shows: - Removed comments like '// Get existing secret', '// Build column headers', '// Load template' - Removed docblocks that just restate method names like 'Get the configured template directory path' for getTemplatePath() - Removed inline comments explaining simple language features - Kept only meaningful documentation that explains non-obvious behavior or architectural decisions This follows the principle in CLAUDE.md: 'No comments unless documenting complex business logic' All tests passing (653 passed)
1 parent c011fce commit d6eaaf2

File tree

9 files changed

+1
-195
lines changed

9 files changed

+1
-195
lines changed

src/Commands/DiffCommand.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ protected function getVaultsToCompare(): array
6666
return array_intersect($requestedVaults, $configuredVaultNames);
6767
}
6868

69-
// Default to all configured vaults
7069
return Keep::getConfiguredVaults()->keys()->toArray();
7170
}
7271

@@ -75,7 +74,6 @@ protected function getStagesToCompare(): array
7574
$stagesOption = $this->option('stage');
7675

7776
if ($stagesOption) {
78-
// Parse comma-separated stages and validate them
7977
$requestedStages = array_map('trim', explode(',', $stagesOption));
8078
$availableStages = Keep::getStages();
8179

@@ -87,7 +85,6 @@ protected function getStagesToCompare(): array
8785
return array_intersect($requestedStages, $availableStages);
8886
}
8987

90-
// Default to all configured stages
9188
return Keep::getStages();
9289
}
9390

@@ -96,7 +93,6 @@ protected function displayTable(Collection $diffs, array $vaults, array $stages)
9693
$this->newLine();
9794
$this->info('Secret Comparison Matrix');
9895

99-
// Build column headers
10096
$headers = ['Key'];
10197
$vaultStageCombinations = [];
10298

@@ -110,7 +106,6 @@ protected function displayTable(Collection $diffs, array $vaults, array $stages)
110106

111107
$headers[] = 'Status';
112108

113-
// Build table rows
114109
$rows = $diffs->map(function (SecretDiff $diff) use ($vaultStageCombinations) {
115110
$row = [$diff->key()];
116111

src/Commands/RunCommand.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ public function __construct(Filesystem $filesystem)
4343
$this->processRunner = new ProcessRunner();
4444
}
4545

46-
/**
47-
* Override run to provide better error message for missing command
48-
*/
4946
public function run(InputInterface $input, OutputInterface $output): int
5047
{
5148
try {
@@ -65,34 +62,27 @@ public function run(InputInterface $input, OutputInterface $output): int
6562

6663
protected function process(): int
6764
{
68-
// Get command and arguments
6965
$commandArgs = $this->argument('cmd');
70-
71-
// Validate command exists
7266
$command = $commandArgs[0];
7367
if (!$this->processRunner->commandExists($command) && !file_exists($command)) {
7468
error("Command not found: {$command}");
7569
return self::FAILURE;
7670
}
7771

78-
// Gather stage and vault
7972
$stage = $this->stage();
8073
$vault = $this->vaultName();
8174

8275
info("🚀 Preparing environment for: " . implode(' ', $commandArgs));
8376

8477
try {
85-
// Build environment variables
8678
$environment = $this->buildEnvironment($stage, $vault);
8779

88-
// Determine if we should inherit current environment
8980
$inheritCurrent = !$this->option('no-inherit');
9081

9182
if (!$inheritCurrent) {
9283
note('Running with clean environment (secrets only)');
9384
}
9485

95-
// Execute the command
9686
info("📦 Executing command with injected secrets...\n");
9787

9888
$result = $this->processRunner->run(
@@ -101,12 +91,9 @@ protected function process(): int
10191
getcwd()
10292
);
10393

104-
// Clear sensitive data from memory
10594
foreach ($environment as $key => $value) {
10695
unset($environment[$key]);
10796
}
108-
109-
// Return the exit code from the subprocess
11097
if (!$result->successful) {
11198
error("\n❌ Command failed with exit code: {$result->exitCode}");
11299
} else {
@@ -124,80 +111,56 @@ protected function process(): int
124111
}
125112
}
126113

127-
/**
128-
* Build environment variables from secrets
129-
*/
130114
protected function buildEnvironment(string $stage, string $vaultSlug): array
131115
{
132116
$templateOption = $this->option('template');
133117
$inheritCurrent = !$this->option('no-inherit');
134118

135-
// Handle template-based injection
136-
// Only use template if --template option is explicitly provided
137-
// But only if no filters are specified (filters only work in direct mode)
138119
$hasFilters = $this->option('only') || $this->option('except');
139120

140121
if (!$hasFilters && $templateOption !== null) {
141-
// If template value is empty string, it means auto-discovery
142122
$templatePath = $templateOption === '' ? null : $templateOption;
143123
return $this->buildFromTemplate($templatePath, $stage, $vaultSlug, $inheritCurrent);
144124
}
145125

146-
// Direct secret injection (all secrets from vault)
147126
return $this->buildFromVault($stage, $vaultSlug, $inheritCurrent);
148127
}
149128

150-
/**
151-
* Build environment from template
152-
*/
153129
protected function buildFromTemplate(?string $templatePath, string $stage, string $vaultSlug, bool $inheritCurrent): array
154130
{
155-
// Resolve template path if empty
156131
if ($templatePath === null) {
157132
$templatePath = $this->resolveTemplateForStage($stage);
158133
note("Using template: {$templatePath}");
159134
}
160135

161-
// Load template
162136
if (!file_exists($templatePath)) {
163137
throw new \InvalidArgumentException("Template file not found: {$templatePath}");
164138
}
165139

166140
$templateContent = file_get_contents($templatePath);
167141
$template = new Template($templateContent);
168142

169-
// Get referenced vaults from template
170143
$referencedVaults = $template->allReferencedVaults();
171144

172-
// Load vaults
173145
$vaults = [];
174146
if (empty($referencedVaults)) {
175-
// No vault references in template, use specified vault
176147
$vaults[$vaultSlug] = Keep::vault($vaultSlug, $stage);
177148
} else {
178-
// Load all referenced vaults
179149
foreach ($referencedVaults as $vaultRef) {
180150
$vaults[$vaultRef] = Keep::vault($vaultRef, $stage);
181151
}
182152
}
183153

184-
// Build environment from template
185154
return $template->toEnvironment($vaults, $inheritCurrent);
186155
}
187156

188-
/**
189-
* Build environment from all vault secrets
190-
*/
191157
protected function buildFromVault(string $stage, string $vaultSlug, bool $inheritCurrent): array
192158
{
193159
$vault = Keep::vault($vaultSlug, $stage);
194160

195161
info("Loading secrets from {$vaultSlug}:{$stage}");
196162

197-
// Fetch all secrets
198163
$secrets = $vault->list();
199-
200-
// Apply filters if provided
201164
$only = $this->option('only');
202165
$except = $this->option('except');
203166

@@ -215,7 +178,6 @@ protected function buildFromVault(string $stage, string $vaultSlug, bool $inheri
215178

216179
note("Injecting {$secrets->count()} secret(s) as environment variables");
217180

218-
// Build environment
219181
return $secrets->toEnvironment($inheritCurrent);
220182
}
221183
}

src/Data/Collections/SecretCollection.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public function toCsvString(): string
4949

5050
protected function escapeCsvField(string $field): string
5151
{
52-
// If field contains comma, quotes, or newline, wrap in quotes and escape quotes
5352
if (preg_match('/[,"\n\r]/', $field)) {
5453
return '"' . str_replace('"', '""', $field) . '"';
5554
}
@@ -96,9 +95,6 @@ public function mapToOnly($keys = [])
9695
return $this->map->only($keys);
9796
}
9897

99-
/**
100-
* Convert collection to array format suitable for API responses.
101-
*/
10298
public function toApiArray(bool $unmask = false): array
10399
{
104100
return $this->map(fn (Secret $secret) => $secret->toApiArray($unmask))
@@ -123,9 +119,6 @@ public static function loadFromVaults(array $vaultNames, string $stage): static
123119
return $allSecrets;
124120
}
125121

126-
/**
127-
* Build environment variables array from secrets.
128-
*/
129122
public function toEnvironment(bool $inheritCurrent = true): array
130123
{
131124
$env = $inheritCurrent ? getenv() : [];
@@ -138,9 +131,6 @@ public function toEnvironment(bool $inheritCurrent = true): array
138131
return $env;
139132
}
140133

141-
/**
142-
* Compare secrets across vault/stage combinations.
143-
*/
144134
public static function compare(array $vaults, array $stages, ?string $only = null, ?string $except = null): Collection
145135
{
146136
$allSecrets = static::gatherSecrets($vaults, $stages, $only, $except);
@@ -189,9 +179,6 @@ protected static function extractAllKeys(array $allSecrets): Collection
189179
return $allKeys->unique()->sort()->values();
190180
}
191181

192-
/**
193-
* Generate summary statistics for diff results.
194-
*/
195182
public static function generateDiffSummary(Collection $diffs, array $vaults, array $stages): array
196183
{
197184
$totalSecrets = $diffs->count();

src/Data/Template.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ public function merge(SecretCollection $secrets, MissingSecretStrategy $strategy
7474
}, $this->contents);
7575
}
7676

77-
/**
78-
* Extract all vault names referenced in this template's placeholders.
79-
*
80-
* @return array<string> Unique vault names found in placeholders
81-
*/
8277
public function allReferencedVaults(): array
8378
{
8479
if ($this->isEmpty()) {
@@ -91,13 +86,6 @@ public function allReferencedVaults(): array
9186
return array_unique($matches[1] ?? []);
9287
}
9388

94-
/**
95-
* Build environment variables array from template.
96-
*
97-
* @param array<string, AbstractVault> $vaults Array of vaults keyed by slug
98-
* @param bool $inheritCurrent Whether to inherit current environment
99-
* @return array<string, string> Key-value pairs for environment
100-
*/
10189
public function toEnvironment(array $vaults, bool $inheritCurrent = true): array
10290
{
10391
$env = $inheritCurrent ? getenv() : [];
@@ -124,11 +112,6 @@ public function toEnvironment(array $vaults, bool $inheritCurrent = true): array
124112
return $env;
125113
}
126114

127-
/**
128-
* Extract all placeholders from the template content.
129-
*
130-
* @return PlaceholderCollection Collection of Placeholder objects
131-
*/
132115
public function placeholders(): PlaceholderCollection
133116
{
134117
if ($this->isEmpty()) {

src/Server/Controllers/WorkspaceController.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010

1111
class WorkspaceController extends ApiController
1212
{
13-
/**
14-
* Get current workspace configuration
15-
*/
1613
public function get(): array
1714
{
1815
$localStorage = new LocalStorage();
1916
$workspace = $localStorage->getWorkspace();
2017

21-
// Get all available vaults and stages (unfiltered)
2218
$allVaults = $this->manager->getAllConfiguredVaults()->map(fn($v) => $v->slug())->values()->toArray();
2319
$allStages = $this->manager->getAllStages();
2420

@@ -32,9 +28,6 @@ public function get(): array
3228
];
3329
}
3430

35-
/**
36-
* Update workspace configuration
37-
*/
3831
public function update(): array
3932
{
4033
if (!isset($this->body['active_vaults']) || !is_array($this->body['active_vaults'])) {

src/Services/Export/DirectExportService.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,26 @@ public function __construct(
1313
protected OutputWriter $outputWriter
1414
) {}
1515

16-
/**
17-
* Handle direct export (no template).
18-
*/
1916
public function handle(array $options, OutputInterface $output): int
2017
{
2118
$stage = $options['stage'];
2219
$vaultNames = $this->getVaultNames($options);
2320

24-
// Load secrets from vaults
2521
$allSecrets = SecretCollection::loadFromVaults($vaultNames, $stage);
2622

27-
// Apply filters
2823
$allSecrets = $allSecrets->filterByPatterns(
2924
only: $options['only'] ?? null,
3025
except: $options['except'] ?? null
3126
);
3227

33-
// Format output
3428
$formattedOutput = $this->formatOutput($allSecrets, $options['format']);
35-
36-
// Output info
3729
if (count($vaultNames) === 1) {
3830
$output->writeln("<info>Exporting secrets from vault '{$vaultNames[0]}' for stage '{$stage}'...</info>");
3931
} else {
4032
$output->writeln('<info>Exporting secrets from '.count($vaultNames).' vaults ('.implode(', ', $vaultNames).") for stage '{$stage}'...</info>");
4133
}
4234
$output->writeln('<info>Found '.$allSecrets->count().' total secrets to export</info>');
4335

44-
// Write output
4536
if ($options['file']) {
4637
$this->outputWriter->write(
4738
$options['file'],

src/Services/Export/TemplateParseService.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,39 @@ public function __construct(
1515
protected OutputWriter $outputWriter
1616
) {}
1717

18-
/**
19-
* Handle template export with parsing (JSON format).
20-
*/
2118
public function handle(array $options, OutputInterface $output): int
2219
{
23-
// Load template
2420
$template = $this->loadTemplate($options['template'], $output);
2521

26-
// Determine which vaults to load from
2722
$vaultNames = $this->determineVaults($options, $template);
2823

29-
// Load secrets
3024
$stage = $options['stage'];
3125
$allSecrets = SecretCollection::loadFromVaults($vaultNames, $stage);
3226

33-
// Apply filters
3427
$allSecrets = $allSecrets->filterByPatterns(
3528
only: $options['only'] ?? null,
3629
except: $options['except'] ?? null
3730
);
3831

39-
// Get missing secret strategy
4032
$missingStrategy = MissingSecretStrategy::from($options['missing'] ?? 'fail');
4133

42-
// Parse template and extract keys
4334
$templateData = $this->parseTemplate(
4435
$template,
4536
$allSecrets,
4637
$missingStrategy,
4738
$options['all'] ?? false
4839
);
4940

50-
// Output info
5141
$format = strtoupper($options['format'] ?? 'json');
5242
$output->writeln("<info>Processing template [{$options['template']}] for stage '{$stage}' as {$format}...</info>");
5343
if ($options['all'] ?? false) {
5444
$output->writeln('<info>Including all additional secrets beyond template placeholders</info>');
5545
}
56-
57-
// Format output based on format option
5846
$formattedOutput = match ($options['format'] ?? 'json') {
5947
'csv' => $this->formatAsCsv($templateData, $allSecrets),
6048
default => json_encode($templateData, JSON_PRETTY_PRINT),
6149
};
6250

63-
// Write output
6451
if ($options['file']) {
6552
$this->outputWriter->write(
6653
$options['file'],

0 commit comments

Comments
 (0)