@@ -26,30 +26,27 @@ class ComposerUtility
2626 /**
2727 * Runtime cache for composer.json data
2828 *
29- * @var array
29+ * @var array<string,array<string,mixed>>
3030 */
3131 protected static $ composerManifestCache ;
3232
3333 /**
3434 * Runtime cache for composer.lock data
3535 *
36- * @var array
36+ * @var array<string,mixed>
3737 */
3838 protected static $ composerLockCache ;
3939
4040 /**
4141 * Returns contents of Composer manifest - or part there of.
4242 *
4343 * @param string $manifestPath
44- * @param string $configurationPath Optional. Only return the part of the manifest indexed by configurationPath
45- * @return array| mixed
44+ * @param ? string $configurationPath Optional. Only return the part of the manifest indexed by configurationPath
45+ * @return mixed
4646 */
4747 public static function getComposerManifest (string $ manifestPath , ?string $ configurationPath = null )
4848 {
4949 $ composerManifest = static ::readComposerManifest ($ manifestPath );
50- if ($ composerManifest === null ) {
51- return null ;
52- }
5350
5451 if ($ configurationPath !== null ) {
5552 return ObjectAccess::getPropertyPath ($ composerManifest , $ configurationPath );
@@ -60,7 +57,7 @@ public static function getComposerManifest(string $manifestPath, ?string $config
6057 /**
6158 * Read the content of the composer.lock
6259 *
63- * @return array
60+ * @return array<string,mixed>
6461 */
6562 public static function readComposerLock (): array
6663 {
@@ -72,8 +69,8 @@ public static function readComposerLock(): array
7269 return [];
7370 }
7471
75- $ json = file_get_contents (FLOW_PATH_ROOT . 'composer.lock ' );
76- $ composerLock = json_decode ($ json , true );
72+ $ json = file_get_contents (FLOW_PATH_ROOT . 'composer.lock ' ) ?: '' ;
73+ $ composerLock = json_decode ($ json , true , flags: JSON_THROW_ON_ERROR );
7774 $ composerPackageVersions = isset ($ composerLock ['packages ' ]) ? $ composerLock ['packages ' ] : [];
7875 $ composerPackageDevVersions = isset ($ composerLock ['packages-dev ' ]) ? $ composerLock ['packages-dev ' ] : [];
7976 self ::$ composerLockCache = array_merge ($ composerPackageVersions , $ composerPackageDevVersions );
@@ -85,7 +82,7 @@ public static function readComposerLock(): array
8582 * Read the content of composer.json in the given path
8683 *
8784 * @param string $manifestPath
88- * @return array
85+ * @return array<string,mixed>
8986 * @throws Exception\MissingPackageManifestException
9087 */
9188 protected static function readComposerManifest (string $ manifestPath ): array
@@ -98,8 +95,8 @@ protected static function readComposerManifest(string $manifestPath): array
9895 if (!is_file ($ manifestPathAndFilename )) {
9996 throw new Exception \MissingPackageManifestException (sprintf ('No composer manifest file found at "%s". ' , $ manifestPathAndFilename ), 1349868540 );
10097 }
101- $ json = file_get_contents ($ manifestPathAndFilename );
102- $ composerManifest = json_decode ($ json , true );
98+ $ json = file_get_contents ($ manifestPathAndFilename ) ?: '' ;
99+ $ composerManifest = json_decode ($ json , true , flags: JSON_THROW_ON_ERROR );
103100
104101 if ($ composerManifest === null ) {
105102 throw new Exception \InvalidPackageManifestException (sprintf ('The composer manifest file found at "%s" could not be parsed. Check for JSON syntax errors! ' , $ manifestPathAndFilename ), 1493909988 );
@@ -131,18 +128,16 @@ public static function isFlowPackageType(string $packageType): bool
131128 *
132129 * @param string $manifestPath
133130 * @param FlowPackageKey $packageKey
134- * @param array $composerManifestData
135- * @return array the manifest data written
131+ * @param array<string,mixed> $composerManifestData
132+ * @return array<string,mixed> the manifest data written
136133 */
137134 public static function writeComposerManifest (string $ manifestPath , FlowPackageKey $ packageKey , array $ composerManifestData = []): array
138135 {
139136 $ manifest = [
140137 'description ' => ''
141138 ];
142139
143- if ($ composerManifestData !== null ) {
144- $ manifest = array_merge ($ manifest , $ composerManifestData );
145- }
140+ $ manifest = array_merge ($ manifest , $ composerManifestData );
146141 if (!isset ($ manifest ['name ' ]) || empty ($ manifest ['name ' ])) {
147142 $ manifest ['name ' ] = $ packageKey ->deriveComposerPackageName ();
148143 }
0 commit comments