3030
3131use function Safe \getcwd ;
3232
33+ /**
34+ * Provides a base configuration and common utilities for Composer commands.
35+ * Extending classes MUST rely on this base abstraction to interact with the console
36+ * application gracefully, and SHALL adhere to the expected return types for commands.
37+ */
3338abstract class AbstractCommand extends BaseCommand
3439{
40+ /**
41+ * @var Filesystem The filesystem instance used for file operations. This property MUST be utilized for interacting with the file system securely.
42+ */
3543 protected readonly Filesystem $ filesystem ;
3644
3745 /**
38- * @param Filesystem|null $filesystem
46+ * Constructs a new AbstractCommand instance.
47+ *
48+ * The method MAY accept a Filesystem instance; if omitted, it SHALL instantiate a new one.
49+ *
50+ * @param Filesystem|null $filesystem the filesystem utility to use
3951 */
4052 public function __construct (?Filesystem $ filesystem = null )
4153 {
@@ -45,10 +57,16 @@ public function __construct(?Filesystem $filesystem = null)
4557 }
4658
4759 /**
48- * @param Process $command
49- * @param OutputInterface $output
60+ * Executes a given system process gracefully and outputs its buffer.
61+ *
62+ * The method MUST execute the provided command ensuring the output is channeled
63+ * to the OutputInterface. It SHOULD leverage TTY if supported. If the process
64+ * fails, it MUST return `self::FAILURE`; otherwise, it SHALL return `self::SUCCESS`.
65+ *
66+ * @param Process $command the configured process instance to run
67+ * @param OutputInterface $output the output interface to log warnings or results
5068 *
51- * @return int
69+ * @return int the status code of the command execution
5270 */
5371 protected function runProcess (Process $ command , OutputInterface $ output ): int
5472 {
@@ -86,7 +104,12 @@ protected function runProcess(Process $command, OutputInterface $output): int
86104 }
87105
88106 /**
89- * @return string
107+ * Retrieves the current working directory of the application.
108+ *
109+ * The method MUST return the initial working directory defined by the application.
110+ * If not available, it SHALL fall back to the safe current working directory.
111+ *
112+ * @return string the absolute path to the current working directory
90113 */
91114 protected function getCurrentWorkingDirectory (): string
92115 {
@@ -95,9 +118,14 @@ protected function getCurrentWorkingDirectory(): string
95118 }
96119
97120 /**
98- * @param string $relativePath
121+ * Computes the absolute path for a given relative or absolute path.
99122 *
100- * @return string
123+ * This method MUST return the exact path if it is already absolute.
124+ * If relative, it SHALL make it absolute relying on the current working directory.
125+ *
126+ * @param string $relativePath the path to evaluate or resolve
127+ *
128+ * @return string the resolved absolute path
101129 */
102130 protected function getAbsolutePath (string $ relativePath ): string
103131 {
@@ -109,10 +137,15 @@ protected function getAbsolutePath(string $relativePath): string
109137 }
110138
111139 /**
112- * @param string $filename
113- * @param bool $force
140+ * Determines the correct absolute path to a configuration file.
141+ *
142+ * The method MUST attempt to resolve the configuration file locally in the working directory.
143+ * If absent and not forced, it SHALL provide the default equivalent from the package itself.
114144 *
115- * @return string
145+ * @param string $filename the name of the configuration file
146+ * @param bool $force determines whether to bypass fallback and forcefully return the local file path
147+ *
148+ * @return string the resolved absolute path to the configuration file
116149 */
117150 protected function getConfigFile (string $ filename , bool $ force = false ): string
118151 {
@@ -128,11 +161,16 @@ protected function getConfigFile(string $filename, bool $force = false): string
128161 }
129162
130163 /**
131- * @param InputInterface $input
132- * @param string $commandName
133- * @param OutputInterface $output
164+ * Configures and executes a registered console command by name.
165+ *
166+ * The method MUST look up the command from the application and run it. It SHALL ignore generic
167+ * validation errors and route the custom input and output correctly.
134168 *
135- * @return int
169+ * @param string $commandName the name of the required command
170+ * @param array|InputInterface $input the input arguments or array definition
171+ * @param OutputInterface $output the interface for buffering output
172+ *
173+ * @return int the status code resulting from the dispatched command
136174 */
137175 protected function runCommand (string $ commandName , array |InputInterface $ input , OutputInterface $ output ): int
138176 {
@@ -149,7 +187,12 @@ protected function runCommand(string $commandName, array|InputInterface $input,
149187 }
150188
151189 /**
152- * @return array
190+ * Retrieves configured PSR-4 namespaces from the composer configuration.
191+ *
192+ * This method SHALL parse the underlying `composer.json` using the Composer instance,
193+ * and MUST provide an empty array if no specific paths exist.
194+ *
195+ * @return array the PSR-4 namespaces mappings
153196 */
154197 protected function getPsr4Namespaces (): array
155198 {
@@ -161,7 +204,12 @@ protected function getPsr4Namespaces(): array
161204 }
162205
163206 /**
164- * @return string
207+ * Computes the human-readable title or description of the current application.
208+ *
209+ * The method SHOULD utilize the package description as the title, but MUST provide
210+ * the raw package name as a fallback mechanism.
211+ *
212+ * @return string the computed title or description string
165213 */
166214 protected function getTitle (): string
167215 {
0 commit comments