11<?php
2+ declare (strict_types=1 );
3+
24namespace Cake \Composer ;
35
46use Composer \Composer ;
79use Composer \Package \PackageInterface ;
810use Composer \Plugin \PluginInterface ;
911use Composer \Script \Event ;
12+ use DirectoryIterator ;
1013use RuntimeException ;
1114
1215class Plugin implements PluginInterface, EventSubscriberInterface
@@ -51,7 +54,7 @@ public static function getSubscribedEvents()
5154 * @param \Composer\Script\Event $event Composer's event object.
5255 * @return void
5356 */
54- public function postAutoloadDump (Event $ event )
57+ public function postAutoloadDump (Event $ event ): void
5558 {
5659 $ composer = $ event ->getComposer ();
5760 $ config = $ composer ->getConfig ();
@@ -78,16 +81,16 @@ public function postAutoloadDump(Event $event)
7881 * Add all composer packages of type `cakephp-plugin`, and all plugins located
7982 * in the plugins directory to a plugin-name indexed array of paths.
8083 *
81- * @param \Composer\Package\PackageInterface[] $packages Array of \Composer\Package\PackageInterface objects.
82- * @param array $pluginDirs The path to the plugins dir.
84+ * @param array< \Composer\Package\PackageInterface> $packages Array of \Composer\Package\PackageInterface objects.
85+ * @param array<string> $pluginDirs The path to the plugins dir.
8386 * @param string $vendorDir The path to the vendor dir.
84- * @return array Plugin name indexed paths to plugins.
87+ * @return array<string, string> Plugin name indexed paths to plugins.
8588 */
8689 public function findPlugins (
8790 array $ packages ,
8891 array $ pluginDirs = ['plugins ' ],
89- $ vendorDir = 'vendor '
90- ) {
92+ string $ vendorDir = 'vendor '
93+ ): array {
9194 $ plugins = [];
9295
9396 foreach ($ packages as $ package ) {
@@ -103,7 +106,7 @@ public function findPlugins(
103106 foreach ($ pluginDirs as $ path ) {
104107 $ path = $ this ->getFullPath ($ path , $ vendorDir );
105108 if (is_dir ($ path )) {
106- $ dir = new \ DirectoryIterator ($ path );
109+ $ dir = new DirectoryIterator ($ path );
107110 foreach ($ dir as $ info ) {
108111 if (!$ info ->isDir () || $ info ->isDot ()) {
109112 continue ;
@@ -131,7 +134,7 @@ public function findPlugins(
131134 * @param string $vendorDir The path to the vendor dir.
132135 * @return string
133136 */
134- public function getFullPath ($ path , $ vendorDir )
137+ public function getFullPath (string $ path , string $ vendorDir ): string
135138 {
136139 if (preg_match ('{^(?:/|[a-z]:|[a-z0-9.]+://)}i ' , $ path )) {
137140 return rtrim ($ path , '/ ' );
@@ -148,11 +151,11 @@ public function getFullPath($path, $vendorDir)
148151 * Rewrite the config file with a complete list of plugins.
149152 *
150153 * @param string $configFile The path to the config file.
151- * @param array $plugins Array of plugins.
154+ * @param array<string, string> $plugins Array of plugins.
152155 * @param string|null $root The root directory. Defaults to a value generated from `$configFile`.
153156 * @return void
154157 */
155- public function writeConfigFile ($ configFile , array $ plugins , $ root = null )
158+ public function writeConfigFile (string $ configFile , array $ plugins , ? string $ root = null ): void
156159 {
157160 $ root = $ root ?: dirname (dirname ($ configFile ));
158161
@@ -212,7 +215,7 @@ public function writeConfigFile($configFile, array $plugins, $root = null)
212215 * @param string $vendorDir Path to composer-vendor dir.
213216 * @return string Absolute file path.
214217 */
215- public function getConfigFilePath ($ vendorDir )
218+ public function getConfigFilePath (string $ vendorDir ): string
216219 {
217220 return $ vendorDir . DIRECTORY_SEPARATOR . 'cakephp-plugins.php ' ;
218221 }
@@ -224,10 +227,11 @@ public function getConfigFilePath($vendorDir)
224227 * @return string The package's primary namespace.
225228 * @throws \RuntimeException When the package's primary namespace cannot be determined.
226229 */
227- public function getPrimaryNamespace (PackageInterface $ package )
230+ public function getPrimaryNamespace (PackageInterface $ package ): string
228231 {
229232 $ primaryNs = null ;
230233 $ autoLoad = $ package ->getAutoload ();
234+ /** @var array<string, string> $pathMap */
231235 foreach ($ autoLoad as $ type => $ pathMap ) {
232236 if ($ type !== 'psr-4 ' ) {
233237 continue ;
@@ -265,6 +269,6 @@ public function getPrimaryNamespace(PackageInterface $package)
265269 );
266270 }
267271
268- return trim (( string ) $ primaryNs , '\\' );
272+ return trim ($ primaryNs , '\\' );
269273 }
270274}
0 commit comments