Skip to content

Commit

Permalink
Merge pull request #189 from loic425/features/psalm-level-6
Browse files Browse the repository at this point in the history
Psalm level 6
  • Loading branch information
loic425 committed May 22, 2019
2 parents 2044f42 + 313895c commit a354187
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 290 deletions.
3 changes: 2 additions & 1 deletion config/services/command.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ services:

App\Command\Installer\InstallAssetsCommand:
arguments:
$publicDir: '%kernel.project_dir%/public'
$environment: '%kernel.environment%'

App\Command\Installer\InstallSampleDataCommand:
arguments:
$projectDir: '%kernel.project_dir%'
$publicDir: '%kernel.project_dir%/public'
$environment: '%kernel.environment%'
23 changes: 0 additions & 23 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,5 @@
<UndefinedThisPropertyAssignment errorLevel="info" />
<UndefinedInterfaceMethod errorLevel="info" />

<!-- level 7 issues - even worse -->

<UndefinedThisPropertyAssignment errorLevel="info" />
<UndefinedPropertyAssignment errorLevel="info" />
<UndefinedThisPropertyFetch errorLevel="info" />
<UndefinedPropertyFetch errorLevel="info" />

<InvalidReturnStatement errorLevel="info" />
<InvalidReturnType errorLevel="info" />
<InvalidArgument errorLevel="info" />
<InvalidPropertyAssignmentValue errorLevel="info" />
<InvalidArrayOffset errorLevel="info" />
<InvalidArrayAssignment errorLevel="info" />
<InvalidArrayAccess errorLevel="info" />
<InvalidClone errorLevel="info" />

<!-- level 8 issues - some fatal errors in PHP -->

<ReservedWord errorLevel="info" />
<MethodSignatureMismatch errorLevel="info" />
<OverriddenMethodAccess errorLevel="info" />
<InaccessibleProperty errorLevel="info" />

</issueHandlers>
</psalm>
Original file line number Diff line number Diff line change
Expand Up @@ -9,47 +9,40 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Command\Helper;

use App\Command\Installer\CommandExecutor;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;

