Skip to content

Commit

Permalink
Added enforced docblocks for complex methods
Browse files Browse the repository at this point in the history
  • Loading branch information
coenjacobs committed Sep 19, 2024
1 parent 4a5a07d commit 58e0644
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Composer/Autoload/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ public function getOutputDir(string $basePath, string $autoloadPath): string;
* @return array<string,SplFileInfo>
*/
public function getFiles(FilesHandler $files): array;
/**
* Returns the intended target path of a file, where it should be moved by
* the Mover class. This requires access to the Mozart configuration, for it
* to determine the target directory. This is done by checking the paths
* that are being registered for this autoloader, to see if they can be
* matched with the full path name of the provided file.
*/
public function getTargetFilePath(SplFileInfo $file): string;
}
3 changes: 3 additions & 0 deletions src/Composer/Autoload/NamespaceAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public function getFiles(FilesHandler $fileHandler): array
return $filesToMove;
}

/**
* @inheritdoc
*/
public function getTargetFilePath(SplFileInfo $file): string
{
$suffix = '';
Expand Down
6 changes: 6 additions & 0 deletions src/Config/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ class Autoload
/** @var array<Autoloader> */
public array $autoloaders = [];

/**
* Loads the autoloaders provided in the loaded composer.json file, which is
* then passed to this method as a stdClass. It registers each autoloader,
* which are then used to access the paths to read and replace contents of
* files that these autoloaders allow access to.
*/
public function setupAutoloaders(stdClass $autoloadData, Package $package): void
{
$autoloaders = [];
Expand Down
3 changes: 3 additions & 0 deletions src/Config/Classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public function getFiles(FilesHandler $fileHandler): array
return $filesToMove;
}

/**
* @inheritdoc
*/
public function getTargetFilePath(SplFileInfo $file): string
{
$suffix = '';
Expand Down
7 changes: 7 additions & 0 deletions src/Config/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ public function getDependencies(): array
return $this->dependencies;
}

/**
* Loads and registers all dependencies of this package, by checking the
* require-object of the composer.json file of this package. Each package
* listed as a dependency is then loaded and registered as being a
* dependency of this package. Also flags this package for having its
* dependencies already loaded, so it doesn't duplicate dependencies.
*/
public function loadDependencies(PackageFinder $finder): void
{
if ($this->dependenciesLoaded) {
Expand Down
5 changes: 5 additions & 0 deletions src/Mover.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ public function movePackages($packages): void
$this->deleteEmptyDirs();
}

/**
* Moves each file for each autoloader, for the provided package. Each
* package will only be moved once, to prevent duplicates, so the package
* name is registered at the end of the method.
*/
private function movePackage(Package $package): void
{
if (!$this->shouldPackageBeMoved($package)) {
Expand Down
9 changes: 9 additions & 0 deletions src/PackageFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public function setConfig(Mozart $config): void
$this->config = $config;
}

/**
* Returns a Package object for the package based on the provided slug (in
* vendor/package format). The data of the package is loaded if a valid
* installed package could be found based on the slug, which is then being
* used to read the composer.json file of the package.
*/
public function getPackageBySlug(string $slug): ?Package
{
/**
Expand Down Expand Up @@ -54,6 +60,9 @@ public function getPackageBySlug(string $slug): ?Package
}

/**
* Returns Package objects which are loaded based on the provided array of
* slugs (in vendor/package format).
*
* @param string[] $slugs
* @return Package[]
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function getReplacerByAutoloader(Autoloader $autoloader): ReplacerInterfa
return $replacer;
}

/**
* Fetches the files or directories to perform a replace action on, based
* on the provided autoloader, for the provided package.
*/
public function replacePackageByAutoloader(Package $package, Autoloader $autoloader): void
{
if ($this->config->isExcludedPackage($package)) {
Expand All @@ -105,6 +109,11 @@ public function replacePackageByAutoloader(Package $package, Autoloader $autoloa
}
}

/**
* Replaces all occurances of previously replaced classes, in the provided
* directory. This to ensure that each package has its parents package
* classes also replaced in its own files.
*/
public function replaceParentClassesInDirectory(string $directory): void
{
if (count($this->replacedClasses)===0) {
Expand Down

0 comments on commit 58e0644

Please sign in to comment.