Skip to content

Commit

Permalink
general logic for creating package.zip
Browse files Browse the repository at this point in the history
  • Loading branch information
rosven9856 committed May 29, 2024
1 parent 1d305b1 commit 5807cbf
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
}
],
"require": {
"php": "^8.3"
"php": "^8.3",
"ext-zip": "*"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.42",
Expand Down
37 changes: 36 additions & 1 deletion src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,41 @@ public function __construct()
*/
public function run()
{
// $this->configuration->get('build.directory');
if (!extension_loaded('zip')) {
// throw
}

$directory = $this->configuration->get('build.directory');

if (is_dir($directory)) {

Check failure on line 32 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

MixedArgument

src/Action.php:32:20: MixedArgument: Argument 1 of is_dir cannot be mixed, expecting string (see https://psalm.dev/030)
// throw
}

// rights

mkdir($directory, 0755, true);

Check failure on line 38 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

MixedArgument

src/Action.php:38:15: MixedArgument: Argument 1 of mkdir cannot be mixed, expecting string (see https://psalm.dev/030)

$zip = new \ZipArchive();
if (!$zip->open($this->configuration->get('build.file'), \ZipArchive::CREATE)) {

Check failure on line 41 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

RiskyTruthyFalsyComparison

src/Action.php:41:13: RiskyTruthyFalsyComparison: Operand of type bool|int contains type int, which can be falsy and truthy. This can cause possibly unexpected behavior. Use strict comparison instead. (see https://psalm.dev/356)

Check failure on line 41 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

MixedArgument

src/Action.php:41:25: MixedArgument: Argument 1 of ZipArchive::open cannot be mixed, expecting string (see https://psalm.dev/030)
// throw
}

$rootDirectory = $this->configuration->getRootDirectory();

$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($rootDirectory),
\RecursiveIteratorIterator::CHILD_FIRST
);

foreach ($iterator as $path) {

// exclude files described in .gitignore

if ($path->isFile()) {

Check failure on line 56 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

MixedMethodCall

src/Action.php:56:24: MixedMethodCall: Cannot determine the type of $path when calling method isFile (see https://psalm.dev/015)
$zip->addFile($path->getPathname(), str_replace($rootDirectory . DIRECTORY_SEPARATOR, '', $path->getPathname()));

Check failure on line 57 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

MixedArgument

src/Action.php:57:31: MixedArgument: Argument 1 of ZipArchive::addFile cannot be mixed, expecting string (see https://psalm.dev/030)

Check failure on line 57 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

MixedMethodCall

src/Action.php:57:38: MixedMethodCall: Cannot determine the type of $path when calling method getPathname (see https://psalm.dev/015)

Check failure on line 57 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

PossiblyInvalidCast

src/Action.php:57:53: PossiblyInvalidCast: array<array-key, string> cannot be cast to string (see https://psalm.dev/190)

Check failure on line 57 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

PossiblyInvalidArgument

src/Action.php:57:53: PossiblyInvalidArgument: Argument 2 of ZipArchive::addFile expects string, but possibly different type array<array-key, string>|string provided (see https://psalm.dev/092)

Check failure on line 57 in src/Action.php

View workflow job for this annotation

GitHub Actions / psalm (8.3)

MixedArgument

src/Action.php:57:107: MixedArgument: Argument 3 of str_replace cannot be mixed, expecting array<array-key, float|int|string>|string (see https://psalm.dev/030)
}
}

$zip->close();
}
}
5 changes: 5 additions & 0 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,9 @@ public function get (string $option): mixed

return $target;
}

public function getRootDirectory (): string
{
return realpath($this->get('build.directory') . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR);
}
}

0 comments on commit 5807cbf

Please sign in to comment.