trait RunCommands
final class CommandsRunner
{
use CreateProgressBar;

/**
* @var CommandExecutor
*/
private $commandExecutor;

/**
* @var EntityManagerInterface
*/
/** @var EntityManagerInterface */
private $entityManager;

/**
* @param CommandExecutor $commandExecutor
* @param EntityManagerInterface $entityManager
*/
public function __construct(CommandExecutor $commandExecutor, EntityManagerInterface $entityManager)
{
$this->commandExecutor = $commandExecutor;
/** @var ProgressBarCreator */
private $progressBarCreator;

public function __construct(
EntityManagerInterface $entityManager,
ProgressBarCreator $progressBarCreator
) {
$this->entityManager = $entityManager;
$this->progressBarCreator = $progressBarCreator;
}

/**
* @param array $commands
* @param OutputInterface $output
* @param bool $displayProgress
*
* @throws \Exception
*/
private function runCommands(array $commands, OutputInterface $output, bool $displayProgress = true): void
public function run(array $commands, InputInterface $input, OutputInterface $output, Application $application, bool $displayProgress = true): void
{
$progress = $this->createProgressBar($displayProgress ? $output : new NullOutput(), count($commands));
$progress = $this->progressBarCreator->create($displayProgress ? $output : new NullOutput(), count($commands));
$commandExecutor = new CommandExecutor($input, $output, $application);

foreach ($commands as $key => $value) {
if (is_string($key)) {
Expand All @@ -60,7 +53,7 @@ private function runCommands(array $commands, OutputInterface $output, bool $dis
$parameters = [];
}

$this->commandExecutor->runCommand($command, $parameters);
$commandExecutor->runCommand($command, $parameters);

// PDO does not always close the connection after Doctrine commands.
// See https://github.com/symfony/symfony/issues/11750.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,27 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Command\Helper;

use App\Installer\Checker\CommandDirectoryChecker;
use Symfony\Component\Console\Output\OutputInterface;

trait EnsureDirectoryExistsAndIsWritable
class DirectoryChecker
{
/**
* @var CommandDirectoryChecker
*/
/** @var CommandDirectoryChecker */
private $commandDirectoryChecker;

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

/**
* @param CommandDirectoryChecker $commandDirectoryChecker
* @param string $commandName
*/
public function __construct(CommandDirectoryChecker $commandDirectoryChecker, string $commandName)
public function __construct(CommandDirectoryChecker $commandDirectoryChecker)
{
$this->commandDirectoryChecker = $commandDirectoryChecker;
$this->commandName = $commandName;
}

/**
* @param string $directory
* @param OutputInterface $output
*/
private function ensureDirectoryExistsAndIsWritable($directory, OutputInterface $output): void
public function ensureDirectoryExistsAndIsWritable(string $directory, OutputInterface $output, string $commandName): void
{
$checker = $this->commandDirectoryChecker;
$checker->setCommandName($this->commandName);
$checker->setCommandName($commandName);

$checker->ensureDirectoryExists($directory, $output);
$checker->ensureDirectoryIsWritable($directory, $output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,16 @@
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Command\Helper;

use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Output\OutputInterface;

trait CreateProgressBar
final class ProgressBarCreator
{
/**
* @param OutputInterface $output
* @param int $length
*
* @return ProgressBar
*/
private function createProgressBar(OutputInterface $output, $length = 10)
public function create(OutputInterface $output, int $length = 10): ProgressBar
{
$progress = new ProgressBar($output);
$progress->setBarCharacter('<info>░</info>');
Expand Down
34 changes: 0 additions & 34 deletions src/Command/Helper/RenderTable.php

This file was deleted.

67 changes: 24 additions & 43 deletions src/Command/Installer/InstallAssetsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,45 @@

namespace App\Command\Installer;

use App\Command\Helper\EnsureDirectoryExistsAndIsWritable;
use App\Command\Helper\RunCommands;
use App\Installer\Checker\CommandDirectoryChecker;
use Doctrine\ORM\EntityManagerInterface;
use App\Command\Helper\CommandsRunner;
use App\Command\Helper\DirectoryChecker;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class InstallAssetsCommand extends Command
{
const WEB_ASSETS_DIRECTORY = 'public/assets/';
const WEB_BUNDLES_DIRECTORY = 'public/bundles/';

use EnsureDirectoryExistsAndIsWritable {
EnsureDirectoryExistsAndIsWritable::__construct as private initializeEnsureDirectoryExistsAndIsWritable;
}
use RunCommands {
RunCommands::__construct as private initializeRunCommands;
}

/**
* @var CommandDirectoryChecker
* @var DirectoryChecker
*/
private $commandDirectoryChecker;

private $directoryChecker;
/**
* @var EntityManagerInterface
* @var CommandsRunner
*/
private $entityManager;

private $commandsRunner;
/**
* @var string
*/
private $environment;

private $publicDir;
/**
* @param CommandDirectoryChecker $commandDirectoryChecker
* @param EntityManagerInterface $entityManager
* @param string $environment
* @var string
*/
public function __construct(CommandDirectoryChecker $commandDirectoryChecker, EntityManagerInterface $entityManager, string $environment)
{
$this->commandDirectoryChecker = $commandDirectoryChecker;
$this->entityManager = $entityManager;
private $environment;

public function __construct(
DirectoryChecker $directoryChecker,
CommandsRunner $commandsRunner,
string $publicDir,
string $environment
) {
$this->directoryChecker = $directoryChecker;
$this->commandsRunner = $commandsRunner;
$this->publicDir = $publicDir;
$this->environment = $environment;

parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
$commandExecutor = new CommandExecutor($input, $output, $this->getApplication());

$this->initializeEnsureDirectoryExistsAndIsWritable($this->commandDirectoryChecker, $this->getName());
$this->initializeRunCommands($commandExecutor, $this->entityManager);
}

/**
* {@inheritdoc}
*/
Expand All @@ -79,14 +58,16 @@ protected function configure()

/**
* {@inheritdoc}
*
* @throws \Exception
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('Installing AppName assets for environment <info>%s</info>.', $this->environment));

try {
$this->ensureDirectoryExistsAndIsWritable(self::WEB_ASSETS_DIRECTORY, $output);
$this->ensureDirectoryExistsAndIsWritable(self::WEB_BUNDLES_DIRECTORY, $output);
$this->directoryChecker->ensureDirectoryExistsAndIsWritable($this->publicDir.'/assets/', $output, $this->getName());
$this->directoryChecker->ensureDirectoryExistsAndIsWritable($this->publicDir.'/bundles/', $output, $this->getName());
} catch (\RuntimeException $exception) {
return 1;
}
Expand All @@ -95,6 +76,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
'assets:install',
];

$this->runCommands($commands, $output);
$this->commandsRunner->run($commands, $input, $output, $this->getApplication());
}
}

0 comments on commit a354187

Please sign in to comment.