From 97fe881af45ebe1b7c750f51b1fae1a379972bae Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 15 Oct 2021 16:26:22 +0200 Subject: [PATCH] Add some docblocks --- src/Composer/Autoload/AutoloadGenerator.php | 77 +++++++++++++++++-- tests/Composer/Test/AllFunctionalTest.php | 22 +++++- .../Composer/Test/Plugin/Mock/Capability.php | 6 ++ 3 files changed, 94 insertions(+), 11 deletions(-) diff --git a/src/Composer/Autoload/AutoloadGenerator.php b/src/Composer/Autoload/AutoloadGenerator.php index 47c888ab7..138b111d6 100644 --- a/src/Composer/Autoload/AutoloadGenerator.php +++ b/src/Composer/Autoload/AutoloadGenerator.php @@ -139,6 +139,9 @@ class AutoloadGenerator } } + /** + * @return int + */ public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, $targetDir, $scanPsrPackages = false, $suffix = '') { if ($this->classMapAuthoritative) { @@ -406,7 +409,11 @@ EOF; return count($classMap); } - private function addClassMapCode($filesystem, $basePath, $vendorPath, $dir, $excluded, $namespaceFilter, $autoloadType, array $classMap, array &$ambiguousClasses, array &$scannedFiles) + /** + * @param ?array $excluded + * @return array + */ + private function addClassMapCode(Filesystem $filesystem, $basePath, $vendorPath, $dir, $excluded, $namespaceFilter, $autoloadType, array $classMap, array &$ambiguousClasses, array &$scannedFiles) { foreach ($this->generateClassMap($dir, $excluded, $namespaceFilter, $autoloadType, true, $scannedFiles) as $class => $path) { $pathCode = $this->getPathCode($filesystem, $basePath, $vendorPath, $path).",\n"; @@ -421,7 +428,8 @@ EOF; } /** - * @param ?array $excluded + * @param ?array $excluded + * @return array */ private function generateClassMap($dir, $excluded, $namespaceFilter, $autoloadType, $showAmbiguousWarning, array &$scannedFiles) { @@ -450,6 +458,7 @@ EOF; /** * @param RootPackageInterface $rootPackage + * @return array */ public function buildPackageMap(InstallationManager $installationManager, PackageInterface $rootPackage, array $packages) { @@ -472,8 +481,6 @@ EOF; } /** - * @param PackageInterface $package - * * @throws \InvalidArgumentException Throws an exception, if the package has illegal settings. */ protected function validatePackage(PackageInterface $package) @@ -500,6 +507,8 @@ EOF; * @param RootPackageInterface $rootPackage root package instance * @param bool|string[] $filteredDevPackages If an array, the list of packages that must be removed. If bool, whether to filter out require-dev packages * @return array array('psr-0' => array('Ns\\Foo' => array('installDir'))) + * + * @phpstan-param array $packageMap */ public function parseAutoloads(array $packageMap, PackageInterface $rootPackage, $filteredDevPackages = false) { @@ -574,6 +583,15 @@ EOF; return $loader; } + /** + * @param string $basePath + * @param string $vendorPath + * @param string $vendorPathCode + * @param string $appBaseDirCode + * @return ?string + * + * @phpstan-param array $packageMap + */ protected function getIncludePathsFile(array $packageMap, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode) { $includePaths = array(); @@ -592,7 +610,7 @@ EOF; } if (!$includePaths) { - return; + return null; } $includePathsCode = ''; @@ -614,6 +632,14 @@ $includePathsCode); EOF; } + /** + * @param array $files + * @param string $basePath + * @param string $vendorPath + * @param string $vendorPathCode + * @param string $appBaseDirCode + * @return ?string + */ protected function getIncludeFilesFile(array $files, Filesystem $filesystem, $basePath, $vendorPath, $vendorPathCode, $appBaseDirCode) { $filesCode = ''; @@ -623,7 +649,7 @@ EOF; } if (!$filesCode) { - return false; + return null; } return <<isAbsolutePath($path)) { @@ -670,6 +702,13 @@ EOF; return $baseDir . var_export($path, true); } + /** + * @param bool $checkPlatform + * @param string[] $devPackageNames + * @return ?string + * + * @phpstan-param array $packageMap + */ protected function getPlatformCheck(array $packageMap, array $ignorePlatformReqs, $checkPlatform, array $devPackageNames) { $lowestPhpVersion = Bound::zero(); @@ -822,6 +861,11 @@ if (\$issues) { PLATFORM_CHECK; } + /** + * @param string $vendorPathToTargetDirCode + * @param string $suffix + * @return string + */ protected function getAutoloadFile($vendorPathToTargetDirCode, $suffix) { $lastChar = $vendorPathToTargetDirCode[strlen($vendorPathToTargetDirCode) - 1]; @@ -843,6 +887,9 @@ return ComposerAutoloaderInit$suffix::getLoader(); AUTOLOAD; } + /** + * @return string + */ protected function getAutoloadRealFile($useClassMap, $useIncludePath, $targetDirLoader, $useIncludeFiles, $vendorPathCode, $appBaseDirCode, $suffix, $useGlobalIncludePath, $prependAutoloader, $staticPhpVersion, $checkPlatform) { $file = <<
|array>|array + */ protected function parseAutoloadsType(array $packageMap, $type, RootPackageInterface $rootPackage) { $autoloads = array(); @@ -1195,6 +1248,10 @@ INITIALIZER; return $autoloads; } + /** + * @param string $path + * @return string + */ protected function getFileIdentifier(PackageInterface $package, $path) { return md5($package->getName() . ':' . $path); @@ -1205,7 +1262,9 @@ INITIALIZER; * * @param array $packageMap * @param RootPackageInterface $rootPackage - * @return array + * @return array + * + * @phpstan-param array $packageMap */ protected function filterPackageMap(array $packageMap, RootPackageInterface $rootPackage) { @@ -1259,7 +1318,9 @@ INITIALIZER; * Packages of equal weight retain the original order * * @param array $packageMap - * @return array + * @return array + * + * @phpstan-param array $packageMap */ protected function sortPackageMap(array $packageMap) { diff --git a/tests/Composer/Test/AllFunctionalTest.php b/tests/Composer/Test/AllFunctionalTest.php index 22cea755d..954db12e0 100644 --- a/tests/Composer/Test/AllFunctionalTest.php +++ b/tests/Composer/Test/AllFunctionalTest.php @@ -21,10 +21,13 @@ use Symfony\Component\Process\Process; */ class AllFunctionalTest extends TestCase { + /** @var string|false */ protected $oldcwd; - protected $oldenv; - protected $oldenvCache; + /** @var ?string */ protected $testDir; + /** + * @var string + */ private static $pharPath; public function setUp() @@ -36,7 +39,9 @@ class AllFunctionalTest extends TestCase public function tearDown() { - chdir($this->oldcwd); + if ($this->oldcwd) { + chdir($this->oldcwd); + } if ($this->testDir) { $fs = new Filesystem; @@ -182,6 +187,9 @@ class AllFunctionalTest extends TestCase } } + /** + * @return array> + */ public function getTestFiles() { $tests = array(); @@ -192,6 +200,10 @@ class AllFunctionalTest extends TestCase return $tests; } + /** + * @param string $file + * @return array + */ private function parseTestFile($file) { $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file), -1, PREG_SPLIT_DELIM_CAPTURE); @@ -250,6 +262,10 @@ class AllFunctionalTest extends TestCase return $data; } + /** + * @param string $output + * @return string + */ private function cleanOutput($output) { $processed = ''; diff --git a/tests/Composer/Test/Plugin/Mock/Capability.php b/tests/Composer/Test/Plugin/Mock/Capability.php index 79635a314..a9dd4accb 100644 --- a/tests/Composer/Test/Plugin/Mock/Capability.php +++ b/tests/Composer/Test/Plugin/Mock/Capability.php @@ -14,8 +14,14 @@ namespace Composer\Test\Plugin\Mock; class Capability implements \Composer\Plugin\Capability\Capability { + /** + * @var mixed[] + */ public $args; + /** + * @param mixed[] $args + */ public function __construct(array $args) { $this->args = $args;