Skip to content

Commit 19aeb47

Browse files
committed
fix: Remove unused methods and redundant code across tools and config files
1 parent 0183438 commit 19aeb47

File tree

6 files changed

+8
-129
lines changed

6 files changed

+8
-129
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"spiral/boot": "^3.15",
1818
"spiral/config": "^3.15",
1919
"spiral/console": "^3.15",
20-
"spiral/files": "^3.15"
20+
"spiral/files": "^3.15",
21+
"symfony/yaml": "^7.2 || ^8.0"
2122
},
2223
"require-dev": {
2324
"spiral/code-style": "^2.2",

src/MCP/Tools/ListTemplatesToolAction.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,12 @@ public function __invoke(ListTemplatesRequest $request): CallToolResult
6161
]);
6262

6363
return ToolResult::success($response);
64-
6564
} catch (ResearchException $e) {
6665
$this->logger->error('Error listing research templates', [
6766
'error' => $e->getMessage(),
6867
]);
6968

7069
return ToolResult::error($e->getMessage());
71-
7270
} catch (\Throwable $e) {
7371
$this->logger->error('Unexpected error listing templates', [
7472
'error' => $e->getMessage(),
@@ -98,7 +96,7 @@ private function applyFilters(array $templates, ListTemplatesRequest $request):
9896
// Filter by name (partial match, case insensitive)
9997
if ($request->nameContains !== null) {
10098
$searchTerm = \strtolower(\trim($request->nameContains));
101-
$templateName = \strtolower((string) $template->name);
99+
$templateName = \strtolower((string)$template->name);
102100

103101
if (!\str_contains($templateName, $searchTerm)) {
104102
return false;

src/MCP/Tools/UpdateEntryToolAction.php

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ public function __invoke(EntryUpdateRequest $request): CallToolResult
8484
]);
8585

8686
return ToolResult::error($e->getMessage());
87-
8887
} catch (EntryNotFoundException $e) {
8988
$this->logger->error('Entry not found', [
9089
'research_id' => $request->researchId,
@@ -93,7 +92,6 @@ public function __invoke(EntryUpdateRequest $request): CallToolResult
9392
]);
9493

9594
return ToolResult::error($e->getMessage());
96-
9795
} catch (ResearchException $e) {
9896
$this->logger->error('Error during research entry update', [
9997
'research_id' => $request->researchId,
@@ -102,7 +100,6 @@ public function __invoke(EntryUpdateRequest $request): CallToolResult
102100
]);
103101

104102
return ToolResult::error($e->getMessage());
105-
106103
} catch (\Throwable $e) {
107104
$this->logger->error('Unexpected error updating entry', [
108105
'research_id' => $request->researchId,
@@ -113,38 +110,4 @@ public function __invoke(EntryUpdateRequest $request): CallToolResult
113110
return ToolResult::error('Failed to update entry: ' . $e->getMessage());
114111
}
115112
}
116-
117-
/**
118-
* Get list of changes applied based on the request
119-
*/
120-
private function getAppliedChanges(EntryUpdateRequest $request): array
121-
{
122-
$changes = [];
123-
124-
if ($request->title !== null) {
125-
$changes[] = 'title';
126-
}
127-
128-
if ($request->description !== null) {
129-
$changes[] = 'description';
130-
}
131-
132-
if ($request->content !== null) {
133-
$changes[] = 'content';
134-
}
135-
136-
if ($request->status !== null) {
137-
$changes[] = 'status';
138-
}
139-
140-
if ($request->tags !== null) {
141-
$changes[] = 'tags';
142-
}
143-
144-
if ($request->textReplace !== null) {
145-
$changes[] = 'text_replacement';
146-
}
147-
148-
return $changes;
149-
}
150113
}

src/MCP/Tools/UpdateResearchToolAction.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -88,38 +88,4 @@ public function __invoke(ResearchUpdateRequest $request): CallToolResult
8888
return ToolResult::error('Failed to update research: ' . $e->getMessage());
8989
}
9090
}
91-
92-
/**
93-
* Get list of changes applied based on the request
94-
*/
95-
private function getAppliedChanges(ResearchUpdateRequest $request): array
96-
{
97-
$changes = [];
98-
99-
if ($request->title !== null) {
100-
$changes[] = 'title';
101-
}
102-
103-
if ($request->description !== null) {
104-
$changes[] = 'description';
105-
}
106-
107-
if ($request->status !== null) {
108-
$changes[] = 'status';
109-
}
110-
111-
if ($request->tags !== null) {
112-
$changes[] = 'tags';
113-
}
114-
115-
if ($request->entryDirs !== null) {
116-
$changes[] = 'entry_directories';
117-
}
118-
119-
if ($request->memory !== null) {
120-
$changes[] = 'memory';
121-
}
122-
123-
return $changes;
124-
}
12591
}

