Commit faf53eeb authored by Hendrik Heneke's avatar Hendrik Heneke
Browse files

Compatibility with PHP >= 7.2.

parent 3004eca0
Pipeline #392 passed with stage
in 26 seconds
......@@ -10,7 +10,10 @@ use Symfony\Component\Console\Input\InputOption;
abstract class AbstractCommand extends Command
{
protected string $projectDir;
/**
* @var string
*/
protected $projectDir;
public function __construct(string $projectDir, ?string $name = null)
{
......
......@@ -10,9 +10,18 @@ use LightnCandy\LightnCandy;
class Compiler extends FileReader
{
private ValuesLoader $loader;
private ?\Closure $fn = null;
private array $helpers = [];
/**
* @var ValuesLoader
*/
private $loader;
/**
* @var \Closure|null
*/
private $fn = null;
/**
* @var \Closure[]
*/
private $helpers = [];
public function __construct(File $file, ValuesLoader $loader)
{
......@@ -24,19 +33,16 @@ class Compiler extends FileReader
return password_hash($password, PASSWORD_DEFAULT);
},
'password_hash_bcrypt' => function ($password) {
if (!in_array('2y', password_algos())) {
throw new \Exception('bcrypt algorithm not supported!');
}
return password_hash($password, PASSWORD_BCRYPT);
},
'password_hash_argon2i' => function ($password) {
if (!in_array('argon2i', password_algos())) {
if (!defined('PASSWORD_ARGON2I')) {
throw new \Exception('argon2i algorithm not supported!');
}
return password_hash($password, PASSWORD_ARGON2I);
},
'password_hash_argon2id' => function ($password) {
if (!in_array('argon2id', password_algos())) {
if (!defined('PASSWORD_ARGON2ID')) {
throw new \Exception('argon2id algorithm not supported!');
}
return password_hash($password, PASSWORD_ARGON2ID);
......
......@@ -8,11 +8,26 @@ use HHIT\ConfigGenerator\Generator\IO\Path;
class Definition
{
private string $id;
private File $templateFile;
private string $type;
private File $valuesFile;
private File $destinationFile;
/**
* @var string
*/
private $id;
/**
* @var File
*/
private $templateFile;
/**
* @var string
*/
private $type;
/**
* @var File
*/
private $valuesFile;
/**
* @var File
*/
private $destinationFile;
public function __construct(string $id, File $templateFile, string $type, File $valuesFile, File $destinationFile)
{
......
......@@ -11,7 +11,10 @@ use HHIT\ConfigGenerator\Generator\StringUtils;
class DefinitionReader
{
private string $projectDir;
/**
* @var string
*/
private $projectDir;
public function __construct(string $projectDir)
{
......
......@@ -14,8 +14,14 @@ use Symfony\Component\Dotenv\Dotenv;
class Factory
{
private string $projectDir;
private string $env;
/**
* @var string
*/
private $projectDir;
/**
* @var string
*/
private $env;
public function __construct(string $projectDir, string $env = 'dev')
{
......
......@@ -14,9 +14,18 @@ use Symfony\Component\Console\Output\OutputInterface;
class Generator
{
private DefinitionReader $definitionReader;
private ValuesLoaderFactory $valuesLoaderFactory;
private ValidatorFactory $validatorFactory;
/**
* @var DefinitionReader
*/
private $definitionReader;
/**
* @var ValuesLoaderFactory
*/
private $valuesLoaderFactory;
/**
* @var ValidatorFactory
*/
private $validatorFactory;
public function __construct(
DefinitionReader $definitionReader,
......
......@@ -5,7 +5,10 @@ namespace HHIT\ConfigGenerator\Generator\IO;
class FileReader
{
private File $file;
/**
* @var File
*/
private $file;
public function __construct(File $file)
{
......
......@@ -5,7 +5,10 @@ namespace HHIT\ConfigGenerator\Generator\IO;
class FileWriter
{
private File $file;
/**
* @var File
*/
private $file;
public function __construct(File $file)
{
......
......@@ -14,11 +14,12 @@ class JsonReader extends FileReader
{
$str = $this->read();
if ($str) {
try {
return json_decode($str, $assoc, $depth, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new \RuntimeException('Reading JSON failed', 0, $e);
$decoded = @json_decode($str, $assoc, $depth);
$err = json_last_error();
if ($err !== JSON_ERROR_NONE) {
throw new \RuntimeException('Reading JSON failed: ' . json_last_error_msg(), $err);
}
return $decoded;
}
}
}
......@@ -7,7 +7,10 @@ use HHIT\ConfigGenerator\Generator\StringUtils;
abstract class Path
{
private string $path;
/**
* @var string
*/
private $path;
protected function __construct(string $path, ?File $relativeTo = null)
{
......
......@@ -5,7 +5,10 @@ namespace HHIT\ConfigGenerator\Generator\Secrets;
class SecretProviderFactory
{
private SymfonyVaultSecretProvider $symfonyProvider;
/**
* @var SymfonyVaultSecretProvider
*/
private $symfonyProvider;
public function __construct(SymfonyVaultSecretProvider $symfonyProvider)
{
......
......@@ -8,8 +8,14 @@ use Symfony\Bundle\FrameworkBundle\Secrets\SodiumVault;
class SymfonyVaultSecretProvider implements SecretProviderInterface
{
private SodiumVault $sodiumVault;
private DotenvVault $dotenvVault;
/**
* @var SodiumVault
*/
private $sodiumVault;
/**
* @var DotenvVault
*/
private $dotenvVault;
public function __construct(SodiumVault $sodiumVault, DotenvVault $dotenvVault)
{
......
......@@ -7,10 +7,10 @@ class JSONValidator implements ValidatorInterface
{
public function validate(string $content)
{
try {
json_decode($content, false, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new ValidationException("JSON is invalid: {$e->getMessage()}", $e->getCode(), $e);
@json_decode($content, false, 512);
$err = json_last_error();
if ($err !== JSON_ERROR_NONE) {
throw new ValidationException("JSON is invalid: " . json_last_error_msg(), $err);
}
}
}
......@@ -9,9 +9,18 @@ use HHIT\ConfigGenerator\Generator\Secrets\SecretProviderInterface;
class ValuesLoader extends JsonReader
{
private array $context = [];
private SecretProviderInterface $provider;
private string $env;
/**
* @var array
*/
private $context = [];
/**
* @var SecretProviderInterface
*/
private $provider;
/**
* @var string
*/
private $env;
public function __construct(File $file, SecretProviderInterface $provider, string $env)
{
......
......@@ -8,8 +8,14 @@ use HHIT\ConfigGenerator\Generator\Secrets\SecretProviderFactory;
class ValuesLoaderFactory
{
private SecretProviderFactory $secretProviderFactory;
private string $env;
/**
* @var SecretProviderFactory
*/
private $secretProviderFactory;
/**
* @var string
*/
private $env;
public function __construct(SecretProviderFactory $secretProviderFactory, string $env)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment