Skip to content

Commit

Permalink
Merge pull request #400 from doctrine/cleanup-code
Browse files Browse the repository at this point in the history
cleanup code
  • Loading branch information
dbu authored Apr 3, 2024
2 parents c338d86 + 68b2cd0 commit 3f29006
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 60 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"symfony/console": "< 4"
},
"require-dev": {
"ext-libxml": "*",
"doctrine/doctrine-bundle": "^2.0.3",
"doctrine/phpcr-odm": "2.x-dev",
"doctrine/orm": "^2.0 || ^3.0",
Expand Down
5 changes: 2 additions & 3 deletions src/Command/PhpcrShellCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// If no arguments supplied, launch the shell with the embedded application
if ($launchShell) {
$shell = PhpcrShell::createEmbeddedShell($session);
$exitCode = $shell->run();
PhpcrShell::createEmbeddedShell($session)->run();

return $exitCode;
return 0;
}

// else try and run the command using the given input
Expand Down
5 changes: 1 addition & 4 deletions src/DataCollector/StopWatchLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
*/
final class StopWatchLogger implements LoggerInterface
{
private ?Stopwatch $stopwatch;

public function __construct(?Stopwatch $stopwatch = null)
public function __construct(private ?Stopwatch $stopwatch = null)
{
$this->stopwatch = $stopwatch;
}

public function startCall($method, ?array $params = null, ?array $env = null): void
Expand Down
6 changes: 1 addition & 5 deletions src/DataFixtures/PHPCRExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@
*/
final class PHPCRExecutor extends BasePHPCRExecutor
{
private ?InitializerManager $initializerManager;

public function __construct(
DocumentManagerInterface $dm,
?PHPCRPurger $purger = null,
?InitializerManager $initializerManager = null
private ?InitializerManager $initializerManager = null
) {
parent::__construct($dm, $purger);

$this->initializerManager = $initializerManager;
}

public function purge(): void
Expand Down
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ private function getOdmDocumentManagersNode(): NodeDefinition
return $root;
}

private function getOdmCacheDriverNode($name): NodeDefinition
private function getOdmCacheDriverNode(string $name): NodeDefinition
{
$root = (new TreeBuilder($name))->getRootNode();

Expand Down
31 changes: 11 additions & 20 deletions src/DependencyInjection/DoctrinePHPCRExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,25 @@
*/
final class DoctrinePHPCRExtension extends AbstractDoctrineExtension
{
/**
* @var string
*/
private $defaultSession;
private string $defaultSession;

/**
* @var string[]
*/
private $sessions = [];
private array $sessions = [];

/**
* @var XmlFileLoader
*/
private $loader;
private XmlFileLoader $loader;

/**
* @var bool
*/
private $disableProxyWarmer = false;
private bool $disableProxyWarmer = false;

/**
* Whether the schema listener service has been loaded already.
*
* This is done the first time a session with jackalope-doctrine-dbal is encountered.
*/
private $dbalSchemaListenerLoaded = false;
private bool $dbalSchemaListenerLoaded = false;

public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$processor = new Processor();
$configuration = new Configuration();
Expand Down Expand Up @@ -107,10 +98,10 @@ public function load(array $configs, ContainerBuilder $container)
$container->removeDefinition('doctrine_phpcr.odm.proxy_cache_warmer');
}
}
$this->loadTypeGuess($config, $container);
$this->loadTypeGuess($container);
}

private function loadTypeGuess($config, ContainerBuilder $container): void
private function loadTypeGuess(ContainerBuilder $container): void
{
$types = [];

Expand All @@ -122,7 +113,7 @@ private function loadTypeGuess($config, ContainerBuilder $container): void
$container->setParameter('doctrine_phpcr.form.type_guess', $types);
}

private function sessionLoad($config, ContainerBuilder $container): void
private function sessionLoad(array $config, ContainerBuilder $container): void
{
$sessions = $loaded = [];
foreach ($config['sessions'] as $name => $session) {
Expand Down Expand Up @@ -170,7 +161,7 @@ private function sessionLoad($config, ContainerBuilder $container): void
$container->setAlias(SessionInterface::class, new Alias($sessions[$config['default_session']], true));
}

private function loadJackalopeSession(array $session, ContainerBuilder $container, $type, $admin = false): void
private function loadJackalopeSession(array $session, ContainerBuilder $container, string $type, bool|string $admin = false): void
{
$serviceNamePrefix = $admin ? '.admin' : '';
$backendParameters = [];
Expand Down Expand Up @@ -598,7 +589,7 @@ protected function getMappingResourceExtension(): string
return 'phpcr';
}

public function getNamespace()
public function getNamespace(): string
{
return 'http://doctrine-project.org/schema/symfony-dic/odm/phpcr';
}
Expand Down
11 changes: 3 additions & 8 deletions src/EventListener/JackalopeDoctrineDbalSchemaListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
*/
class JackalopeDoctrineDbalSchemaListener
{
/**
* @var RepositorySchema
*/
private $schema;

public function __construct(RepositorySchema $schema)
{
$this->schema = $schema;
public function __construct(
private RepositorySchema $schema
) {
}

public function postGenerateSchema(GenerateSchemaEventArgs $args): void
Expand Down
9 changes: 8 additions & 1 deletion src/Form/Type/DocumentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@
namespace Doctrine\Bundle\PHPCRBundle\Form\Type;

use Doctrine\Bundle\PHPCRBundle\Form\ChoiceList\PhpcrOdmQueryBuilderLoader;
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
use Doctrine\Persistence\ObjectManager;
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface;
use Symfony\Bridge\Doctrine\Form\Type\DoctrineType;

class DocumentType extends DoctrineType
{
public function getLoader($manager, $queryBuilder, $class): EntityLoaderInterface
public function getLoader(ObjectManager $manager, object $queryBuilder, string $class): EntityLoaderInterface
{
if (!$manager instanceof DocumentManagerInterface || !($queryBuilder instanceof QueryBuilder || $queryBuilder instanceof \Closure)) {
throw new \InvalidArgumentException('Expected a '.DocumentManagerInterface::class.' and a closure or '.QueryBuilder::class.', got '.get_class($manager).' and '.get_class($queryBuilder));
}

return new PhpcrOdmQueryBuilderLoader(
$queryBuilder,
$manager,
Expand Down
21 changes: 7 additions & 14 deletions src/Form/Type/PHPCRReferenceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,14 @@ public function __construct(?SessionInterface $session = null)

public function buildForm(FormBuilderInterface $builder, array $options): void
{
switch (strtolower($options['transformer_type'])) {
case 'uuid':
$transformer = new PHPCRNodeToUuidTransformer($this->session);

break;
case 'path':
$transformer = new PHPCRNodeToPathTransformer($this->session);

break;
default:
throw new InvalidConfigurationException(sprintf('
$transformer = match (strtolower($options['transformer_type'])) {
'uuid' => new PHPCRNodeToUuidTransformer($this->session),
'path' => new PHPCRNodeToPathTransformer($this->session),
default => throw new InvalidConfigurationException(sprintf('
The option "transformer_type" must be either "uuid" or "path", "%s" given',
$options['transformer_type']
));
}
$options['transformer_type']
)),
};

$builder->addModelTransformer($transformer);
}
Expand Down
3 changes: 1 addition & 2 deletions src/OptionalCommand/ODM/LoadFixtureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$paths = \is_array($dirOrFile) ? $dirOrFile : [$dirOrFile];
} else {
$kernel = $application->getKernel();
$projectDir = method_exists($kernel, 'getRootDir') ? $kernel->getRootDir() : $kernel->getProjectDir().'/src';
$paths = [$projectDir.'/DataFixtures/PHPCR'];
$paths = [$kernel->getProjectDir().'/src/DataFixtures/PHPCR'];
foreach ($kernel->getBundles() as $bundle) {
$paths[] = $bundle->getPath().'/DataFixtures/PHPCR';
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Functional/Form/PHPCRTypeGuesserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ private function renderForm(FormBuilderInterface $formBuilder): void
* Assert that the form element has an inner type of type $typeClass and
* the specified options with their values.
*
* @param array $options keys are option names, values the expected option values
* @param array $options keys are option names, values the expected option values
* @param class-string $typeClass
*/
private function assertFormType(FormBuilderInterface $element, string $typeClass, array $options): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function getConfiguration(): ConfigurationInterface
*/
public function testSupports(array $expectedConfiguration, array $files): void
{
$formats = array_map(function ($path) {
$formats = array_map(static function ($path) {
return __DIR__.'/../../Fixtures/fixtures/'.$path;
}, $files);

Expand Down

0 comments on commit 3f29006

Please sign in to comment.