Skip to content

Commit 9478d6a

Browse files
committed
Refactor
1 parent 8e72745 commit 9478d6a

File tree

3 files changed

+20
-22
lines changed

3 files changed

+20
-22
lines changed

src/Cli/IO.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public static function error(Throwable $e, bool $logStackTrace = true): void
9898
]);
9999
}
100100

101+
public static function warning(string $message): void
102+
{
103+
self::writeln(Styles::bold(Styles::bgYellow(' ! ')) . ' ' . Styles::yellow($message));
104+
}
105+
101106
public static function enableVerbose(): void
102107
{
103108
if (self::$verboseMode) return;

src/Commands/Deploy.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5858
sprintf("Deploying %s to environment %s", Styles::bold($appName), Styles::bold($environment)),
5959
]);
6060

61-
// Analyze dependencies for optimization warnings
6261
$dependencyWarnings = DependencyAnalyzer::analyzeComposerDependencies();
6362
if (!empty($dependencyWarnings)) {
64-
IO::writeln(['']);
63+
IO::writeln('');
6564
foreach ($dependencyWarnings as $warning) {
66-
IO::writeln(Styles::yellow('' . $warning));
65+
IO::warning($warning);
6766
}
68-
IO::writeln(['']);
67+
IO::writeln('');
6968
}
7069

7170
IO::spin('creating deployment');

src/Helpers/DependencyAnalyzer.php

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@ public static function analyzeComposerDependencies(string $composerJsonPath = 'c
3434
return [];
3535
}
3636

37-
// Check for AWS SDK
38-
if (isset($require['aws/aws-sdk-php'])) {
37+
// Check for AWS SDK in composer.json or vendor directory
38+
$hasAwsSdk = isset($require['aws/aws-sdk-php']) ||
39+
(is_dir('vendor/aws/aws-sdk-php') && file_exists('vendor/aws/aws-sdk-php/composer.json'));
40+
41+
if ($hasAwsSdk) {
3942
$isOptimized = self::isAwsSdkOptimized($composer);
4043
if (!$isOptimized) {
4144
$warnings[] = 'AWS SDK detected - optimize your deployment size: https://github.com/aws/aws-sdk-php/tree/master/src/Script/Composer';
4245
}
4346
}
4447

45-
// Check for Google SDK
46-
if (isset($require['google/apiclient']) || isset($require['google/cloud'])) {
48+
// Check for Google SDK in composer.json or vendor directory
49+
$hasGoogleSdk = isset($require['google/apiclient']) ||
50+
(is_dir('vendor/google/apiclient') && file_exists('vendor/google/apiclient/composer.json'));
51+
52+
if ($hasGoogleSdk) {
4753
$isOptimized = self::isGoogleSdkOptimized($composer);
4854
if (!$isOptimized) {
4955
$warnings[] = 'Google SDK detected - optimize your deployment size: https://github.com/googleapis/google-api-php-client#cleaning-up-unused-services';
@@ -68,18 +74,12 @@ private static function isAwsSdkOptimized(array $composer): bool
6874
if (is_array($scripts) && isset($scripts['pre-autoload-dump'])) {
6975
$preAutoloadDump = (array) $scripts['pre-autoload-dump'];
7076
foreach ($preAutoloadDump as $script) {
71-
if (is_string($script) && str_contains($script, 'aws-sdk-php') && str_contains($script, 'remove-unused-services')) {
77+
if (is_string($script) && str_contains($script, 'Aws\\Script\\Composer\\Composer::removeUnusedServices')) {
7278
return true;
7379
}
7480
}
7581
}
7682

77-
// Check for custom AWS SDK optimizations in extra section
78-
$extra = $composer['extra'] ?? [];
79-
if (is_array($extra) && isset($extra['aws']) && is_array($extra['aws']) && isset($extra['aws']['includes'])) {
80-
return true;
81-
}
82-
8383
return false;
8484
}
8585

@@ -94,18 +94,12 @@ private static function isGoogleSdkOptimized(array $composer): bool
9494
if (is_array($scripts) && isset($scripts['pre-autoload-dump'])) {
9595
$preAutoloadDump = (array) $scripts['pre-autoload-dump'];
9696
foreach ($preAutoloadDump as $script) {
97-
if (is_string($script) && str_contains($script, 'google') && str_contains($script, 'remove-unused-services')) {
97+
if (is_string($script) && str_contains($script, 'Google\\Task\\Composer::cleanup')) {
9898
return true;
9999
}
100100
}
101101
}
102102

103-
// Check for custom Google SDK optimizations in extra section
104-
$extra = $composer['extra'] ?? [];
105-
if (is_array($extra) && isset($extra['google']) && is_array($extra['google']) && isset($extra['google']['exclude_files'])) {
106-
return true;
107-
}
108-
109103
return false;
110104
}
111105
}

0 commit comments

Comments
 (0)