Skip to content

Commit

Permalink
Merge pull request #4 from portrino/feature/symfony-v7
Browse files Browse the repository at this point in the history
allow required symfony/* packages >=7.0
  • Loading branch information
EvilBMP authored Jun 19, 2024
2 parents fcd65bf + 33e6df9 commit 0208169
Show file tree
Hide file tree
Showing 30 changed files with 245 additions and 165 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: CI
on:
push:
pull_request:
schedule:
- cron: '5 5 * * *'

jobs:
testsuite:
Expand All @@ -28,4 +26,4 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
php: [ '8.0', '8.1', '8.2', '8.3' ]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.build
/.idea
/.env*
/.php-cs-fixer.cache
/composer.lock
5 changes: 5 additions & 0 deletions build/php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()->exclude(['node_modules', 'var'])->in(__DIR__ . '/..');
return $config;
12 changes: 8 additions & 4 deletions build/phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
includes:
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-strict-rules/rules.neon
- %currentWorkingDirectory%/.build/vendor/phpstan/phpstan-deprecation-rules/rules.neon

parameters:
level: 5
level: 8

paths:
- %currentWorkingDirectory%/spec
- %currentWorkingDirectory%/src
- %currentWorkingDirectory%/tests

# ignoreErrors:
# - '#Call to method .* on an unknown class .*PxRegisterUser.*#'
# - '#(Parameter|Property) .* has (invalid type|unknown class) .*PxRegisterUser(Repository)?.*#'
ignoreErrors:
- '#Class .* extends generic class PhpSpec\\ObjectBehavior but does not specify its types: TKey, TValue#'
- '#Property class@anonymous.*callable has no type specified.*#'
30 changes: 20 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@
}
],
"require": {
"php": ">=7.2",
"php": ">=8.0",
"jackiedo/dotenv-editor": "^2.0",
"symfony/console": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/dotenv": "^3.4 || ^4.0 || ^5.0 || ^6.0",
"symfony/process": "^3.4 || ^4.0 || ^5.0 || ^6.0"
"symfony/console": "^6.0 || ^7.0",
"symfony/dotenv": "^6.0 || ^7.0",
"symfony/process": "^6.0 || ^7.0"
},
"require-dev": {
"behat/behat": "^3.4",
"composer/composer": "^1.0 || ^2.0",
"ergebnis/composer-normalize": "^2.19",
"phpspec/phpspec": "^4.3 || ^5.0 || ^6.0 || ^7.0",
"phpstan/phpstan": "^1.10"
"behat/behat": "^3.14",
"composer/composer": "^2.0",
"ergebnis/composer-normalize": "^2.43",
"friendsofphp/php-cs-fixer": "^3.47",
"phpspec/phpspec": "^7.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-strict-rules": "^1.5",
"typo3/coding-standards": "^0.7"
},
"replace": {
"sroze/companienv": "*"
Expand Down Expand Up @@ -74,13 +78,19 @@
"ci:php:stan": "./.build/bin/phpstan analyse -c ./build/phpstan.neon --no-progress",
"ci:static": [
"@ci:composer:normalize",
"@ci:php:cs-fixer",
"@ci:php:lint",
"@ci:php:stan"
],
"ci:test": [
"@ci:test:behat"
],
"ci:test:behat": "./.build/bin/behat --strict --stop-on-failure"
"ci:test:behat": "./.build/bin/behat --strict --stop-on-failure",
"fix:php": [
"@fix:php:cs",
"@fix:php:sniff"
],
"fix:php:cs": "./.build/bin/php-cs-fixer fix --config ./build/php-cs-fixer.php"
},
"scripts-descriptions": {
"ci": "Runs all dynamic and static code checks.",
Expand Down
2 changes: 0 additions & 2 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\AfterFeatureScope;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
Expand All @@ -13,7 +12,6 @@

class FeatureContext implements Context
{

private $interaction;

private $fileSystem;
Expand Down
2 changes: 1 addition & 1 deletion spec/Companienv/IO/InputOutputInteractionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class InputOutputInteractionSpec extends ObjectBehavior
{
function let(InputInterface $input, OutputInterface $output)
public function let(InputInterface $input, OutputInterface $output): void
{
$this->beConstructedWith($input, $output);
}
Expand Down
29 changes: 18 additions & 11 deletions src/Companienv/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,34 @@
use Companienv\Extension\OnlyIf;
use Companienv\Extension\RsaKeys;
use Companienv\Extension\SslCertificate;
use Companienv\IO\FileSystem\NativePhpFileSystem;
use Companienv\Interaction\AskVariableValues;
use Companienv\IO\FileSystem\NativePhpFileSystem;
use Companienv\IO\InputOutputInteraction;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Application as ConsoleApplication;
use Symfony\Component\Console\Output\OutputInterface;

class Application extends ConsoleApplication
{
private $rootDirectory;
private string $rootDirectory;

/** @var Extension[] */
private $extensions = [];
private array $extensions;

