Skip to content

Commit

Permalink
Add php 8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
lacoder-png committed Oct 14, 2022
1 parent 548eb45 commit 29a5df4
Show file tree
Hide file tree
Showing 44 changed files with 445 additions and 648 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ vendor/
composer.lock
phpunit.xml
build/
.php-cs-fixer.cache
42 changes: 42 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

return (new PhpCsFixer\Config())
->setRiskyAllowed(false)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'header_comment' => [
'header' => '',
'separate' => 'none',
],
'single_blank_line_before_namespace' => true,
'no_extra_blank_lines' => [
'tokens' => [
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block'
]
],
'phpdoc_align' => false,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
'cast_spaces' => true,
'binary_operator_spaces' => false,
'increment_style' => false,
'yoda_style' => false,
'trailing_comma_in_multiline' => true,
'single_line_throw' => false,
])
->setFinder(
(new PhpCsFixer\Finder())
->exclude([
'vendor',
])
->in(__DIR__)
);
63 changes: 0 additions & 63 deletions .php_cs

This file was deleted.

12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
"type": "library",
"license": "MIT",
"require": {
"php": "^7.1",
"ulrichsg/getopt-php": "^3.2"
"php": "^7.4 || ^8.0",
"ulrichsg/getopt-php": "^4.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"phpunit/phpunit": "^7.5",
"vlucas/phpdotenv": "^2.4"
"friendsofphp/php-cs-fixer": "~v3.12.0",
"phpunit/phpunit": "^9.5",
"vlucas/phpdotenv": "v3.6.10"
},
"suggest": {
"vlucas/phpdotenv": "Required for DotEnvV2FileReaderAdapter."
"vlucas/phpdotenv": "Required for DotEnvFileReaderAdapter"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 1 addition & 6 deletions src/Decorator/EnvProviderDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

final class EnvProviderDecorator
{
/**
* @var EnvResolvingStrategyInterface|null $resolvingStrategy
*/
private static $resolvingStrategy;
private static ?EnvResolvingStrategyInterface $resolvingStrategy;

public static function init(EnvResolvingStrategyInterface $resolvingStrategy): void
{
Expand All @@ -25,9 +22,7 @@ public static function resetStrategy(): void
}

/**
* @param string $envName
* @throws EnvProviderDecoratorException
* @return string
*/
public static function getEnv(string $envName): string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Factory/FileBasedEnvResolvingStrategyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function createStrategy(
return new FileBasedEnvResolvingStrategy(
new FirstSuccessfulHostDetector([
new ServerHeadersBasedHostDetector($serverHeaderToSearch),
new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build())
new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build()),
]),
new DotEnvV2FileReaderAdapter(
new PathResolver($basePathToEnvFile, new SuffixAppendFormatter(DIRECTORY_SEPARATOR)),
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/HostBasedEnvResolvingStrategyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public static function createStrategy(
return new HostBasedEnvResolvingStrategy(
new FirstSuccessfulHostDetector([
new ServerHeadersBasedHostDetector($serverHeaderToSearch),
new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build())
new CliArgsBasedHostDetector($cliArgToSearch, GetOptAdapterFactory::build()),
]),
new FormatterPipeline([
new PrefixAppendFormatter($delimiter),
new CharReplaceFormatter('-', '_')
new CharReplaceFormatter('-', '_'),
])
);
}
Expand Down
25 changes: 9 additions & 16 deletions src/FileReader/DotEnvV2FileReaderAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,26 @@

namespace Lamoda\MultiEnv\FileReader;

use Dotenv\Dotenv;
use Dotenv\Exception\ExceptionInterface;
use Lamoda\MultiEnv\FileReader\Exception\EnvFileReaderException;
use Lamoda\MultiEnv\FileReader\FileNameResolver\FileNameResolverInterface;
use Lamoda\MultiEnv\FileReader\PathResolver\PathResolverInterface;
use Lamoda\MultiEnv\Model\HostId;

final class DotEnvV2FileReaderAdapter implements EnvFileReaderInterface
{
/**
* @var PathResolverInterface
*/
private $pathResolver;
private PathResolverInterface $pathResolver;

/**
* @var FileNameResolverInterface
*/
private $fileNameResolver;
private FileNameResolverInterface $fileNameResolver;

/**
* @var bool
*/
private $isEnvFileAlreadyLoaded;
private bool $isEnvFileAlreadyLoaded;

public function __construct(PathResolverInterface $pathResolver, FileNameResolverInterface $fileNameResolver)
{
// @codeCoverageIgnoreStart
if (!class_exists(\Dotenv\Dotenv::class)) {
throw EnvFileReaderException::becauseAdapterCanNotBeCreated(__CLASS__, \Dotenv\Dotenv::class);
if (!class_exists(Dotenv::class)) {
throw EnvFileReaderException::becauseAdapterCanNotBeCreated(__CLASS__, Dotenv::class);
}
// @codeCoverageIgnoreEnd
$this->pathResolver = $pathResolver;
Expand All @@ -45,13 +38,13 @@ public function readEnvFile(HostId $hostId): void
}

try {
$dotEnv = new \Dotenv\Dotenv(
$dotEnv = Dotenv::create(
$this->pathResolver->resolvePathToEnvFile($hostId),
$this->fileNameResolver->resolveEnvFileName($hostId)
);
$dotEnv->overload();
$this->isEnvFileAlreadyLoaded = true;
} catch (\Dotenv\Exception\ExceptionInterface $exception) {
} catch (ExceptionInterface $exception) {
throw EnvFileReaderException::becauseEnvFileCanNotBeProcessed($exception);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/FileReader/Exception/EnvFileReaderException.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static function becauseEnvFileCanNotBeProcessed(?Throwable $previous): se
return new self('Can\'t process file with env', 0, $previous);
}

public static function becauseAdapterCanNotBeCreated(string $adapterName, string $required)
public static function becauseAdapterCanNotBeCreated(string $adapterName, string $required): self
{
return new self('Can\t create adapter "' . $adapterName . '". It\'s require "' . $required . '"');
}
Expand Down
13 changes: 4 additions & 9 deletions src/FileReader/FileNameResolver/FileNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,10 @@
final class FileNameResolver implements FileNameResolverInterface
{
public const DEFAULT_FILE_NAME = '.env';
/**
* @var string
*/
private $originalFileName;

/**
*@var FormatterInterface|null
*/
private $formatter;

private string $originalFileName;

private ?FormatterInterface $formatter;

public function __construct(string $originalFileName = self::DEFAULT_FILE_NAME, FormatterInterface $formatter = null)
{
Expand Down
10 changes: 2 additions & 8 deletions src/FileReader/PathResolver/PathResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@

final class PathResolver implements PathResolverInterface
{
/**
* @var string
*/
private $originalPath;
private string $originalPath;

/**
* @var FormatterInterface|null
*/
private $formatter;
private ?FormatterInterface $formatter;

public function __construct(string $originalPath, FormatterInterface $formatter = null)
{
Expand Down
10 changes: 2 additions & 8 deletions src/Formatter/CharReplaceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@

final class CharReplaceFormatter implements FormatterInterface
{
/**
* @var string
*/
private $search;
private string $search;

/**
* @var string
*/
private $replace;
private string $replace;

public function __construct(string $search, string $replace)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/FormatterPipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class FormatterPipeline implements FormatterInterface
/**
* @var FormatterInterface[]
*/
private $formatters;
private array $formatters;

public function __construct(array $formatters)
{
Expand Down
8 changes: 1 addition & 7 deletions src/Formatter/PrefixAppendFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@

final class PrefixAppendFormatter implements FormatterInterface
{
/**
* @var string $delimiter
*/
private $delimiter;
private string $delimiter;

public function __construct(string $delimiter = '')
{
$this->delimiter = trim($delimiter);
}

/**
* @param string $originalName
* @param HostId $hostId
* @throws FormatterException
* @return string
*/
public function formatName(string $originalName, HostId $hostId): string
{
Expand Down
8 changes: 1 addition & 7 deletions src/Formatter/SuffixAppendFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@

final class SuffixAppendFormatter implements FormatterInterface
{
/**
* @var string $delimiter
*/
private $delimiter;
private string $delimiter;

public function __construct(string $delimiter = '')
{
$this->delimiter = trim($delimiter);
}

/**
* @param string $originalName
* @param HostId $hostId
* @throws FormatterException
* @return string
*/
public function formatName(string $originalName, HostId $hostId): string
{
Expand Down
Loading

0 comments on commit 29a5df4

Please sign in to comment.