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