/**
* @param string $rootDirectory
* @param Extension[]|null $extensions
*/
public function __construct(string $rootDirectory, array $extensions = null)
{
parent::__construct('Companienv', '0.0.x-dev');

$this->rootDirectory = $rootDirectory;
$this->extensions = $extensions !== null ? $extensions : self::defaultExtensions();
$this->extensions = $extensions ?? self::defaultExtensions();

$this->add(new class([$this, 'companion'], 'companion') extends Command {
$this->add(new class ([$this, 'companion'], 'companion') extends Command {
private $callable;

public function __construct(callable $callable, $name)
Expand All @@ -54,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->setDefaultCommand('companion', true);
}

public function companion(InputInterface $input, OutputInterface $output)
public function companion(InputInterface $input, OutputInterface $output): int
{
$companion = new Companion(
new NativePhpFileSystem($this->rootDirectory),
Expand All @@ -67,12 +71,15 @@ public function companion(InputInterface $input, OutputInterface $output)
return 0;
}

public function registerExtension(Extension $extension)
public function registerExtension(Extension $extension): void
{
array_unshift($this->extensions, $extension);
}

public static function defaultExtensions()
/**
* @return Extension[]
*/
public static function defaultExtensions(): array
{
return [
new OnlyIf(),
Expand All @@ -83,12 +90,12 @@ public static function defaultExtensions()
];
}

public static function defaultFile()
public static function defaultFile(): string
{
return '.env';
}

public static function defaultDistributionFile()
public static function defaultDistributionFile(): string
{
return '.env.dist';
}
Expand Down
41 changes: 24 additions & 17 deletions src/Companienv/Companion.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Companienv;

use Companienv\DotEnv\Block;
use Companienv\DotEnv\File;
use Companienv\DotEnv\MissingVariable;
use Companienv\DotEnv\Parser;
use Companienv\IO\FileSystem\FileSystem;
Expand All @@ -14,11 +15,11 @@

class Companion
{
private $fileSystem;
private $interaction;
private $reference;
private $extension;
private $envFileName;
private FileSystem $fileSystem;
private Interaction $interaction;
private File $reference;
private Extension $extension;
private string $envFileName;

public function __construct(FileSystem $fileSystem, Interaction $interaction, Extension $extension, string $envFileName = '.env', string $distFileName = '.env.dist')
{
Expand All @@ -29,7 +30,7 @@ public function __construct(FileSystem $fileSystem, Interaction $interaction, Ex
$this->envFileName = $envFileName;
}

public function fillGaps()
public function fillGaps(): void
{
$missingVariables = $this->getVariablesRequiringValues();
if (count($missingVariables) === 0) {
Expand All @@ -45,7 +46,7 @@ public function fillGaps()
$this->interaction->writeln([
'',
'<comment>I let you think about it then. Re-run the command to get started again.</comment>',
''
'',
]);

return;
Expand All @@ -56,22 +57,25 @@ public function fillGaps()
}
}

private function fillBlockGaps(Block $block, array $missingVariables)
/**
* @param MissingVariable[] $missingVariables
*/
private function fillBlockGaps(Block $block, array $missingVariables): void
{
$variablesInBlock = $block->getVariablesInBlock($missingVariables);
if (count($variablesInBlock) == 0) {
if (count($variablesInBlock) === 0) {
return;
}

if (!empty($title = $block->getTitle())) {
if ($block->getTitle() !== '') {
$this->interaction->writeln([
'',
'<info>' . $block->getTitle() . '</info>',
]);
}

if (!empty($description = $block->getDescription())) {
$this->interaction->writeln($description);
if ($block->getDescription() !== '') {
$this->interaction->writeln($block->getDescription());
}

$this->interaction->writeln('');
Expand All @@ -83,7 +87,7 @@ private function fillBlockGaps(Block $block, array $missingVariables)
}
}

private function writeVariable(string $name, string $value)
private function writeVariable(string $name, ?string $value = null): void
{
if (!$this->fileSystem->exists($this->envFileName)) {
$this->fileSystem->write($this->envFileName, '');
Expand Down Expand Up @@ -126,7 +130,7 @@ private function writeVariable(string $name, string $value)
/**
* @return MissingVariable[]
*/
private function getVariablesRequiringValues()
private function getVariablesRequiringValues(): array
{
$variablesInFile = $this->getDefinedVariablesHash();
$missingVariables = [];
Expand All @@ -144,7 +148,10 @@ private function getVariablesRequiringValues()
return $missingVariables;
}

public function getDefinedVariablesHash()
/**
* @return array<string, mixed>
*/
public function getDefinedVariablesHash(): array
{
$variablesInFile = [];
if ($this->fileSystem->exists($this->envFileName)) {
Expand All @@ -155,12 +162,12 @@ public function getDefinedVariablesHash()
return $variablesInFile;
}

public function askConfirmation(string $question) : bool
public function askConfirmation(string $question): bool
{
return $this->interaction->askConfirmation($question);
}

public function ask(string $question, string $default = null) : string
public function ask(string $question, string $default = ''): string
{
return $this->interaction->ask($question, $default);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Companienv/Composer/InteractionViaComposer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class InteractionViaComposer implements Interaction
{
private $io;
private IOInterface $io;

public function __construct(IOInterface $io)
{
Expand All @@ -25,7 +25,7 @@ public function askConfirmation(string $question): bool
return $this->io->askConfirmation($question);
}

public function ask(string $question, string $default = null): string
public function ask(string $question, string $default = ''): string
{
if (!$this->io->isInteractive()) {
$this->writeln(sprintf('Automatically returned "%s" in non-interactive mode', $default));
Expand All @@ -36,8 +36,8 @@ public function ask(string $question, string $default = null): string
return $this->io->ask($question, $default);
}

public function writeln($messageOrMessages)
public function writeln(array|string $messageOrMessages): void
{
return $this->io->write($messageOrMessages);
$this->io->write($messageOrMessages);
}
}
4 changes: 2 additions & 2 deletions src/Companienv/Composer/ScriptHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class ScriptHandler
{
public static function run(Event $event)
public static function run(Event $event): void
{
$extras = $event->getComposer()->getPackage()->getExtra();

Expand All @@ -20,7 +20,7 @@ public static function run(Event $event)
$configs = [['file' => Application::defaultFile(), 'dist-file' => Application::defaultDistributionFile()]];
}

$directory = getcwd();
$directory = (string)getcwd();
foreach ($configs as $config) {
$companion = new Companion(
new NativePhpFileSystem($directory),
Expand Down
Loading

0 comments on commit 0208169

Please sign in to comment.