Skip to content

Commit

Permalink
fix coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
rosven9856 committed Aug 21, 2024
1 parent 789a3a1 commit e1b7334
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 90 deletions.
6 changes: 4 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

declare(strict_types=1);

use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PHPyh\CodingStandard\PhpCsFixerCodingStandard;

$finder = PhpCsFixer\Finder::create()
$finder = Finder::create()
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
Expand All @@ -16,7 +18,7 @@
'benchmark.php',
]);

$config = (new PhpCsFixer\Config())
$config = (new Config())
->setFinder($finder)
->setCacheFile(__DIR__ . '/var/.php-cs-fixer.cache');

Expand Down
32 changes: 11 additions & 21 deletions src/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@

namespace App;

use Automattic\IgnoreFile;
use App\Configuration\Configuration;
use Automattic\IgnoreFile;

class Action
final readonly class Action
{
protected Configuration $configuration;
private Configuration $configuration;

/**
*
*/
public function __construct()
{
$this->configuration = new Configuration();
}

/**
* @return void
* @throws \Exception
*/
public function run()
public function run(): void
{
if (!extension_loaded('zip')) {
if (!\extension_loaded('zip')) {
throw new \Exception('ZIP extension is not loaded');
}

Expand All @@ -37,7 +33,7 @@ public function run()

// rights

mkdir($directory, 0755, true);
mkdir($directory, 0o755, true);

$ignore = new IgnoreFile();

Expand All @@ -50,24 +46,22 @@ public function run()

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

foreach ($iterator as $path) {

/**
* @var \SplFileInfo $path
*/
if ($path->getBasename() === '.gitignore') {
$ignore->add(
file_get_contents($path->getRealPath()),
dirname($path->getRealPath()) . '/'
\dirname($path->getRealPath()) . '/',
);
}
}

foreach ($iterator as $path) {

/**
* @var \SplFileInfo $path
*/
Expand All @@ -76,28 +70,24 @@ public function run()
}

if (!$ignore->ignores($path->getPathname())) {
$zip->addFile($path->getPathname(), str_replace($rootDirectory . DIRECTORY_SEPARATOR, '', $path->getPathname()));
$zip->addFile($path->getPathname(), str_replace($rootDirectory . \DIRECTORY_SEPARATOR, '', $path->getPathname()));
}
}

$zip->close();



$GITHUB_OUTPUT = (string) $this->configuration->get('GITHUB_OUTPUT');

if (!empty($GITHUB_OUTPUT)) {

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

file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);

file_put_contents($GITHUB_OUTPUT, "{$name}={$value}\n", FILE_APPEND);

$name = 'path';
$value = (string) $this->configuration->get('build.file');

file_put_contents($GITHUB_OUTPUT, "$name=$value\n", FILE_APPEND);
file_put_contents($GITHUB_OUTPUT, "{$name}={$value}\n", FILE_APPEND);
}
}
}
23 changes: 8 additions & 15 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,34 @@

final readonly class Configuration
{
protected array $options;
private array $options;

/**
* @use
*/
public function __construct ()
public function __construct()
{
$GITHUB_WORKSPACE = (string) getenv('GITHUB_WORKSPACE');
$GITHUB_OUTPUT = (string) getenv('GITHUB_OUTPUT');
$dirName = (string) getenv('BUILD_DIRECTORY_NAME');
$fileName = (string) getenv('BUILD_FILE_NAME');

$GITHUB_WORKSPACE = !empty($GITHUB_WORKSPACE) ? $GITHUB_WORKSPACE : realpath(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..');
$GITHUB_OUTPUT = !empty($GITHUB_OUTPUT) ? $GITHUB_OUTPUT : $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'outputcmd.txt';
$GITHUB_WORKSPACE = !empty($GITHUB_WORKSPACE) ? $GITHUB_WORKSPACE : realpath(__DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . '..');
$GITHUB_OUTPUT = !empty($GITHUB_OUTPUT) ? $GITHUB_OUTPUT : $GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . 'var' . \DIRECTORY_SEPARATOR . 'outputcmd.txt';
$dirName = !empty($dirName) ? $dirName : '.build';
$fileName = !empty($fileName) ? $fileName : 'package.zip';

$this->options = [
'GITHUB_WORKSPACE' => $GITHUB_WORKSPACE,
'GITHUB_OUTPUT' => $GITHUB_OUTPUT,
'build' => [
'directory' => $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . $dirName,
'file' => $GITHUB_WORKSPACE . DIRECTORY_SEPARATOR . $dirName . DIRECTORY_SEPARATOR . $fileName,
'directory' => $GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . $dirName,
'file' => $GITHUB_WORKSPACE . \DIRECTORY_SEPARATOR . $dirName . \DIRECTORY_SEPARATOR . $fileName,
],
];
}

/**
* @param string $option
* @return mixed
*/
public function get (string $option): mixed
public function get(string $option): mixed
{
$keys = explode('.', $option);
$target = $this->options;
Expand All @@ -57,10 +53,7 @@ public function get (string $option): mixed
return $target;
}

/**
* @return string
*/
public function getRootDirectory (): string
public function getRootDirectory(): string
{
return (string) $this->get('GITHUB_WORKSPACE');
}
Expand Down
Loading

0 comments on commit e1b7334

Please sign in to comment.