From fe58f095fac06a084b468269c48d6984f52b1e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=20Waterb=C3=B6hr?= Date: Wed, 27 Sep 2023 09:32:47 +0200 Subject: [PATCH] Add Symfony 6 support --- Command/AbstractCommand.php | 42 ++++++----- Command/BuildCommand.php | 6 +- Command/BundleTrait.php | 20 ++---- Command/DatabaseCreateCommand.php | 12 ++-- Command/DatabaseDropCommand.php | 16 +++-- Command/DatabaseReverseCommand.php | 7 +- Command/FixturesDumpCommand.php | 12 ++-- Command/FixturesLoadCommand.php | 37 +++++----- Command/FormGenerateCommand.php | 21 +++--- Command/FormattingHelpers.php | 10 +-- Command/GraphvizGenerateCommand.php | 7 +- Command/MigrationDiffCommand.php | 7 +- Command/MigrationDownCommand.php | 7 +- Command/MigrationMigrateCommand.php | 7 +- Command/MigrationStatusCommand.php | 7 +- Command/MigrationUpCommand.php | 7 +- Command/ModelBuildCommand.php | 7 +- Command/SqlBuildCommand.php | 7 +- Command/SqlInsertCommand.php | 11 +-- Command/TableDropCommand.php | 13 ++-- Command/WrappedCommand.php | 17 ++--- Controller/PanelController.php | 21 +++--- DataCollector/PropelDataCollector.php | 16 ++--- DataFixtures/AbstractDataHandler.php | 47 ++++-------- DataFixtures/Dumper/AbstractDataDumper.php | 17 +++-- DataFixtures/Dumper/DataDumperInterface.php | 2 +- DataFixtures/Dumper/YamlDataDumper.php | 2 +- DataFixtures/Loader/AbstractDataLoader.php | 28 ++++---- DataFixtures/Loader/DataLoaderInterface.php | 2 +- DataFixtures/Loader/XmlDataLoader.php | 4 +- DataFixtures/Loader/YamlDataLoader.php | 9 +-- DependencyInjection/Configuration.php | 4 +- DependencyInjection/PropelExtension.php | 8 +-- .../Security/UserProvider/PropelFactory.php | 19 +++-- Form/BaseAbstractType.php | 72 ------------------- Form/ChoiceList/PropelChoiceLoader.php | 14 ++-- .../CollectionToArrayTransformer.php | 2 +- .../TranslationCollectionFormListener.php | 4 +- .../EventListener/TranslationFormListener.php | 4 +- Form/PropelExtension.php | 6 +- Form/Type/ModelType.php | 12 ++-- Form/Type/TranslationCollectionType.php | 4 +- Form/Type/TranslationType.php | 8 +-- Form/TypeGuesser.php | 14 ++-- Logger/PropelLogger.php | 29 ++------ .../ParamConverter/PropelParamConverter.php | 4 +- Resources/config/console.xml | 6 +- Resources/config/services.yaml | 2 + Security/User/PropelUserProvider.php | 15 ++-- Service/SchemaLocator.php | 15 ++-- Tests/Fixtures/Acl/ArrayCache.php | 60 ---------------- Validator/Constraints/UniqueObject.php | 10 +-- .../Constraints/UniqueObjectValidator.php | 2 +- composer.json | 14 ++-- 54 files changed, 307 insertions(+), 449 deletions(-) delete mode 100644 Form/BaseAbstractType.php delete mode 100644 Tests/Fixtures/Acl/ArrayCache.php diff --git a/Command/AbstractCommand.php b/Command/AbstractCommand.php index c7b78fef..7e44f631 100644 --- a/Command/AbstractCommand.php +++ b/Command/AbstractCommand.php @@ -10,12 +10,13 @@ namespace Propel\Bundle\PropelBundle\Command; +use Propel\Bundle\PropelBundle\Service\SchemaLocator; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Psr\Container\ContainerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\HttpKernel\Bundle\Bundle; use Symfony\Component\HttpKernel\Bundle\BundleInterface; @@ -48,7 +49,7 @@ public function getContainer(): ContainerInterface /** * {@inheritdoc} */ - protected function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output): void { $this->input = $input; $this->output = $output; @@ -68,7 +69,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) /** * Create all the files needed by Propel's commands. */ - protected function setupBuildTimeFiles() + protected function setupBuildTimeFiles(): void { $fs = new Filesystem(); $fs->mkdir($this->cacheDir); @@ -85,7 +86,7 @@ protected function setupBuildTimeFiles() * @param string $cacheDir The directory in which the schemas will * be copied. */ - protected function copySchemas(KernelInterface $kernel, $cacheDir) + protected function copySchemas(KernelInterface $kernel, string $cacheDir): void { $filesystem = new Filesystem(); @@ -171,7 +172,7 @@ protected function copySchemas(KernelInterface $kernel, $cacheDir) * * @return array A list of schemas. */ - protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null) + protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bundle = null): array { if (null !== $bundle) { return $this->getSchemaLocator()->locateFromBundle($bundle); @@ -190,7 +191,7 @@ protected function getFinalSchemas(KernelInterface $kernel, BundleInterface $bun * * @return int The command return code. */ - protected function runCommand(Command $command, array $parameters, InputInterface $input, OutputInterface $output) + protected function runCommand(Command $command, array $parameters, InputInterface $input, OutputInterface $output): int { // add the command's name to the parameters array_unshift($parameters, $this->getName()); @@ -227,7 +228,7 @@ protected function runCommand(Command $command, array $parameters, InputInterfac * * @param string $file Should be 'propel.json'. */ - protected function createPropelConfigurationFile($file) + protected function createPropelConfigurationFile(string $file): void { $propelConfig = $this->getContainer()->getParameter('propel.configuration'); @@ -249,7 +250,7 @@ protected function createPropelConfigurationFile($file) * * @return array */ - protected function getConnections(array $connections) + protected function getConnections(array $connections): array { $dsnList = array(); foreach ($connections as $connection) { @@ -266,7 +267,7 @@ protected function getConnections(array $connections) * * @return array The connection data. */ - protected function getConnectionData($name) + protected function getConnectionData(string $name): array { $knownConnections = $this->getContainer()->getParameter('propel.configuration'); if (!isset($knownConnections['database']['connections'][$name])) { @@ -283,7 +284,7 @@ protected function getConnectionData($name) * * @return string The DSN. */ - protected function getDsn($connectionName) + protected function getDsn(string $connectionName): string { $connection = $this->getConnectionData($connectionName); // Add user and password to dsn string @@ -298,10 +299,7 @@ protected function getDsn($connectionName) return implode(';', $dsn); } - /** - * @return \Symfony\Component\Config\FileLocatorInterface - */ - protected function getSchemaLocator() + protected function getSchemaLocator(): SchemaLocator { return $this->getContainer()->get('propel.schema_locator'); } @@ -311,7 +309,7 @@ protected function getSchemaLocator() * * @return string */ - protected function getPackageFromApp($namespace) + protected function getPackageFromApp(string $namespace): string { if ('\\' === $namespace[0]) { $namespace = substr($namespace, 1); @@ -330,7 +328,7 @@ protected function getPackageFromApp($namespace) * * @return string */ - protected function getPackageFromBundle(Bundle $bundle, $namespace) + protected function getPackageFromBundle(Bundle $bundle, string $namespace): string { //find relative path from namespace to bundle->getNamespace() $baseNamespace = (new \ReflectionClass($bundle))->getNamespaceName(); @@ -365,7 +363,7 @@ protected function getPackageFromBundle(Bundle $bundle, $namespace) * * @return string The current Propel cache directory. */ - protected function getCacheDir() + protected function getCacheDir(): string { return $this->cacheDir; } @@ -378,7 +376,7 @@ protected function getCacheDir() * * @return string relative path without trailing slash */ - public static function getRelativePath($from, $to) + public static function getRelativePath(string $from, string $to): string { $from = '/' . trim($from, '/'); $to = '/' . trim($to, '/'); @@ -402,7 +400,7 @@ public static function getRelativePath($from, $to) * @param string $dsn A DSN * @return string The database name extracted from the given DSN */ - protected function parseDbName($dsn) + protected function parseDbName(string $dsn): ?string { preg_match('#(dbname|Database)=([a-zA-Z0-9\_]+)#', $dsn, $matches); @@ -419,7 +417,7 @@ protected function parseDbName($dsn) * * @return string */ - protected function getMigrationsTable() + protected function getMigrationsTable(): string { $config = $this->getContainer()->getParameter('propel.configuration'); @@ -431,7 +429,7 @@ protected function getMigrationsTable() * * @return string */ - protected function getDefaultConnection() + protected function getDefaultConnection(): string { $config = $this->getContainer()->getParameter('propel.configuration'); @@ -443,7 +441,7 @@ protected function getDefaultConnection() * * @return string The platform class name. */ - protected function getPlatform() + protected function getPlatform(): ?string { $config = $this->getContainer()->getParameter('propel.configuration'); return $config['generator']['platformClass']; diff --git a/Command/BuildCommand.php b/Command/BuildCommand.php index 26fd6963..0620ba90 100644 --- a/Command/BuildCommand.php +++ b/Command/BuildCommand.php @@ -24,7 +24,7 @@ class BuildCommand extends Command /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this ->setName('propel:build') @@ -44,7 +44,7 @@ protected function configure() * * @throws \InvalidArgumentException When the target directory does not exist */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { if (!$input->getOption('sql')) { $in = new ArrayInput(array( @@ -76,5 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $cmd = $this->getApplication()->find('propel:sql:insert'); $cmd->run($in, $output); } + + return 0; } } diff --git a/Command/BundleTrait.php b/Command/BundleTrait.php index dd0ec230..b35e8229 100644 --- a/Command/BundleTrait.php +++ b/Command/BundleTrait.php @@ -21,27 +21,17 @@ */ trait BundleTrait { - /** - * @return ContainerInterface - */ - protected abstract function getContainer(); + protected abstract function getContainer(): ContainerInterface; /** * Returns the selected bundle. * If no bundle argument is set, the user will get ask for it. - * - * @param InputInterface $input - * @param OutputInterface $output - * - * @return BundleInterface */ - protected function getBundle(InputInterface $input, OutputInterface $output) + protected function getBundle(InputInterface $input, OutputInterface $output): BundleInterface { - $kernel = $this - ->getContainer() - ->get('kernel'); + $kernel = $this->getContainer()->get('kernel'); - if ($input->hasArgument('bundle') && '@' === substr($input->getArgument('bundle'), 0, 1)) { + if ($input->hasArgument('bundle') && str_starts_with($input->getArgument('bundle'), '@')) { return $kernel->getBundle(substr($input->getArgument('bundle'), 1)); } @@ -62,4 +52,4 @@ protected function getBundle(InputInterface $input, OutputInterface $output) return $kernel->getBundle($bundleName); } -} \ No newline at end of file +} diff --git a/Command/DatabaseCreateCommand.php b/Command/DatabaseCreateCommand.php index 45563e1e..19619137 100644 --- a/Command/DatabaseCreateCommand.php +++ b/Command/DatabaseCreateCommand.php @@ -12,6 +12,7 @@ use Propel\Runtime\Connection\ConnectionManagerSingle; use Propel\Runtime\Propel; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; @@ -27,7 +28,7 @@ class DatabaseCreateCommand extends AbstractCommand /** * @see Command */ - protected function configure() + protected function configure(): void { $this ->setName('propel:database:create') @@ -42,14 +43,15 @@ protected function configure() * * @throws \InvalidArgumentException When the target directory does not exist */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $connectionName = $input->getOption('connection') ?: $this->getDefaultConnection(); $config = $this->getConnectionData($connectionName); $dbName = $this->parseDbName($config['dsn']); if (null === $dbName) { - return $output->writeln('No database name found.'); + $output->writeln('No database name found.'); + return 1; } else { $query = 'CREATE DATABASE '. $dbName .';'; } @@ -67,6 +69,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $statement->execute(); $output->writeln(sprintf('Database %s has been created.', $dbName)); + + return 0; } /** @@ -78,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output) * @param array $config A Propel connection configuration. * @return array */ - private function getTemporaryConfiguration($config) + private function getTemporaryConfiguration(array $config): array { $dbName = $this->parseDbName($config['dsn']); diff --git a/Command/DatabaseDropCommand.php b/Command/DatabaseDropCommand.php index 553fcbde..7d2788ed 100644 --- a/Command/DatabaseDropCommand.php +++ b/Command/DatabaseDropCommand.php @@ -11,6 +11,7 @@ namespace Propel\Bundle\PropelBundle\Command; use Propel\Runtime\Propel; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -27,7 +28,7 @@ class DatabaseDropCommand extends AbstractCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this ->setName('propel:database:drop') @@ -51,12 +52,12 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { if (!$input->getOption('force')) { $output->writeln('You have to use the "--force" option to drop the database.'); - return; + return 1; } if ('prod' === $this->getKernel()->getEnvironment()) { @@ -65,7 +66,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (false === $this->askConfirmation($input, $output, 'Are you sure ? (y/n) ', false)) { $output->writeln('Aborted, nice decision !'); - return -2; + return 1; } } @@ -74,7 +75,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $dbName = $this->parseDbName($config['dsn']); if (null === $dbName) { - return $output->writeln('No database name found.'); + $output->writeln('No database name found.'); + return 1; } else { $query = 'DROP DATABASE '. $dbName .';'; } @@ -93,6 +95,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $statement->execute(); $output->writeln(sprintf('Database %s has been dropped.', $dbName)); + + return 0; } /** @@ -104,7 +108,7 @@ protected function execute(InputInterface $input, OutputInterface $output) * @param array $config A Propel connection configuration. * @return array */ - private function getTemporaryConfiguration($config) + private function getTemporaryConfiguration(array $config): array { $dbName = $this->parseDbName($config['dsn']); diff --git a/Command/DatabaseReverseCommand.php b/Command/DatabaseReverseCommand.php index 1181eb97..0198b429 100644 --- a/Command/DatabaseReverseCommand.php +++ b/Command/DatabaseReverseCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -24,7 +25,7 @@ class DatabaseReverseCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -42,7 +43,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseDatabaseReverseCommand(); } @@ -50,7 +51,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { return array( '--output-dir' => $input->getOption('output-dir'), diff --git a/Command/FixturesDumpCommand.php b/Command/FixturesDumpCommand.php index 0259c5c0..22ea46be 100644 --- a/Command/FixturesDumpCommand.php +++ b/Command/FixturesDumpCommand.php @@ -10,9 +10,11 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Filesystem; /** @@ -26,12 +28,12 @@ class FixturesDumpCommand extends AbstractCommand * Default fixtures directory. * @var string */ - protected $defaultFixturesDir = 'app/propel/fixtures'; + protected string $defaultFixturesDir = 'app/propel/fixtures'; /** * @see Command */ - protected function configure() + protected function configure(): void { $this ->setName('propel:fixtures:dump') @@ -55,7 +57,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $fixtureDir = $input->getOption('dir') ?: $this->defaultFixturesDir; $path = realpath($this->getKernel()->getProjectDir() . '/') . '/' . $fixtureDir; @@ -67,7 +69,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $fs->mkdir($path); $this->writeNewDirectory($output, $path); } else { - throw new \IOException(sprintf('Unable to find the %s folder', $path)); + throw new IOException(sprintf('Unable to find the %s folder', $path)); } } @@ -78,6 +80,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->writeNewFile($output, $filename); - return true; + return 0; } } diff --git a/Command/FixturesLoadCommand.php b/Command/FixturesLoadCommand.php index f787b190..ac925ff4 100644 --- a/Command/FixturesLoadCommand.php +++ b/Command/FixturesLoadCommand.php @@ -10,6 +10,8 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Config\FileLocatorInterface; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; @@ -30,24 +32,24 @@ class FixturesLoadCommand extends AbstractCommand * Default fixtures directory. * @var string */ - private $defaultFixturesDir = 'app/propel/fixtures'; + private string $defaultFixturesDir = 'app/propel/fixtures'; /** * Absolute path for fixtures directory * @var string */ - private $absoluteFixturesPath = ''; + private string $absoluteFixturesPath = ''; /** * Filesystem for manipulating files * @var \Symfony\Component\Filesystem\Filesystem */ - private $filesystem = null; + private ? Filesystem $filesystem = null; /** * @see Command */ - protected function configure() + protected function configure(): void { $this ->setName('propel:fixtures:load') @@ -112,7 +114,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $this->filesystem = new Filesystem(); @@ -147,16 +149,18 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('No YML fixtures found.'); } } + + return 0; } /** * Load fixtures * - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output - * @param string $type If specified, only fixtures with the given type will be loaded (yml, xml). + * @param InputInterface $input + * @param OutputInterface $output + * @param string $type If specified, only fixtures with the given type will be loaded (yml, xml). */ - protected function loadFixtures(InputInterface $input, OutputInterface $output, $type = null) + protected function loadFixtures(InputInterface $input, OutputInterface $output, string $type = null) { if (null === $type) { return; @@ -191,7 +195,7 @@ protected function loadFixtures(InputInterface $input, OutputInterface $output, * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output */ - protected function loadSqlFixtures(InputInterface $input, OutputInterface $output) + protected function loadSqlFixtures(InputInterface $input, OutputInterface $output): int { $tmpdir = $this->getCacheDir(); $datas = $this->getFixtureFiles('sql'); @@ -230,7 +234,7 @@ protected function loadSqlFixtures(InputInterface $input, OutputInterface $outpu * * @param string $tmpdir The temporary directory path. */ - protected function prepareCache($tmpdir) + protected function prepareCache(string $tmpdir): void { // Recreate a propel directory in cache $this->filesystem->remove($tmpdir); @@ -240,7 +244,7 @@ protected function prepareCache($tmpdir) /** * Insert SQL */ - protected function insertSql($connectionName, InputInterface $input, OutputInterface $output) + protected function insertSql($connectionName, InputInterface $input, OutputInterface $output): bool { $parameters = array( '--connection' => array($connectionName), @@ -276,7 +280,7 @@ protected function insertSql($connectionName, InputInterface $input, OutputInter * * @return \Iterator An iterator through the files. */ - protected function getFixtureFiles($type = 'sql', $in = null) + protected function getFixtureFiles(string $type = 'sql', string $in = null) { $finder = new Finder(); $finder->sort(function ($a, $b) { @@ -306,15 +310,12 @@ protected function getFixtureFiles($type = 'sql', $in = null) * * @return String */ - protected function getFixturesPath(BundleInterface $bundle) + protected function getFixturesPath(BundleInterface $bundle): string { return $bundle->getPath() . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'fixtures'; } - /** - * @return \Symfony\Component\Config\FileLocatorInterface - */ - protected function getFileLocator() + protected function getFileLocator(): FileLocatorInterface { return $this->getContainer()->get('file_locator'); } diff --git a/Command/FormGenerateCommand.php b/Command/FormGenerateCommand.php index ef38dfea..13ace999 100644 --- a/Command/FormGenerateCommand.php +++ b/Command/FormGenerateCommand.php @@ -16,6 +16,7 @@ use Propel\Generator\Model\Table; use Propel\Generator\Manager\ModelManager; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -35,7 +36,7 @@ class FormGenerateCommand extends AbstractCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this ->setName('propel:form:generate') @@ -59,7 +60,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $kernel = $this->getKernel(); $models = $input->getArgument('models'); @@ -71,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $schemas = $this->getFinalSchemas($kernel, $bundle); if (!$schemas) { $output->writeln(sprintf('No *schemas.xml files found in bundle %s.', $bundle->getName())); - return; + return 1; } $manager = $this->getModelManager($input, $schemas); @@ -81,6 +82,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $this->createFormTypeFromDatabase($bundle, $database, $models, $output, $force); } } + + return 0; } /** @@ -92,7 +95,7 @@ protected function execute(InputInterface $input, OutputInterface $output) * @param OutputInterface $output An OutputInterface instance * @param boolean $force Override files if present. */ - protected function createFormTypeFromDatabase(BundleInterface $bundle, Database $database, $models, OutputInterface $output, $force = false) + protected function createFormTypeFromDatabase(BundleInterface $bundle, Database $database, $models, OutputInterface $output, bool $force = false): void { $dir = $this->createDirectory($bundle, $output); @@ -119,7 +122,7 @@ protected function createFormTypeFromDatabase(BundleInterface $bundle, Database * * @return string The path to the created directory. */ - protected function createDirectory(BundleInterface $bundle, OutputInterface $output) + protected function createDirectory(BundleInterface $bundle, OutputInterface $output): string { $fs = new Filesystem(); @@ -140,7 +143,7 @@ protected function createDirectory(BundleInterface $bundle, OutputInterface $out * @param boolean $force Is the write forced? * @param OutputInterface $output An OutputInterface instance. */ - protected function writeFormType(BundleInterface $bundle, Table $table, \SplFileInfo $file, $force, OutputInterface $output) + protected function writeFormType(BundleInterface $bundle, Table $table, \SplFileInfo $file, bool $force, OutputInterface $output): void { $formBuilder = new FormBuilder(); $formTypeContent = $formBuilder->buildFormType($bundle, $table, self::DEFAULT_FORM_TYPE_DIRECTORY); @@ -153,7 +156,7 @@ protected function writeFormType(BundleInterface $bundle, Table $table, \SplFile * @param \SplFileInfo $file * @return string */ - protected function getRelativeFileName(\SplFileInfo $file) + protected function getRelativeFileName(\SplFileInfo $file): string { return substr(str_replace(realpath($this->getContainer()->getParameter('kernel.project_dir') . '/'), '', $file), 1); } @@ -165,7 +168,7 @@ protected function getRelativeFileName(\SplFileInfo $file) * * @return GeneratorConfig */ - protected function getGeneratorConfig(InputInterface $input) + protected function getGeneratorConfig(InputInterface $input): GeneratorConfig { $generatorConfig = null; @@ -184,7 +187,7 @@ protected function getGeneratorConfig(InputInterface $input) * * @return ModelManager */ - protected function getModelManager(InputInterface $input, array $schemas) + protected function getModelManager(InputInterface $input, array $schemas): ModelManager { $schemaFiles = array(); foreach ($schemas as $data) { diff --git a/Command/FormattingHelpers.php b/Command/FormattingHelpers.php index fc4bea06..5fda4e58 100644 --- a/Command/FormattingHelpers.php +++ b/Command/FormattingHelpers.php @@ -27,7 +27,7 @@ trait FormattingHelpers * @param string $text A text message. * @param string $style A style to apply on the section. */ - protected function writeSection(OutputInterface $output, $text, $style = 'bg=blue;fg=white') + protected function writeSection(OutputInterface $output, $text, $style = 'bg=blue;fg=white'): void { $output->writeln(array( '', @@ -48,7 +48,7 @@ protected function writeSection(OutputInterface $output, $text, $style = 'bg=blu * * @return bool true if the user has confirmed, false otherwise */ - protected function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default = true) + protected function askConfirmation(InputInterface $input, OutputInterface $output, $question, $default = true): bool { $question = new Question($question); do { @@ -66,7 +66,7 @@ protected function askConfirmation(InputInterface $input, OutputInterface $outpu * @param OutputInterface $output The output. * @param string $filename The filename. */ - protected function writeNewFile(OutputInterface $output, $filename) + protected function writeNewFile(OutputInterface $output, string $filename): void { $output->writeln('>> File+ ' . $filename); } @@ -75,7 +75,7 @@ protected function writeNewFile(OutputInterface $output, $filename) * @param OutputInterface $output The output. * @param string $directory The directory. */ - protected function writeNewDirectory(OutputInterface $output, $directory) + protected function writeNewDirectory(OutputInterface $output, string $directory): void { $output->writeln('>> Dir+ ' . $directory); } @@ -87,7 +87,7 @@ protected function writeNewDirectory(OutputInterface $output, $directory) * @param string $taskName A task name. * @param Boolean $more Whether to add a 'more details' message or not. */ - protected function writeTaskError($output, $taskName, $more = true) + protected function writeTaskError(OutputInterface $output, string $taskName, bool $more = true): void { $moreText = $more ? ' To get more details, run the command with the "--verbose" option.' : ''; diff --git a/Command/GraphvizGenerateCommand.php b/Command/GraphvizGenerateCommand.php index 3ca0231b..429c89fb 100644 --- a/Command/GraphvizGenerateCommand.php +++ b/Command/GraphvizGenerateCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -23,7 +24,7 @@ class GraphvizGenerateCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -38,7 +39,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseGraphvizGenerateCommand(); } @@ -46,7 +47,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { return array( '--output-dir' => $input->getOption('output-dir'), diff --git a/Command/MigrationDiffCommand.php b/Command/MigrationDiffCommand.php index c8936d9b..12c3a423 100644 --- a/Command/MigrationDiffCommand.php +++ b/Command/MigrationDiffCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -23,7 +24,7 @@ class MigrationDiffCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -44,7 +45,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseMigrationCommand(); } @@ -52,7 +53,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $defaultOutputDir = $this->getContainer()->getParameter('propel.configuration')['paths']['migrationDir']; diff --git a/Command/MigrationDownCommand.php b/Command/MigrationDownCommand.php index 5cce8376..8ac13abf 100644 --- a/Command/MigrationDownCommand.php +++ b/Command/MigrationDownCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -23,7 +24,7 @@ class MigrationDownCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -42,7 +43,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseMigrationCommand(); } @@ -50,7 +51,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $defaultOutputDir = $this->getContainer()->getParameter('propel.configuration')['paths']['migrationDir']; diff --git a/Command/MigrationMigrateCommand.php b/Command/MigrationMigrateCommand.php index b890624d..6712dbfc 100644 --- a/Command/MigrationMigrateCommand.php +++ b/Command/MigrationMigrateCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -23,7 +24,7 @@ class MigrationMigrateCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -42,7 +43,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseMigrationCommand(); } @@ -50,7 +51,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $defaultOutputDir = $this->getContainer()->getParameter('propel.configuration')['paths']['migrationDir']; diff --git a/Command/MigrationStatusCommand.php b/Command/MigrationStatusCommand.php index 114b643f..0c4ebfa7 100644 --- a/Command/MigrationStatusCommand.php +++ b/Command/MigrationStatusCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -23,7 +24,7 @@ class MigrationStatusCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -40,7 +41,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseMigrationCommand(); } @@ -48,7 +49,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $defaultOutputDir = $this->getContainer()->getParameter('propel.configuration')['paths']['migrationDir']; diff --git a/Command/MigrationUpCommand.php b/Command/MigrationUpCommand.php index c550b84a..a90324f1 100644 --- a/Command/MigrationUpCommand.php +++ b/Command/MigrationUpCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -23,7 +24,7 @@ class MigrationUpCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -42,7 +43,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseMigrationCommand(); } @@ -50,7 +51,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $defaultOutputDir = $this->getContainer()->getParameter('propel.configuration')['paths']['migrationDir']; diff --git a/Command/ModelBuildCommand.php b/Command/ModelBuildCommand.php index 77a089f7..873d4e0f 100644 --- a/Command/ModelBuildCommand.php +++ b/Command/ModelBuildCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -24,7 +25,7 @@ class ModelBuildCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -42,7 +43,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new BaseModelBuildCommand(); } @@ -50,7 +51,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $outputDirDefault = $this->getApplication()->getKernel()->getProjectDir().'/'; $outputDir = $this->input->getOption('output-dir') ?: $outputDirDefault; diff --git a/Command/SqlBuildCommand.php b/Command/SqlBuildCommand.php index a71f2850..ec95ceae 100644 --- a/Command/SqlBuildCommand.php +++ b/Command/SqlBuildCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; @@ -21,7 +22,7 @@ class SqlBuildCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { parent::configure(); @@ -37,7 +38,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new \Propel\Generator\Command\SqlBuildCommand(); } @@ -45,7 +46,7 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $defaultSqlDir = $this->getContainer()->getParameter('propel.configuration')['paths']['sqlDir']; diff --git a/Command/SqlInsertCommand.php b/Command/SqlInsertCommand.php index db23a460..888a0ec8 100644 --- a/Command/SqlInsertCommand.php +++ b/Command/SqlInsertCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -22,7 +23,7 @@ class SqlInsertCommand extends WrappedCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this ->setName('propel:sql:insert') @@ -36,7 +37,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function createSubCommandInstance() + protected function createSubCommandInstance(): Command { return new \Propel\Generator\Command\SqlInsertCommand(); } @@ -44,10 +45,10 @@ protected function createSubCommandInstance() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { if ($input->getOption('force')) { - parent::execute($input, $output); + return parent::execute($input, $output); } else { $output->writeln('You have to use --force to execute all SQL statements.'); return 1; @@ -57,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output) /** * {@inheritdoc} */ - protected function getSubCommandArguments(InputInterface $input) + protected function getSubCommandArguments(InputInterface $input): array { $defaultSqlDir = $this->getContainer()->getParameter('propel.configuration')['paths']['sqlDir']; diff --git a/Command/TableDropCommand.php b/Command/TableDropCommand.php index 541207cb..bed20bf9 100644 --- a/Command/TableDropCommand.php +++ b/Command/TableDropCommand.php @@ -12,6 +12,7 @@ use Propel\Runtime\Adapter\Pdo\MysqlAdapter; use Propel\Runtime\Propel; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; @@ -27,7 +28,7 @@ class TableDropCommand extends AbstractCommand /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { $this ->setName('propel:table:drop') @@ -42,17 +43,19 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $connection = Propel::getConnection($input->getOption('connection')); $adapter = Propel::getAdapter($connection->getName()); if (!$adapter instanceof MysqlAdapter) { - return $output->writeln('This command is MySQL only.'); + $output->writeln('This command is MySQL only.'); + return 1; } if (!$input->getOption('force')) { - return $output->writeln('You have to use the "--force" option to drop some tables.'); + $output->writeln('You have to use the "--force" option to drop some tables.'); + return 1; } $tablesToDelete = $input->getArgument('table'); @@ -107,5 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } $connection->exec('SET FOREIGN_KEY_CHECKS = 1;'); + + return 0; } } diff --git a/Command/WrappedCommand.php b/Command/WrappedCommand.php index bd31417d..deedb2c3 100644 --- a/Command/WrappedCommand.php +++ b/Command/WrappedCommand.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\Command; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -21,32 +22,26 @@ abstract class WrappedCommand extends AbstractCommand { /** * Creates the instance of the Propel sub-command to execute. - * - * @return \Symfony\Component\Console\Command\Command */ - abstract protected function createSubCommandInstance(); + abstract protected function createSubCommandInstance(): Command; /** * Returns all the arguments and options needed by the Propel sub-command. - * - * @return array */ - abstract protected function getSubCommandArguments(InputInterface $input); + abstract protected function getSubCommandArguments(InputInterface $input): array; /** * {@inheritdoc} */ - protected function configure() + protected function configure(): void { - $this - ->addOption('platform', null, InputOption::VALUE_OPTIONAL, 'The platform') - ; + $this->addOption('platform', null, InputOption::VALUE_OPTIONAL, 'The platform'); } /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $params = $this->getSubCommandArguments($input); $command = $this->createSubCommandInstance(); diff --git a/Controller/PanelController.php b/Controller/PanelController.php index 880de62a..936be79e 100644 --- a/Controller/PanelController.php +++ b/Controller/PanelController.php @@ -10,10 +10,11 @@ namespace Propel\Bundle\PropelBundle\Controller; +use Propel\Bundle\PropelBundle\DataCollector\PropelDataCollector; use Propel\Runtime\Propel; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; -use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Profiler\Profiler; /** * PanelController is designed to display information in the Propel Panel. @@ -25,7 +26,7 @@ class PanelController extends AbstractController /** * This method renders the global Propel configuration. */ - public function configurationAction() + public function configurationAction(): Response { return $this->render( '@Propel/Panel/configuration.html.twig', @@ -40,19 +41,21 @@ public function configurationAction() /** * Renders the profiler panel for the given token. * - * @param string $token The profiler token - * @param string $connection The connection name - * @param integer $query + * @param string $token The profiler token + * @param string $connection The connection name + * @param integer $query + * @param Profiler|null $profiler * * @return Response A Response instance */ - public function explainAction($token, $connection, $query, ContainerBagInterface $container) + public function explainAction(string $token, string $connection, int $query, ?Profiler $profiler): Response { - $profiler = $container->get('profiler'); $profiler->disable(); - $profile = $profiler->loadProfile($token); - $queries = $profile->getCollector('propel')->getQueries(); + + /** @var PropelDataCollector $propelDataCollector */ + $propelDataCollector = $profile->getCollector('propel'); + $queries = $propelDataCollector->getQueries(); if (!isset($queries[$query])) { return new Response('This query does not exist.'); diff --git a/DataCollector/PropelDataCollector.php b/DataCollector/PropelDataCollector.php index 89479084..3f5fc7dd 100644 --- a/DataCollector/PropelDataCollector.php +++ b/DataCollector/PropelDataCollector.php @@ -22,7 +22,7 @@ */ class PropelDataCollector extends DataCollector { - protected $logger; + protected PropelLogger $logger; public function __construct(PropelLogger $logger) { @@ -32,7 +32,7 @@ public function __construct(PropelLogger $logger) /** * {@inheritdoc} */ - public function collect(Request $request, Response $response, \Throwable $exception = null) + public function collect(Request $request, Response $response, \Throwable $exception = null): void { $this->data = array( 'queries' => $this->cloneVar($this->buildQueries()), @@ -45,7 +45,7 @@ public function collect(Request $request, Response $response, \Throwable $except * * @return string The collector name. */ - public function getName() + public function getName(): string { return 'propel'; } @@ -55,7 +55,7 @@ public function getName() * * @return array Queries */ - public function getQueries() + public function getQueries(): array { return $this->data['queries']; } @@ -65,7 +65,7 @@ public function getQueries() * * @return int The query count */ - public function getQueryCount() + public function getQueryCount(): int { return $this->data['querycount']; } @@ -90,7 +90,7 @@ public function getTime() * * @return array An array of Build objects */ - private function buildQueries() + private function buildQueries(): array { return $this->logger->getQueries(); } @@ -100,7 +100,7 @@ private function buildQueries() * * @return int The number of queries. */ - private function countQueries() + private function countQueries(): int { return count($this->logger->getQueries()); } @@ -108,7 +108,7 @@ private function countQueries() /** * @inheritdoc */ - public function reset() + public function reset(): void { // TODO: Implement reset() method. } diff --git a/DataFixtures/AbstractDataHandler.php b/DataFixtures/AbstractDataHandler.php index 36697e03..85ccb475 100644 --- a/DataFixtures/AbstractDataHandler.php +++ b/DataFixtures/AbstractDataHandler.php @@ -10,6 +10,7 @@ namespace Propel\Bundle\PropelBundle\DataFixtures; +use Propel\Runtime\Connection\ConnectionInterface; use Propel\Runtime\Map\DatabaseMap; use Propel\Runtime\Propel; use Symfony\Component\Finder\Finder; @@ -19,42 +20,23 @@ */ abstract class AbstractDataHandler { - /** - * @var string - */ - protected $rootDir; - - /** - * @var \PDO - */ - protected $con; - - /** - * @var DatabaseMap - */ - protected $dbMap; + protected string $rootDir; + protected ?ConnectionInterface $con = null; + protected ?DatabaseMap $dbMap = null; + /** @var array{database?: array{connections: array>}} */ + protected array $datasources = array(); /** - * @var array - */ - protected $datasources = array(); - - /** - * Default constructor - * * @param string $rootDir The root directory. * @param array $datasources */ - public function __construct($rootDir, array $datasources) + public function __construct(string $rootDir, array $datasources) { $this->rootDir = $rootDir; $this->datasources = $datasources; } - /** - * @return string - */ - protected function getRootDir() + protected function getRootDir(): string { return $this->rootDir; } @@ -64,7 +46,7 @@ protected function getRootDir() * * @param string $connectionName A connection name. */ - protected function loadMapBuilders($connectionName = null) + protected function loadMapBuilders(?string $connectionName = null): void { if (null !== $this->dbMap) { return; @@ -92,13 +74,8 @@ protected function loadMapBuilders($connectionName = null) /** * Check if a table is in a database - * - * @param string $class - * @param string $connectionName - * - * @return boolean */ - protected function isInDatabase($class, $connectionName) + protected function isInDatabase(string $class, string $connectionName): bool { return constant($class.'::DATABASE_NAME') === $connectionName; } @@ -112,7 +89,7 @@ protected function isInDatabase($class, $connectionName) * * @return string|null */ - private function guessFullClassName($path, $shortClassName) + private function guessFullClassName(string $path, string $shortClassName): ?string { $array = array(); $path = str_replace('/', '\\', $path); @@ -142,7 +119,7 @@ private function guessFullClassName($path, $shortClassName) * * @return string[] */ - protected function getModelSearchPaths($connectionName) + protected function getModelSearchPaths(string $connectionName): array { $searchPath = array(); diff --git a/DataFixtures/Dumper/AbstractDataDumper.php b/DataFixtures/Dumper/AbstractDataDumper.php index 31c3ddf7..106253da 100644 --- a/DataFixtures/Dumper/AbstractDataDumper.php +++ b/DataFixtures/Dumper/AbstractDataDumper.php @@ -10,9 +10,10 @@ namespace Propel\Bundle\PropelBundle\DataFixtures\Dumper; -use \PDO; +use PDO; use Propel\Bundle\PropelBundle\DataFixtures\AbstractDataHandler; use Propel\Generator\Model\PropelTypes; +use Propel\Runtime\Map\ColumnMap; use Propel\Runtime\Propel; /** @@ -25,7 +26,7 @@ abstract class AbstractDataDumper extends AbstractDataHandler implements DataDum /** * {@inheritdoc} */ - public function dump($filename, $connectionName = null) + public function dump($filename, $connectionName = null): void { if (null === $filename || '' === $filename) { throw new \Exception('Invalid filename provided.'); @@ -34,7 +35,7 @@ public function dump($filename, $connectionName = null) $this->loadMapBuilders($connectionName); $this->con = Propel::getConnection($connectionName); - $array = $this->getDataAsArray($connectionName); + $array = $this->getDataAsArray(); $data = $this->transformArrayToData($array); if (false === file_put_contents($filename, $data)) { @@ -46,10 +47,8 @@ public function dump($filename, $connectionName = null) * Transforms an array of data to a specific format * depending on the specialized dumper. It should return * a string content ready to write in a file. - * - * @return string */ - abstract protected function transformArrayToData($data); + abstract protected function transformArrayToData(array $data): string; /** * Dumps data to fixture from a given connection and @@ -58,7 +57,7 @@ abstract protected function transformArrayToData($data); * @param string $connectionName The connection name * @return array */ - protected function getDataAsArray() + protected function getDataAsArray(): array { $tables = array(); foreach ($this->dbMap->getTables() as $table) { @@ -185,7 +184,7 @@ protected function getDataAsArray() * @param array $classes The array with the class names * @return array */ - protected function fixOrderingOfForeignKeyData($classes) + protected function fixOrderingOfForeignKeyData(array $classes): array { // reordering classes to take foreign keys into account for ($i = 0, $count = count($classes); $i < $count; $i++) { @@ -216,7 +215,7 @@ protected function fixOrderingOfForeignKeyData($classes) return $classes; } - protected function fixOrderingOfForeignKeyDataInSameTable($resultsSets, $tableName, $column, $in = null) + protected function fixOrderingOfForeignKeyDataInSameTable(array $resultsSets, string $tableName, ColumnMap $column, $in = null): array { $sql = sprintf('SELECT * FROM %s WHERE %s %s', constant(constant($tableName.'::TABLE_MAP').'::TABLE_NAME'), diff --git a/DataFixtures/Dumper/DataDumperInterface.php b/DataFixtures/Dumper/DataDumperInterface.php index 59ce01f4..3c2d6e89 100644 --- a/DataFixtures/Dumper/DataDumperInterface.php +++ b/DataFixtures/Dumper/DataDumperInterface.php @@ -23,5 +23,5 @@ interface DataDumperInterface * @param string $filename The file name to write data. * @param string $connectionName The Propel connection name. */ - public function dump($filename, $connectionName = null); + public function dump(string $filename, ?string $connectionName = null): void; } diff --git a/DataFixtures/Dumper/YamlDataDumper.php b/DataFixtures/Dumper/YamlDataDumper.php index 319f7ae7..c8c0de9a 100644 --- a/DataFixtures/Dumper/YamlDataDumper.php +++ b/DataFixtures/Dumper/YamlDataDumper.php @@ -22,7 +22,7 @@ class YamlDataDumper extends AbstractDataDumper /** * {@inheritdoc} */ - protected function transformArrayToData($data) + protected function transformArrayToData($data): string { return Yaml::dump( $data, diff --git a/DataFixtures/Loader/AbstractDataLoader.php b/DataFixtures/Loader/AbstractDataLoader.php index f9161a0f..55649c06 100644 --- a/DataFixtures/Loader/AbstractDataLoader.php +++ b/DataFixtures/Loader/AbstractDataLoader.php @@ -25,15 +25,11 @@ */ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoaderInterface { - /** - * @var array - */ - protected $deletedClasses = array(); + /** @var string[] */ + protected array $deletedClasses = array(); - /** - * @var array - */ - protected $object_references = array(); + /** @var array */ + protected array $object_references = array(); /** * Transforms a file containing data in an array. @@ -41,12 +37,12 @@ abstract class AbstractDataLoader extends AbstractDataHandler implements DataLoa * @param string $file A filename. * @return array */ - abstract protected function transformDataToArray($file); + abstract protected function transformDataToArray(string $file): array; /** * {@inheritdoc} */ - public function load($connectionName, $files = array()) + public function load($connectionName, $files = array()): int { $nbFiles = 0; $this->deletedClasses = array(); @@ -84,7 +80,7 @@ public function load($connectionName, $files = array()) * * @param array $data The data to delete */ - protected function deleteCurrentData($data = null) + protected function deleteCurrentData($data = null): void { if ($data !== null) { $classes = array_keys($data); @@ -103,7 +99,7 @@ protected function deleteCurrentData($data = null) * * @param string $class Class name to delete */ - protected function deleteClassData($class) + protected function deleteClassData(string $class): void { $tableMap = $this->dbMap->getTable(constant(constant($class.'::TABLE_MAP').'::TABLE_NAME')); $tableMap->doDeleteAll($this->con); @@ -124,7 +120,7 @@ protected function deleteClassData($class) * * @param array|null $data The data to be loaded */ - protected function loadDataFromArray($data = null) + protected function loadDataFromArray(?array $data = null): void { if ($data === null) { return; @@ -244,7 +240,7 @@ protected function loadDataFromArray($data = null) * @param string $key Key identifying specified object * @param ActiveRecordInterface $obj A Propel object */ - protected function saveParentReference($class, $key, &$obj) + protected function saveParentReference(string $class, string $key, ActiveRecordInterface $obj): void { if (!method_exists($obj, 'getPrimaryKey')) { return; @@ -271,7 +267,7 @@ protected function saveParentReference($class, $key, &$obj) * @param string $middleTableName The middle table name * @param array $values An array of values */ - protected function loadManyToMany($obj, $middleTableName, $values) + protected function loadManyToMany(ActiveRecordInterface $obj, string $middleTableName, array $values): void { $middleTable = $this->dbMap->getTable($middleTableName); $middleClass = $middleTable->getClassname(); @@ -306,7 +302,7 @@ protected function loadManyToMany($obj, $middleTableName, $values) } } - protected function cleanObjectRef($ref) + protected function cleanObjectRef(string $ref): string { return $ref[0] === '\\' ? substr($ref, 1) : $ref; } diff --git a/DataFixtures/Loader/DataLoaderInterface.php b/DataFixtures/Loader/DataLoaderInterface.php index 34db55d8..89670e82 100644 --- a/DataFixtures/Loader/DataLoaderInterface.php +++ b/DataFixtures/Loader/DataLoaderInterface.php @@ -23,5 +23,5 @@ interface DataLoaderInterface * @param array $files A set of files containing datas to load. * @param string $connectionName The Propel connection name */ - public function load($connectionName, $files = array()); + public function load(string $connectionName, array $files = array()): int; } diff --git a/DataFixtures/Loader/XmlDataLoader.php b/DataFixtures/Loader/XmlDataLoader.php index 77ec0c68..4fbbbe86 100644 --- a/DataFixtures/Loader/XmlDataLoader.php +++ b/DataFixtures/Loader/XmlDataLoader.php @@ -20,7 +20,7 @@ class XmlDataLoader extends AbstractDataLoader /** * {@inheritdoc} */ - protected function transformDataToArray($file) + protected function transformDataToArray(string $file): array { $xml = simplexml_load_file($file); @@ -31,7 +31,7 @@ protected function transformDataToArray($file) * @param SimpleXMLElement $xml * @return array */ - protected function simpleXmlToArray($xml) + protected function simpleXmlToArray($xml): array { $array = array(); if ($xml instanceof \SimpleXMLElement) { diff --git a/DataFixtures/Loader/YamlDataLoader.php b/DataFixtures/Loader/YamlDataLoader.php index ec6042c4..c9c03674 100644 --- a/DataFixtures/Loader/YamlDataLoader.php +++ b/DataFixtures/Loader/YamlDataLoader.php @@ -21,15 +21,12 @@ */ class YamlDataLoader extends AbstractDataLoader { - /** - * @var \Faker\Generator - */ - private $faker; + private ?Generator $faker; /** * {@inheritdoc} */ - public function __construct($rootDir, array $datasources, Generator $faker = null) + public function __construct($rootDir, array $datasources, ?Generator $faker = null) { parent::__construct($rootDir, $datasources); @@ -39,7 +36,7 @@ public function __construct($rootDir, array $datasources, Generator $faker = nul /** * {@inheritdoc} */ - protected function transformDataToArray($file) + protected function transformDataToArray(string $file): array { if (strpos($file, "\n") === false && is_file($file)) { if (false === is_readable($file)) { diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 1c5bb38d..e9cd6059 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -18,8 +18,8 @@ */ class Configuration extends PropelConfiguration { - private $debug; - private $defaultDir; + private bool $debug; + private string $defaultDir; public function __construct($debug, $kernelDir) { diff --git a/DependencyInjection/PropelExtension.php b/DependencyInjection/PropelExtension.php index 8f4bdc16..a9ad0513 100644 --- a/DependencyInjection/PropelExtension.php +++ b/DependencyInjection/PropelExtension.php @@ -29,7 +29,7 @@ class PropelExtension extends Extension * @param array $configs An array of configuration settings * @param ContainerBuilder $container A ContainerBuilder instance */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { $configuration = $this->getConfiguration($configs, $container); $config = $this->processConfiguration($configuration, $configs); @@ -60,7 +60,7 @@ public function load(array $configs, ContainerBuilder $container) } } - public function getConfiguration(array $config, ContainerBuilder $container) + public function getConfiguration(array $config, ContainerBuilder $container): Configuration { return new Configuration($container->getParameter('kernel.debug'), $container->getParameter('kernel.project_dir')); } @@ -70,7 +70,7 @@ public function getConfiguration(array $config, ContainerBuilder $container) * * @return string The XSD base path */ - public function getXsdValidationBasePath() + public function getXsdValidationBasePath(): string { return __DIR__.'/../Resources/config/schema'; } @@ -82,7 +82,7 @@ public function getXsdValidationBasePath() * * @return string The alias */ - public function getAlias() + public function getAlias(): string { return 'propel'; } diff --git a/DependencyInjection/Security/UserProvider/PropelFactory.php b/DependencyInjection/Security/UserProvider/PropelFactory.php index 28e1b89e..961f7413 100644 --- a/DependencyInjection/Security/UserProvider/PropelFactory.php +++ b/DependencyInjection/Security/UserProvider/PropelFactory.php @@ -20,14 +20,20 @@ */ class PropelFactory implements UserProviderFactoryInterface { - private $key; - private $providerId; - public function __construct($key, $providerId) + private string $key; + private string $providerId; + public function __construct(string $key, string $providerId) { $this->key = $key; $this->providerId = $providerId; } - public function create(ContainerBuilder $container, $id, $config) + + /** + * @param ContainerBuilder $container + * @param string $id + * @param array $config + */ + public function create(ContainerBuilder $container, $id, $config): void { $container ->setDefinition($id, new ChildDefinition($this->providerId)) @@ -35,11 +41,12 @@ public function create(ContainerBuilder $container, $id, $config) ->addArgument($config['property']) ; } - public function getKey() + public function getKey(): string { return $this->key; } - public function addConfiguration(NodeDefinition $node) + + public function addConfiguration(NodeDefinition $node): void { $node ->children() diff --git a/Form/BaseAbstractType.php b/Form/BaseAbstractType.php deleted file mode 100644 index c592cb4f..00000000 --- a/Form/BaseAbstractType.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @deprecated use AbstractType directly - */ -abstract class BaseAbstractType extends AbstractType -{ - protected $options = array(); - - public function __construct($mergeOptions = null) - { - if ($mergeOptions) { - $this->mergeOptions($mergeOptions); - } - } - - public function setOption($name, $value) - { - $this->options[$name] = $value; - } - - public function getOption($name) - { - return $this->options[$name]; - } - - public function setOptions($options) - { - $this->options = $options; - } - - public function getOptions() - { - return $this->options; - } - - public function mergeOptions($options) - { - $this->options = array_merge($this->options, $options); - } - - /** - * {@inheritdoc} - */ - public function configureOptions(OptionsResolver $resolver) - { - $resolver->setDefaults($this->options); - } - - /** - * {@inheritdoc} - */ - public function getName() - { - return get_class($this); - } -} diff --git a/Form/ChoiceList/PropelChoiceLoader.php b/Form/ChoiceList/PropelChoiceLoader.php index 47b0f4bc..ce1e7a38 100644 --- a/Form/ChoiceList/PropelChoiceLoader.php +++ b/Form/ChoiceList/PropelChoiceLoader.php @@ -29,7 +29,7 @@ class PropelChoiceLoader implements ChoiceLoaderInterface * @var ChoiceListFactoryInterface */ protected $factory; - + /** * @var string */ @@ -85,14 +85,14 @@ public function __construct(ChoiceListFactoryInterface $factory, $class, ModelCr /** * {@inheritdoc} */ - public function loadChoiceList($value = null) + public function loadChoiceList($value = null): ChoiceListInterface { if ($this->choiceList) { return $this->choiceList; } $models = iterator_to_array($this->query->find()); - + $this->choiceList = $this->factory->createListFromChoices($models, $value); return $this->choiceList; @@ -101,13 +101,13 @@ public function loadChoiceList($value = null) /** * {@inheritdoc} */ - public function loadChoicesForValues(array $values, $value = null) + public function loadChoicesForValues(array $values, $value = null): array { // Performance optimization if (empty($values)) { return array(); } - + // Optimize performance in case we have a single-field identifier if (!$this->choiceList && $this->identifierAsIndex && current($this->identifier) instanceof ColumnMap) { $phpName = current($this->identifier)->getPhpName(); @@ -136,7 +136,7 @@ public function loadChoicesForValues(array $values, $value = null) /** * {@inheritdoc} */ - public function loadValuesForChoices(array $choices, $value = null) + public function loadValuesForChoices(array $choices, $value = null): array { // Performance optimization if (empty($choices)) { @@ -210,4 +210,4 @@ private function getIdentifierValues($model) return $model->getPrimaryKeys(); } -} \ No newline at end of file +} diff --git a/Form/DataTransformer/CollectionToArrayTransformer.php b/Form/DataTransformer/CollectionToArrayTransformer.php index dd066bc7..05d30255 100644 --- a/Form/DataTransformer/CollectionToArrayTransformer.php +++ b/Form/DataTransformer/CollectionToArrayTransformer.php @@ -36,7 +36,7 @@ public function transform($collection) return $collection->getData(); } - public function reverseTransform($array) + public function reverseTransform($array): ObjectCollection { $collection = new ObjectCollection(); diff --git a/Form/EventListener/TranslationCollectionFormListener.php b/Form/EventListener/TranslationCollectionFormListener.php index 0572f75d..c7177be0 100644 --- a/Form/EventListener/TranslationCollectionFormListener.php +++ b/Form/EventListener/TranslationCollectionFormListener.php @@ -31,14 +31,14 @@ public function __construct($languages, $i18nClass) $this->languages = $languages; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return array( FormEvents::PRE_SET_DATA => array('preSetData', 1), ); } - public function preSetData(FormEvent $event) + public function preSetData(FormEvent $event): void { $form = $event->getForm(); $data = $event->getData(); diff --git a/Form/EventListener/TranslationFormListener.php b/Form/EventListener/TranslationFormListener.php index d9377acf..e04732ae 100644 --- a/Form/EventListener/TranslationFormListener.php +++ b/Form/EventListener/TranslationFormListener.php @@ -31,14 +31,14 @@ public function __construct($columns, $dataClass) $this->dataClass = $dataClass; } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return array( FormEvents::PRE_SET_DATA => array('preSetData', 1), ); } - public function preSetData(FormEvent $event) + public function preSetData(FormEvent $event): void { $form = $event->getForm(); $data = $event->getData(); diff --git a/Form/PropelExtension.php b/Form/PropelExtension.php index 3298dc57..d2ca020b 100644 --- a/Form/PropelExtension.php +++ b/Form/PropelExtension.php @@ -47,8 +47,8 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null, $this->propertyAccessor = $propertyAccessor ?: PropertyAccess::createPropertyAccessor(); $this->choiceListFactory = $choiceListFactory ?: new PropertyAccessDecorator(new DefaultChoiceListFactory(), $this->propertyAccessor); } - - protected function loadTypes() + + protected function loadTypes(): array { return array( new Type\ModelType($this->propertyAccessor, $this->choiceListFactory), @@ -57,7 +57,7 @@ protected function loadTypes() ); } - protected function loadTypeGuesser() + protected function loadTypeGuesser(): TypeGuesser { return new TypeGuesser(); } diff --git a/Form/Type/ModelType.php b/Form/Type/ModelType.php index 410975bd..c6818f54 100644 --- a/Form/Type/ModelType.php +++ b/Form/Type/ModelType.php @@ -87,7 +87,7 @@ public function __construct(PropertyAccessorInterface $propertyAccessor = null, * @internal This method is public to be usable as callback. It should not * be used in user code. */ - public static function createChoiceLabel($choice) + public static function createChoiceLabel($choice): string { return (string) $choice; } @@ -109,7 +109,7 @@ public static function createChoiceLabel($choice) * @internal This method is public to be usable as callback. It should not * be used in user code. */ - public static function createChoiceName($choice, $key, $value) + public static function createChoiceName($choice, $key, $value): string { return str_replace('-', '_', (string) $value); } @@ -117,7 +117,7 @@ public static function createChoiceName($choice, $key, $value) /** * {@inheritDoc} */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { if ($options['multiple']) { $builder @@ -129,7 +129,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritDoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $choiceLoader = function (Options $options) { // Unless the choices are given explicitly, load them on demand @@ -251,12 +251,12 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'model'; } - public function getParent() + public function getParent(): string { return 'Symfony\Component\Form\Extension\Core\Type\ChoiceType'; } diff --git a/Form/Type/TranslationCollectionType.php b/Form/Type/TranslationCollectionType.php index af80f549..1a6e492c 100644 --- a/Form/Type/TranslationCollectionType.php +++ b/Form/Type/TranslationCollectionType.php @@ -28,7 +28,7 @@ class TranslationCollectionType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { if (!isset($options['entry_options']['data_class']) || null === $options['entry_options']['data_class']) { throw new MissingOptionsException('data_class must be set'); @@ -44,7 +44,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired(array( 'languages' diff --git a/Form/Type/TranslationType.php b/Form/Type/TranslationType.php index d7a248d8..2d925f36 100644 --- a/Form/Type/TranslationType.php +++ b/Form/Type/TranslationType.php @@ -27,7 +27,7 @@ class TranslationType extends AbstractType /** * {@inheritdoc} */ - public function buildForm(FormBuilderInterface $builder, array $options) + public function buildForm(FormBuilderInterface $builder, array $options): void { $builder->addEventSubscriber( new TranslationFormListener($options['columns'], $options['data_class']) @@ -37,7 +37,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) /** * {@inheritdoc} */ - public function configureOptions(OptionsResolver $resolver) + public function configureOptions(OptionsResolver $resolver): void { $resolver->setRequired(array( 'data_class', @@ -48,12 +48,12 @@ public function configureOptions(OptionsResolver $resolver) /** * {@inheritdoc} */ - public function getBlockPrefix() + public function getBlockPrefix(): string { return 'propel_translation'; } - public function getName() + public function getName(): string { return $this->getBlockPrefix(); } diff --git a/Form/TypeGuesser.php b/Form/TypeGuesser.php index a53e4649..288ce187 100644 --- a/Form/TypeGuesser.php +++ b/Form/TypeGuesser.php @@ -42,7 +42,7 @@ class TypeGuesser implements FormTypeGuesserInterface /** * {@inheritDoc} */ - public function guessType($class, $property) + public function guessType($class, $property): ?TypeGuess { if (!$table = $this->getTable($class)) { return new TypeGuess(TextType::class, array(), Guess::LOW_CONFIDENCE); @@ -124,17 +124,18 @@ public function guessType($class, $property) /** * {@inheritDoc} */ - public function guessRequired($class, $property) + public function guessRequired($class, $property): ?ValueGuess { if ($column = $this->getColumn($class, $property)) { return new ValueGuess($column->isNotNull(), Guess::HIGH_CONFIDENCE); } + return null; } /** * {@inheritDoc} */ - public function guessMaxLength($class, $property) + public function guessMaxLength($class, $property): ?ValueGuess { if ($column = $this->getColumn($class, $property)) { if ($column->isText()) { @@ -148,12 +149,13 @@ public function guessMaxLength($class, $property) return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE); } } + return null; } /** * {@inheritDoc} */ - public function guessPattern($class, $property) + public function guessPattern($class, $property): ?ValueGuess { if ($column = $this->getColumn($class, $property)) { switch ($column->getType()) { @@ -164,6 +166,8 @@ public function guessPattern($class, $property) return new ValueGuess(null, Guess::MEDIUM_CONFIDENCE); } } + + return null; } /** @@ -182,7 +186,7 @@ protected function getTable($class) return $this->cache[$class] = $query->getTableMap(); } - + return null; } diff --git a/Logger/PropelLogger.php b/Logger/PropelLogger.php index ee49df8a..184088d9 100644 --- a/Logger/PropelLogger.php +++ b/Logger/PropelLogger.php @@ -19,31 +19,14 @@ */ class PropelLogger implements LoggerInterface { - /** - * @var LoggerInterface - */ - protected $logger; - - /** - * @var array - */ - protected $queries = array(); - - /** - * @var Stopwatch - */ - protected $stopwatch; + protected ?LoggerInterface $logger; + protected array $queries = array(); + protected ?Stopwatch $stopwatch; private bool $isPrepared; use LoggerTrait; - /** - * Constructor. - * - * @param LoggerInterface $logger A LoggerInterface instance - * @param Stopwatch $stopwatch A Stopwatch instance - */ public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch = null) { $this->logger = $logger; @@ -59,7 +42,7 @@ public function __construct(LoggerInterface $logger = null, Stopwatch $stopwatch * @param array $context * @return null */ - public function log($level, $message, array $context = array()) + public function log($level, $message, array $context = array()): void { if (null === $this->logger) { return; @@ -100,7 +83,7 @@ public function log($level, $message, array $context = array()) $this->logger->log($level, $message, $context); } - public function getQueries() + public function getQueries(): array { return $this->queries; } @@ -110,7 +93,7 @@ public function getQueries() * * @return array */ - private function getStackTrace() + private function getStackTrace(): array { $e = new \Exception(); $trace = explode("\n", $e->getTraceAsString()); diff --git a/Request/ParamConverter/PropelParamConverter.php b/Request/ParamConverter/PropelParamConverter.php index 520f728f..11d49c16 100644 --- a/Request/ParamConverter/PropelParamConverter.php +++ b/Request/ParamConverter/PropelParamConverter.php @@ -69,7 +69,7 @@ class PropelParamConverter implements ParamConverterInterface * @throws NotFoundHttpException * @throws \Exception */ - public function apply(Request $request, ParamConverter $configuration) + public function apply(Request $request, ParamConverter $configuration): bool { $class = $configuration->getClass(); $classQuery = $class . 'Query'; @@ -156,7 +156,7 @@ public function apply(Request $request, ParamConverter $configuration) * * @return bool */ - public function supports(ParamConverter $configuration) + public function supports(ParamConverter $configuration): bool { if (null === ($classname = $configuration->getClass())) { return false; diff --git a/Resources/config/console.xml b/Resources/config/console.xml index 949cebc3..cd4224c6 100644 --- a/Resources/config/console.xml +++ b/Resources/config/console.xml @@ -7,10 +7,12 @@ - + - + queryClass; $query = $queryClass::create(); @@ -73,7 +73,7 @@ public function loadUserByUsername($username) } if (null === $user = $query->findOne()) { - throw new UsernameNotFoundException(sprintf('User "%s" not found.', $username)); + throw new UserNotFoundException(sprintf('User "%s" not found.', $username)); } return $user; @@ -82,7 +82,7 @@ public function loadUserByUsername($username) /** * {@inheritdoc} */ - public function refreshUser(UserInterface $user) + public function refreshUser(UserInterface $user): UserInterface { if (!$user instanceof $this->class) { throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', get_class($user))); @@ -96,8 +96,13 @@ public function refreshUser(UserInterface $user) /** * {@inheritdoc} */ - public function supportsClass($class) + public function supportsClass($class): bool { return $class === $this->class; } + + public function loadUserByIdentifier(string $identifier): UserInterface + { + return $this->loadUserByIdentifier($identifier); + } } diff --git a/Service/SchemaLocator.php b/Service/SchemaLocator.php index a752c6f4..807e6ed6 100644 --- a/Service/SchemaLocator.php +++ b/Service/SchemaLocator.php @@ -16,8 +16,9 @@ class SchemaLocator { - protected $fileLocator; - protected $configuration; + protected FileLocatorInterface $fileLocator; + /** @var array{paths: array{schemaDir: string, sqlDir: string, migrationDir: string, composerDir: string, loaderScriptDir: string}} */ + protected array $configuration; public function __construct(FileLocatorInterface $fileLocator, array $configuration) { @@ -25,7 +26,7 @@ public function __construct(FileLocatorInterface $fileLocator, array $configurat $this->configuration = $configuration; } - public function locateFromBundlesAndConfiguration(array $bundles) + public function locateFromBundlesAndConfiguration(array $bundles): array { return array_merge( $this->locateFromBundles($bundles), @@ -33,7 +34,7 @@ public function locateFromBundlesAndConfiguration(array $bundles) ); } - private function locateFromConfiguration() + private function locateFromConfiguration(): array { $finalSchemas = array(); @@ -52,7 +53,7 @@ private function locateFromConfiguration() return $finalSchemas; } - public function locateFromBundles(array $bundles) + public function locateFromBundles(array $bundles): array { $schemas = array(); foreach ($bundles as $bundle) { @@ -65,7 +66,7 @@ public function locateFromBundles(array $bundles) /** * @param \Symfony\Component\HttpKernel\Bundle\BundleInterface */ - public function locateFromBundle(BundleInterface $bundle) + public function locateFromBundle(BundleInterface $bundle): array { $finalSchemas = array(); @@ -91,7 +92,7 @@ public function locateFromBundle(BundleInterface $bundle) * @param BundleInterface $bundle * @return string */ - protected function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle) + protected function transformToLogicalName(\SplFileInfo $schema, BundleInterface $bundle): string { $schemaPath = str_replace( $bundle->getPath(). DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR, diff --git a/Tests/Fixtures/Acl/ArrayCache.php b/Tests/Fixtures/Acl/ArrayCache.php deleted file mode 100644 index 79d298c9..00000000 --- a/Tests/Fixtures/Acl/ArrayCache.php +++ /dev/null @@ -1,60 +0,0 @@ -content[$primaryKey])) { - unset($this->content[$primaryKey]); - } - } - - public function evictFromCacheByIdentity(ObjectIdentityInterface $oid) - { - // Propel ACL does not make use of those. - } - - public function getFromCacheById($primaryKey) - { - if (isset($this->content[$primaryKey])) { - return $this->content[$primaryKey]; - } - - return null; - } - - public function getFromCacheByIdentity(ObjectIdentityInterface $oid) - { - // Propel ACL does not make use of those. - } - - public function putInCache(AclInterface $acl) - { - if (null === $acl->getId()) { - throw new \InvalidArgumentException('The given ACL does not have an ID.'); - } - - $this->content[$acl->getId()] = $acl; - } - - public function clearCache() - { - $this->content = array(); - } -} diff --git a/Validator/Constraints/UniqueObject.php b/Validator/Constraints/UniqueObject.php index a071b14e..efd3b074 100644 --- a/Validator/Constraints/UniqueObject.php +++ b/Validator/Constraints/UniqueObject.php @@ -25,17 +25,17 @@ class UniqueObject extends Constraint /** * @var string */ - public $message = 'A {{ object_class }} object already exists with {{ fields }}'; + public string $message = 'A {{ object_class }} object already exists with {{ fields }}'; /** * @var string Used to merge multiple fields in the message */ - public $messageFieldSeparator = ' and '; + public string $messageFieldSeparator = ' and '; /** * @var array */ - public $fields = array(); + public array $fields = array(); /** * @var string Used to set the path where the error will be attached, default is global. @@ -62,7 +62,7 @@ public function __construct($options = null) /** * {@inheritDoc} */ - public function getRequiredOptions() + public function getRequiredOptions(): array { return array('fields'); } @@ -70,7 +70,7 @@ public function getRequiredOptions() /** * {@inheritDoc} */ - public function getTargets() + public function getTargets(): string { return self::CLASS_CONSTRAINT; } diff --git a/Validator/Constraints/UniqueObjectValidator.php b/Validator/Constraints/UniqueObjectValidator.php index 26a598bb..973c883f 100644 --- a/Validator/Constraints/UniqueObjectValidator.php +++ b/Validator/Constraints/UniqueObjectValidator.php @@ -27,7 +27,7 @@ class UniqueObjectValidator extends ConstraintValidator /** * {@inheritdoc} */ - public function validate($object, Constraint $constraint) + public function validate($object, Constraint $constraint): void { $fields = (array) $constraint->fields; $class = get_class($object); diff --git a/composer.json b/composer.json index 2c3b8b6d..078d9f3a 100644 --- a/composer.json +++ b/composer.json @@ -13,17 +13,17 @@ "exclude-from-classmap": [ "Tests/" ] }, "require": { - "php": ">=8.0", + "php": ">=7.4", "propel/propel": "2.0.0-beta2", - "symfony/console": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/framework-bundle": "^4.4|^5.0", - "symfony/security-bundle": "^4.4|^5.0" + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/framework-bundle": "^4.4|^5.0|^6.0", + "symfony/security-core": "^4.4|^5.0|^6.0" }, "require-dev": { "phpunit/phpunit": "^9.5", - "sensio/framework-extra-bundle": "^4.0|^5.0", - "symfony/form": "^4.0|^5.0", + "sensio/framework-extra-bundle": "^4.0|^5.0|^6.0", + "symfony/form": "^4.0|^5.0|^6.0", "fzaninotto/faker": "dev-master", "mikey179/vfsstream": "^1.6", "twig/twig": "^2|^3"