Skip to content

Commit

Permalink
Cleanup of unused logic and code standards
Browse files Browse the repository at this point in the history
  • Loading branch information
coenjacobs committed Sep 9, 2024
1 parent 8b453e2 commit 57c0b61
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 101 deletions.
2 changes: 0 additions & 2 deletions src/Composer/Autoload/NamespaceAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ abstract class NamespaceAutoloader implements Autoloader
* A package's composer.json config autoload key's value, where $key is `psr-1`|`psr-4`|`classmap`.
*
* @param $autoloadConfig
*
* @return void
*/
public function processConfig($autoloadConfig): void
{
Expand Down
5 changes: 3 additions & 2 deletions src/Config/Classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace CoenJacobs\Mozart\Config;

use CoenJacobs\Mozart\Composer\Autoload\Autoloader;
use Exception;

class Classmap implements Autoloader
{
Expand All @@ -27,10 +28,10 @@ public function processConfig($autoloadConfig): void
}

/**
* @throws \Exception
* @throws Exception
*/
public function getSearchNamespace(): string
{
throw new \Exception('Classmap autoloaders do not contain a namespace and this method can not be used.');
throw new Exception('Classmap autoloaders do not contain a namespace and this method can not be used.');
}
}
21 changes: 0 additions & 21 deletions src/Config/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use CoenJacobs\Mozart\Composer\Autoload\Autoloader;
use CoenJacobs\Mozart\Config\Autoload;
use CoenJacobs\Mozart\Config\ConfigAccessor;
use CoenJacobs\Mozart\Config\Extra;
use CoenJacobs\Mozart\Config\ReadsConfig;
use stdClass;
Expand All @@ -13,9 +12,6 @@ class Package
{
use ReadsConfig;

/** @var string */
public $path = '';

/** @var Package[] */
public $requirePackages = [];

Expand All @@ -27,23 +23,6 @@ class Package
public ?Autoload $autoload = null;
public ?Extra $extra = null;

/**
* Create a PHP object to represent a composer package.
*
* @param string $path The path to the vendor folder with the composer.json "name", i.e. the domain/package
* definition, which is the vendor subdir from where the package's composer.json should be read.
* @param stdClass $overrideAutoload Optional configuration to replace the package's own autoload definition with
* another which Mozart can use.
*/
public function __construct($path, $overrideAutoload = null)
{
$this->path = $path;

if (isset($overrideAutoload)) {
$this->setAutoload($overrideAutoload);
}
}

public function setAutoload(stdClass $data): void
{
$autoload = new Autoload();
Expand Down
14 changes: 1 addition & 13 deletions src/Console/Commands/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class Compose extends Command
/** @var Mozart */
private $config;

/**
* @return void
*/
protected function configure(): void
{
$this->setName('compose');
Expand Down Expand Up @@ -89,8 +86,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* @param Package[] $packages
*
* @return void
*/
protected function movePackages($packages): void
{
Expand All @@ -103,8 +98,6 @@ protected function movePackages($packages): void

/**
* @param Package[] $packages
*
* @return void
*/
protected function replacePackages($packages): void
{
Expand All @@ -115,8 +108,6 @@ protected function replacePackages($packages): void

/**
* Move all the packages over, one by one, starting on the deepest level of dependencies.
*
* @return void
*/
public function movePackage(Package $package): void
{
Expand All @@ -135,8 +126,6 @@ public function movePackage(Package $package): void

/**
* Replace contents of all the packages, one by one, starting on the deepest level of dependencies.
*
* @return void
*/
public function replacePackage(Package $package): void
{
Expand Down Expand Up @@ -198,13 +187,12 @@ private function findPackages(array $slugs): array
* Get an array containing all the dependencies and dependencies
* @param Package $package
* @param Package[] $dependencies
* @return array
* @return Package[]
*/
private function getAllDependenciesOfPackage(Package $package, $dependencies = []): array
{
if ($this->config->isExcludedPackage($package)) {
return $dependencies;
;
}

if (empty($package->getDependencies())) {
Expand Down
18 changes: 2 additions & 16 deletions src/Mover.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public function __construct(string $workingDir, Mozart $config)
* Create the required `dep_directory` and `classmap_directory` and delete targetDirs of packages about to be moved.
*
* @param Package[] $packages The packages that, in the next step, will be moved.
*
* @return void
*/
public function deleteTargetDirs($packages): void
{
Expand Down Expand Up @@ -103,10 +101,7 @@ public function deleteEmptyDirs(): void
}
}

/**
* @return void
*/
public function movePackage(Package $package)
public function movePackage(Package $package): void
{
if (in_array($package->getName(), $this->movedPackages)) {
return;
Expand Down Expand Up @@ -173,14 +168,7 @@ public function movePackage(Package $package)
}
}

/**
* @param Package $package
* @param Autoloader $autoloader
* @param SplFileInfo $file
* @param string $path
* @return string
*/
public function moveFile(Package $package, $autoloader, $file, $path = '')
public function moveFile(Package $package, Autoloader $autoloader, SplFileInfo $file, string $path = ''): string
{
if ($autoloader instanceof NamespaceAutoloader) {
$namespacePath = $autoloader->getNamespacePath();
Expand Down Expand Up @@ -214,8 +202,6 @@ public function moveFile(Package $package, $autoloader, $file, $path = '')
* Deletes all the packages that are moved from the /vendor/ directory to
* prevent packages that are prefixed/namespaced from being used or
* influencing the output of the code. They just need to be gone.
*
* @return void
*/
protected function deletePackageVendorDirectories(): void
{
Expand Down
3 changes: 1 addition & 2 deletions src/Replace/BaseReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ abstract class BaseReplacer implements Replacer

/**
* @param Autoloader $autoloader
* @return void
*/
public function setAutoloader(Autoloader $autoloader)
public function setAutoloader(Autoloader $autoloader): void
{
$this->autoloader = $autoloader;
}
Expand Down
12 changes: 5 additions & 7 deletions src/Replace/ClassmapReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class ClassmapReplacer extends BaseReplacer

/**
* @param false|string $contents
*
* @return string
*/
public function replace($contents): string
{
Expand All @@ -29,16 +27,16 @@ public function replace($contents): string
return preg_replace_callback(
"
/ # Start the pattern
namespace\s+[a-zA-Z0-9_\x7f-\xff\\\\]+[;{\s\n]{1}.*?(?=namespace|$)
# Look for a preceeding namespace declaration, up until
namespace\s+[a-zA-Z0-9_\x7f-\xff\\\\]+[;{\s\n]{1}.*?(?=namespace|$)
# Look for a preceeding namespace declaration, up until
# a potential second namespace declaration
| # if found, match that much before repeating the search
| # if found, match that much before repeating the search
# on the remainder of the string
(?:abstract\sclass|class|interface)\s+ # Look behind for class, abstract class, interface
([a-zA-Z0-9_\x7f-\xff]+) # Match the word until the first
([a-zA-Z0-9_\x7f-\xff]+) # Match the word until the first
# non-classname-valid character
\s? # Allow a space after
(?:{|extends|implements|\n) # Class declaration can be followed by {, extends,
(?:{|extends|implements|\n) # Class declaration can be followed by {, extends,
# implements, or a new line
/sx", // # dot matches newline, ignore whitespace in regex.
function ($matches) use ($contents) {
Expand Down
4 changes: 1 addition & 3 deletions src/Replace/NamespaceReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ class NamespaceReplacer extends BaseReplacer
/**
* @param string $contents The text to make replacements in.
* @param null $file Only used in ClassmapReplacer (for recording which files were changed).
*
* @return string The updated text.
*/
public function replace($contents, $file = null)
public function replace($contents, $file = null): string
{
$searchNamespace = preg_quote($this->autoloader->getSearchNamespace(), '/');
$dependencyNamespace = preg_quote($this->dep_namespace, '/');
Expand Down
31 changes: 1 addition & 30 deletions src/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ public function replacePackage(Package $package): void
}
}

/**
* @param $targetFile
* @param $autoloader
*
* @return void
*/
public function replaceInFile(string $targetFile, Autoloader $autoloader): void
{
$targetFile = str_replace($this->workingDir, '', $targetFile);
Expand Down Expand Up @@ -89,13 +83,7 @@ public function replaceInFile(string $targetFile, Autoloader $autoloader): void
$this->filesystem->write($targetFile, $contents);
}

/**
* @param Package $package
* @param $autoloader
*
* @return void
*/
public function replacePackageByAutoloader(Package $package, Composer\Autoload\Autoloader $autoloader): void
public function replacePackageByAutoloader(Package $package, Autoloader $autoloader): void
{
if ($autoloader instanceof NamespaceAutoloader) {
$source_path = $this->workingDir . $this->targetDir
Expand All @@ -117,12 +105,6 @@ public function replacePackageByAutoloader(Package $package, Composer\Autoload\A
}
}

/**
* @param $autoloader
* @param $directory
*
* @return void
*/
public function replaceParentClassesInDirectory(string $directory): void
{
if (count($this->replacedClasses)===0) {
Expand Down Expand Up @@ -171,12 +153,6 @@ function ($matches) use ($replacement) {
}
}

/**
* @param $autoloader
* @param $directory
*
* @return void
*/
public function replaceInDirectory(NamespaceAutoloader $autoloader, string $directory): void
{
$finder = new Finder();
Expand All @@ -195,11 +171,6 @@ public function replaceInDirectory(NamespaceAutoloader $autoloader, string $dire
* Replace everything in parent package, based on the dependency package.
* This is done to ensure that package A (which requires package B), is also
* updated with the replacements being made in package B.
*
* @param Package $package
* @param Package $parent
*
* @return void
*/
public function replaceParentPackage(Package $package, Package $parent): void
{
Expand Down
5 changes: 0 additions & 5 deletions tests/replacers/NamespaceReplacerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ protected function setUp(): void

/**
* Creates a NamespaceReplacer, given a namespace and a prefix.
*
* @param string $namespace
* @param string $prefix
*
* @return Psr0
*/
protected static function createReplacer(string $namespace, string $prefix = self::PREFIX) : NamespaceReplacer
{
Expand Down

0 comments on commit 57c0b61

Please sign in to comment.