diff --git a/assets/css/style.css b/assets/css/style.css index cd5fdf8..4a8adf0 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -7,11 +7,11 @@ } #spanner { - display:none; + display:none; position: absolute; top: 50%; left: 50%; - margin-left:-13rem; - margin-top:-10rem; + margin-left:-13rem; + margin-top:-10rem; z-index: 1000; } diff --git a/composer.json b/composer.json index 02a0098..59b34a7 100644 --- a/composer.json +++ b/composer.json @@ -1,18 +1,18 @@ { - "name": "5dvision/siga-php-sample-app", - "description": "SiGa sample application", - "homepage": "https://5dvision.ee", - "type": "project", - "license": "MIT", - "support": { + "name": "5dvision/siga-php-sample-app", + "description": "SiGa sample application", + "homepage": "https://5dvision.ee", + "type": "project", + "license": "MIT", + "support": { "issues": "https://github.com/5dvision/siga-php-sample-app/issues", "source": "https://github.com/5dvision/siga-php-sample-app" }, - "authors": [{ - "name": "Kullar Kert", - "email": "kullar.kert@gmail.com" - }], - "repositories": [ + "authors": [{ + "name": "Kullar Kert", + "email": "kullar.kert@gmail.com" + }], + "repositories": [ { "type": "path", "url": "../siga-php-client", @@ -20,11 +20,15 @@ "symlink": true } } - ], - "minimum-stability": "stable", - "require": { - "php": "^7.2.5 || ^8.0", + ], + "minimum-stability": "stable", + "require": { + "php": ">=8.2", "ext-json": "*", - "5dvision/siga-php-client": "dev-master" + "5dvision/siga-php-client": "dev-master" + }, + "require-dev": { + "rector/rector": "^2.4", + "laravel/pint": "^1.29" } } diff --git a/composer.lock b/composer.lock index 0752c6b..1707d28 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1d5470d901b08aae7e066abf2ae780f9", + "content-hash": "7b82dc60283424c5ff451b036be786bd", "packages": [ { "name": "5dvision/siga-php-client", @@ -12,7 +12,7 @@ "dist": { "type": "path", "url": "../siga-php-client", - "reference": "565eae514bcfcac749943655ac57092029f806e0" + "reference": "b76f4d4acc214b81fdb5cae3479438a4010d13dc" }, "require": { "ext-ctype": "*", @@ -20,7 +20,10 @@ "ext-json": "*", "ext-zip": "*", "guzzlehttp/guzzle": "^7.1", - "php": "^7.2.5 || ^8.0" + "php": ">=8.2" + }, + "require-dev": { + "rector/rector": "^2.4" }, "type": "library", "autoload": { @@ -659,7 +662,200 @@ "time": "2024-09-25T14:20:29+00:00" } ], - "packages-dev": [], + "packages-dev": [ + { + "name": "laravel/pint", + "version": "v1.29.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/pint.git", + "reference": "0770e9b7fafd50d4586881d456d6eb41c9247a80" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/pint/zipball/0770e9b7fafd50d4586881d456d6eb41c9247a80", + "reference": "0770e9b7fafd50d4586881d456d6eb41c9247a80", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "php": "^8.2.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.95.1", + "illuminate/view": "^12.56.0", + "larastan/larastan": "^3.9.6", + "laravel-zero/framework": "^12.1.0", + "mockery/mockery": "^1.6.12", + "nunomaduro/termwind": "^2.4.0", + "pestphp/pest": "^3.8.6", + "shipfastlabs/agent-detector": "^1.1.3" + }, + "bin": [ + "builds/pint" + ], + "type": "project", + "autoload": { + "psr-4": { + "App\\": "app/", + "Database\\Seeders\\": "database/seeders/", + "Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "An opinionated code formatter for PHP.", + "homepage": "https://laravel.com", + "keywords": [ + "dev", + "format", + "formatter", + "lint", + "linter", + "php" + ], + "support": { + "issues": "https://github.com/laravel/pint/issues", + "source": "https://github.com/laravel/pint" + }, + "time": "2026-04-20T15:26:14+00:00" + }, + { + "name": "phpstan/phpstan", + "version": "2.2.2", + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e5cc34d491a90e79c216d824f60fe21fd4d93bd6", + "reference": "e5cc34d491a90e79c216d824f60fe21fd4d93bd6", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ondřej Mirtes" + }, + { + "name": "Markus Staab" + }, + { + "name": "Vincent Langlet" + } + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2026-06-05T09:00:01+00:00" + }, + { + "name": "rector/rector", + "version": "2.4.5", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "cbd86024be5014d3c14d9f0b3f7aae8ecbffd62c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/cbd86024be5014d3c14d9f0b3f7aae8ecbffd62c", + "reference": "cbd86024be5014d3c14d9f0b3f7aae8ecbffd62c", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.1.56" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "homepage": "https://getrector.com/", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/2.4.5" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2026-05-26T21:03:22+00:00" + } + ], "aliases": [], "minimum-stability": "stable", "stability-flags": { @@ -668,8 +864,9 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": "^7.2.5 || ^8.0" + "php": "^7.2.5 || ^8.0", + "ext-json": "*" }, - "platform-dev": [], - "plugin-api-version": "2.6.0" + "platform-dev": {}, + "plugin-api-version": "2.9.0" } diff --git a/config.php b/config.php index 3339e5e..d163729 100644 --- a/config.php +++ b/config.php @@ -10,29 +10,41 @@ /** * Siga endpoint URL */ -define('SIGA_ENDPOINT', 'https://dsig.eesti.ee'); +if (!defined('SIGA_ENDPOINT')) { + define('SIGA_ENDPOINT', 'https://dsig.eesti.ee'); +} /** * Siga client name */ -define('SIGA_CLIENT_NAME', ''); +if (!defined('SIGA_CLIENT_NAME')) { + define('SIGA_CLIENT_NAME', ''); +} /** * Siga service name */ -define('SIGA_SERVICE_NAME', ''); +if (!defined('SIGA_SERVICE_NAME')) { + define('SIGA_SERVICE_NAME', ''); +} /** * Siga ServiceUUID for header(X-Authorization-ServiceUUID) */ -define('SIGA_UUID', ''); +if (!defined('SIGA_UUID')) { + define('SIGA_UUID', ''); +} /** * Siga signing secret */ -define('SIGA_SIGN_SECRET', ''); +if (!defined('SIGA_SIGN_SECRET')) { + define('SIGA_SIGN_SECRET', ''); +} /** * Upload directory where the uploaded files are stored */ -define('UPLOAD_DIR', __DIR__ . DIRECTORY_SEPARATOR . 'uploads'); +if (!defined('UPLOAD_DIR')) { + define('UPLOAD_DIR', __DIR__ . DIRECTORY_SEPARATOR . 'uploads'); +} diff --git a/helpers/functions.php b/helpers/functions.php index bf4e4f9..42c0b4a 100644 --- a/helpers/functions.php +++ b/helpers/functions.php @@ -22,8 +22,8 @@ function getUploadDirectory() function getContainerName($containerId, $files) { - //lets find container name from first uploaded file - $containerName = explode('.', array_keys($files)[0])[0]; + //let's find container name from first uploaded file + $containerName = explode('.', (string) array_keys($files)[0])[0]; if (!$containerName) { $containerName = $containerId; @@ -50,7 +50,7 @@ function uploadFile() //Upload file $filename = $_FILES[$input_field_name]['name']; - $ext = pathinfo($filename, PATHINFO_EXTENSION); + $ext = pathinfo((string) $filename, PATHINFO_EXTENSION); $uFilename = uniqid('SiGa', true).'.'.$ext; $destination = getUploadDirectory() .'/'. $uFilename; @@ -94,33 +94,16 @@ function deleteUploadedFiles(array $files) */ function getUploadErrorException($code) { - switch ($code) { - case UPLOAD_ERR_INI_SIZE: - $message = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; - break; - case UPLOAD_ERR_FORM_SIZE: - $message = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; - break; - case UPLOAD_ERR_PARTIAL: - $message = 'The uploaded file was only partially uploaded'; - break; - case UPLOAD_ERR_NO_FILE: - $message = 'No file was uploaded'; - break; - case UPLOAD_ERR_NO_TMP_DIR: - $message = 'Missing a temporary folder'; - break; - case UPLOAD_ERR_CANT_WRITE: - $message = 'Failed to write file to disk'; - break; - case UPLOAD_ERR_EXTENSION: - $message = 'File upload stopped by extension'; - break; - - default: - $message = 'Unknown upload error'; - break; - } + $message = match ($code) { + UPLOAD_ERR_INI_SIZE => 'The uploaded file exceeds the upload_max_filesize directive in php.ini', + UPLOAD_ERR_FORM_SIZE => 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form', + UPLOAD_ERR_PARTIAL => 'The uploaded file was only partially uploaded', + UPLOAD_ERR_NO_FILE => 'No file was uploaded', + UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary folder', + UPLOAD_ERR_CANT_WRITE => 'Failed to write file to disk', + UPLOAD_ERR_EXTENSION => 'File upload stopped by extension', + default => 'Unknown upload error', + }; return new Exception($message, $code); } @@ -137,7 +120,7 @@ function human_filesize($bytes, $decimals = 2) { $sz = 'BKMGTP'; $factor = floor((strlen($bytes) - 1) / 3) ?: 0; - return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor]; + return sprintf("%.{$decimals}f", $bytes / 1024 ** $factor) . @$sz[$factor]; } /** @@ -159,9 +142,9 @@ function dump($input) * * @param mixed $input Input * - * @return void + * @return never */ -function dd($input) +function dd($input): never { dump($input); exit(); diff --git a/index.php b/index.php index b77ae75..cd044d9 100644 --- a/index.php +++ b/index.php @@ -14,7 +14,7 @@ 'secret' => SIGA_SIGN_SECRET, ]); -if ($_SESSION['containerId']) { +if (!empty($_SESSION['containerId'])) { $sigaClient->setContainerId($_SESSION['containerId']); } @@ -56,7 +56,7 @@ function loadFooter() /* Parse acts */ -if ($_GET['action'] == 'download_container') { +if (!empty($_GET['action']) && $_GET['action'] == 'download_container') { try { $pathToFile = getUploadDirectory(). DIRECTORY_SEPARATOR . $_SESSION['containerId'].'.asice'; @@ -88,7 +88,7 @@ function loadFooter() try { $files = uploadFile(); - loadContentTemplate($action, ['files'=> $files]); + loadContentTemplate($action, ['files' => $files]); $_SESSION['containerId'] = $sigaClient->createContainer($_POST['containerType'], $files); $_SESSION['containerFiles'] = array_column($files, 'path', 'name'); diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..ea5e72c --- /dev/null +++ b/pint.json @@ -0,0 +1,3 @@ +{ + "preset": "psr12" +} diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..82a14a7 --- /dev/null +++ b/rector.php @@ -0,0 +1,15 @@ +withPaths([ + __DIR__ . '/actions', + __DIR__ . '/helpers', + __DIR__ . '/templates', + __DIR__ . '/index.php', + __DIR__ . '/config.php', + ]) + ->withPhpSets(); diff --git a/templates/create_new_doc.php b/templates/create_new_doc.php index 21cb4a3..cd5b0b2 100644 --- a/templates/create_new_doc.php +++ b/templates/create_new_doc.php @@ -1,4 +1,4 @@ - + -