src/Storage/FileStorage/FileStorageConfig.php

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,6 @@ public function __construct(
2020
public string $fileEncoding = 'utf-8',
2121
) {}
2222

23-
/**
24-
* Create from array configuration
25-
*/
26-
public static function fromArray(array $config): self
27-
{
28-
return new self(
29-
basePath: $config['base_path'] ?? '.researches',
30-
templatesPath: $config['templates_path'] ?? '.templates',
31-
defaultEntryStatus: $config['default_entry_status'] ?? 'draft',
32-
createDirectoriesOnDemand: $config['create_directories_on_demand'] ?? true,
33-
validateTemplatesOnBoot: $config['validate_templates_on_boot'] ?? true,
34-
maxFileSize: $config['max_file_size'] ?? 10485760,
35-
allowedExtensions: $config['allowed_extensions'] ?? ['md', 'yaml'],
36-
fileEncoding: $config['file_encoding'] ?? 'utf-8',
37-
);
38-
}
39-
40-
/**
41-
* Validate configuration values
42-
*/
43-
public function validate(): array
44-
{
45-
$errors = [];
46-
47-
if (empty($this->basePath)) {
48-
$errors[] = 'Base path cannot be empty';
49-
}
50-
51-
if (empty($this->templatesPath)) {
52-
$errors[] = 'Templates path cannot be empty';
53-
}
54-
55-
if (empty($this->defaultEntryStatus)) {
56-
$errors[] = 'Default entry status cannot be empty';
57-
}
58-
59-
if ($this->maxFileSize <= 0) {
60-
$errors[] = 'Max file size must be greater than 0';
61-
}
62-
63-
if (empty($this->allowedExtensions)) {
64-
$errors[] = 'At least one allowed extension must be specified';
65-
}
66-
67-
return $errors;
68-
}
69-
7023
#[\Override]
7124
public function jsonSerialize(): array
7225
{

src/Storage/FileStorageBootloader.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Butschster\ContextGenerator\Research\Storage;
66

7-
use Butschster\ContextGenerator\DirectoriesInterface;
87
use Butschster\ContextGenerator\Research\Config\ResearchConfigInterface;
98
use Butschster\ContextGenerator\Research\Repository\EntryRepositoryInterface;
109
use Butschster\ContextGenerator\Research\Repository\ResearchRepositoryInterface;
@@ -38,16 +37,15 @@ public function defineSingletons(): array
3837
FilesInterface $files,
3938
LoggerInterface $logger,
4039
ExceptionReporterInterface $reporter,
41-
DirectoriesInterface $dirs,
4240
TemplateRepositoryInterface $templateRepository,
4341
ResearchRepositoryInterface $researchRepository,
4442
EntryRepositoryInterface $entryRepository,
4543
): StorageDriverInterface => new FileStorageDriver(
46-
driverConfig: FileStorageConfig::fromArray([
47-
'base_path' => $config->getResearchesPath(),
48-
'templates_path' => $config->getTemplatesPath(),
49-
'default_entry_status' => $config->getDefaultEntryStatus(),
50-
]),
44+
driverConfig: new FileStorageConfig(
45+
basePath: $config->getResearchesPath(),
46+
templatesPath: $config->getTemplatesPath(),
47+
defaultEntryStatus: $config->getDefaultEntryStatus(),
48+
),
5149
templateRepository: $templateRepository,
5250
researchRepository: $researchRepository,
5351
entryRepository: $entryRepository,

0 commit comments

Comments
 (0)