Skip to content

Commit 3781355

Browse files
committed
refactor: enhance documentation for ComposerJson, DevToolsCommandLoader, SystemClock, and DevToolsServiceProvider classes
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 36763dd commit 3781355

5 files changed

Lines changed: 105 additions & 8 deletions

File tree

src/Composer/Json/ComposerJson.php

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,41 @@
2121
use Composer\Factory;
2222
use Composer\Json\JsonFile;
2323

24+
/**
25+
* Represents a specialized reader for a Composer JSON file.
26+
*
27+
* This class SHALL provide convenient accessors for commonly used
28+
* `composer.json` metadata after reading and caching the file contents.
29+
* Consumers SHOULD use this class when they need normalized access to
30+
* package-level metadata. The internal data cache MUST reflect the
31+
* contents returned by the underlying JSON file reader at construction
32+
* time.
33+
*/
2434
final class ComposerJson extends JsonFile
2535
{
36+
/**
37+
* Stores the decoded Composer JSON document contents.
38+
*
39+
* This property MUST contain the data read from the target Composer
40+
* file during construction. Consumers SHOULD treat the structure as
41+
* internal implementation detail and SHALL rely on accessor methods
42+
* instead of direct access.
43+
*
44+
* @var array<string, mixed>
45+
*/
2646
private array $data;
2747

2848
/**
29-
* @param string|null $path
49+
* Initializes the Composer JSON reader.
50+
*
51+
* When no path is provided, the default Composer file location
52+
* returned by Composer's factory SHALL be used. The constructor MUST
53+
* immediately read and cache the JSON document contents so that
54+
* subsequent accessor methods can operate on the in-memory data.
55+
*
56+
* @param string|null $path The absolute or relative path to a
57+
* Composer JSON file. When omitted, the
58+
* default Composer file path SHALL be used.
3059
*/
3160
public function __construct(?string $path = null)
3261
{
@@ -35,23 +64,45 @@ public function __construct(?string $path = null)
3564
}
3665

3766
/**
38-
* @return string
67+
* Returns the package name declared in the Composer file.
68+
*
69+
* This method SHALL return the value of the `name` key when present.
70+
* If the package name is not defined, the method MUST return an
71+
* empty string.
72+
*
73+
* @return string the package name, or an empty string when undefined
3974
*/
4075
public function getPackageName(): string
4176
{
4277
return $this->data['name'] ?? '';
4378
}
4479

4580
/**
46-
* @return string
81+
* Returns the package description declared in the Composer file.
82+
*
83+
* This method SHALL return the value of the `description` key when
84+
* present. If the description is not defined, the method MUST return
85+
* an empty string.
86+
*
87+
* @return string the package description, or an empty string when
88+
* undefined
4789
*/
4890
public function getPackageDescription(): string
4991
{
5092
return $this->data['description'] ?? '';
5193
}
5294

5395
/**
54-
* @return string|null
96+
* Returns the package license when it can be resolved to a single value.
97+
*
98+
* This method SHALL return the `license` value directly when it is a
99+
* string. When the license is an array containing exactly one item,
100+
* that single item SHALL be returned. When the license field is not
101+
* present, is empty, or cannot be resolved to exactly one string
102+
* value, the method MUST return null.
103+
*
104+
* @return string|null the resolved license identifier, or null when
105+
* no single license value can be determined
55106
*/
56107
public function getPackageLicense(): ?string
57108
{
@@ -69,25 +120,47 @@ public function getPackageLicense(): ?string
69120
}
70121

71122
/**
72-
* @return array
123+
* Returns the package authors declared in the Composer file.
124+
*
125+
* This method SHALL return the value of the `authors` key when
126+
* present. If the key is absent, the method MUST return an empty
127+
* array.
128+
*
129+
* @return array the authors list as declared in the Composer file,
130+
* or an empty array when undefined
73131
*/
74132
public function getAuthors(): array
75133
{
76134
return $this->data['authors'] ?? [];
77135
}
78136

79137
/**
80-
* @return array
138+
* Returns the extra configuration section declared in the Composer file.
139+
*
140+
* This method SHALL return the value of the `extra` key when present.
141+
* If the key is absent, the method MUST return an empty array.
142+
*
143+
* @return array the extra configuration data, or an empty array when
144+
* undefined
81145
*/
82146
public function getExtra(): array
83147
{
84148
return $this->data['extra'] ?? [];
85149
}
86150

87151
/**
88-
* @param string $type
152+
* Returns the autoload configuration for the requested autoload type.
153+
*
154+
* This method SHALL inspect the `autoload` section and return the
155+
* nested configuration for the requested type, such as `psr-4`.
156+
* When the `autoload` section or the requested type is not defined,
157+
* the method MUST return an empty array.
158+
*
159+
* @param string $type The autoload mapping type to retrieve. This
160+
* defaults to `psr-4`.
89161
*
90-
* @return array
162+
* @return array the autoload configuration for the requested type,
163+
* or an empty array when unavailable
91164
*/
92165
public function getAutoload(string $type = 'psr-4'): array
93166
{

src/Console/CommandLoader/DevToolsCommandLoader.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
final class DevToolsCommandLoader extends ContainerCommandLoader
2929
{
3030
/**
31+
* Constructs the DevToolsCommandLoader.
32+
*
33+
* This constructor initializes the command loader by scanning the Command directory for classes that are
34+
* instantiable and have the AsCommand attribute.
35+
* It builds a command map associating command names with their respective classes.
36+
*
3137
* @param Finder $finder
3238
* @param ContainerInterface $container
3339
*/
@@ -37,6 +43,8 @@ public function __construct(Finder $finder, ContainerInterface $container)
3743
}
3844

3945
/**
46+
* Builds a command map by scanning the Command directory for classes that are instantiable and have the AsCommand attribute.
47+
*
4048
* @param Finder $finder
4149
*
4250
* @return array

src/Console/DevTools.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
*/
3434
final class DevTools extends ComposerApplication
3535
{
36+
/**
37+
* @var ContainerInterface holds the static container instance for global access within the DevTools context
38+
*/
3639
private static ?ContainerInterface $container = null;
3740

3841
/**

src/Psr/Clock/SystemClock.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,16 @@
2121
use DateTimeImmutable;
2222
use Psr\Clock\ClockInterface;
2323

24+
/**
25+
* A clock implementation that returns the current system time.
26+
*
27+
* This class implements the ClockInterface and provides a method to get the current time as a DateTimeImmutable object.
28+
*/
2429
final class SystemClock implements ClockInterface
2530
{
2631
/**
32+
* Returns the current time as a DateTimeImmutable Object.
33+
*
2734
* @return DateTimeImmutable
2835
*/
2936
public function now(): DateTimeImmutable

src/ServiceProvider/DevToolsServiceProvider.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@
6262
use function DI\create;
6363
use function DI\get;
6464

65+
/**
66+
* DevToolsServiceProvider registers the services provided by this package.
67+
*
68+
* This class implements the ServiceProviderInterface from the PHP-Interop container package,
69+
* allowing it to be used with any compatible dependency injection container.
70+
*/
6571
final class DevToolsServiceProvider implements ServiceProviderInterface
6672
{
6773
/**

0 commit comments

Comments
 (0)