Skip to content

Commit

Permalink
update coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
JanTvrdik committed Jan 20, 2024
1 parent 221ad58 commit 78069ee
Show file tree
Hide file tree
Showing 44 changed files with 175 additions and 185 deletions.
1 change: 0 additions & 1 deletion src/Bridges/DoctrineDbal/DoctrineAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ public function escapeIdentifier($value)
{
return $this->conn->quoteIdentifier($value);
}

}
12 changes: 5 additions & 7 deletions src/Bridges/DoctrineOrm/StructureDiffGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

class StructureDiffGenerator implements IDiffGenerator
{

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

Expand All @@ -27,10 +26,10 @@ class StructureDiffGenerator implements IDiffGenerator


/**
* @param EntityManagerInterface $entityManager
* @param string|NULL $ignoredQueriesFile
* @param EntityManagerInterface $entityManager
* @param string|NULL $ignoredQueriesFile
*/
public function __construct(EntityManagerInterface $entityManager, $ignoredQueriesFile = NULL)
public function __construct(EntityManagerInterface $entityManager, $ignoredQueriesFile = null)
{
$this->entityManager = $entityManager;
$this->ignoredQueriesFile = $ignoredQueriesFile;
Expand Down Expand Up @@ -70,7 +69,7 @@ protected function getUpdateQueries()

$schemaTool = new SchemaTool($this->entityManager);
$metadata = $this->entityManager->getMetadataFactory()->getAllMetadata();
$queries = $schemaTool->getUpdateSchemaSql($metadata, TRUE);
$queries = $schemaTool->getUpdateSchemaSql($metadata, true);

return $queries;
}
Expand All @@ -81,7 +80,7 @@ protected function getUpdateQueries()
*/
protected function getIgnoredQueries()
{
if ($this->ignoredQueriesFile === NULL) {
if ($this->ignoredQueriesFile === null) {
return [];
}

Expand All @@ -90,5 +89,4 @@ protected function getIgnoredQueries()

return $queries;
}

}
42 changes: 22 additions & 20 deletions src/Bridges/NetteDI/MigrationsExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Nextras\Migrations\Bridges\NetteDI;

use Doctrine;
use Nette;
use Nette\DI\ContainerBuilder;
use Nette\Utils\Strings;
Expand All @@ -26,15 +27,15 @@ class MigrationsExtension extends Nette\DI\CompilerExtension

/** @var array */
public $defaults = [
'dir' => NULL,
'dir' => null,
'phpParams' => [],
'driver' => NULL,
'dbal' => NULL,
'driver' => null,
'dbal' => null,
'printer' => 'console',
'groups' => NULL, // null|array
'diffGenerator' => TRUE, // false|doctrine
'withDummyData' => FALSE,
'ignoredQueriesFile' => NULL,
'groups' => null, // null|array
'diffGenerator' => true, // false|doctrine
'withDummyData' => false,
'ignoredQueriesFile' => null,
];

/** @var array */
Expand All @@ -59,6 +60,7 @@ class MigrationsExtension extends Nette\DI\CompilerExtension
'psrLog' => 'Nextras\Migrations\Bridges\PsrLog\PsrLogPrinter',
];


public function loadConfiguration()
{
$config = $this->validateConfig($this->defaults);
Expand All @@ -82,7 +84,7 @@ public function loadConfiguration()
}

// groups
if ($config['groups'] === NULL) {
if ($config['groups'] === null) {
Validators::assertField($config, 'dir', 'string|Nette\PhpGenerator\PhpLiteral');
Validators::assertField($config, 'withDummyData', 'bool');
$config['groups'] = $this->createDefaultGroupConfiguration($config['dir'], $config['withDummyData']);
Expand Down Expand Up @@ -126,7 +128,7 @@ public function beforeCompile()
}

// diff generator
if ($config['diffGenerator'] === TRUE) {
if ($config['diffGenerator'] === true) {
if ($builder->findByType('Doctrine\ORM\EntityManagerInterface') && $builder->hasDefinition($this->prefix('group.structures'))) {
Validators::assertField($config, 'ignoredQueriesFile', 'null|string');
$diffGenerator = $this->createDoctrineStructureDiffGeneratorDefinition($config['ignoredQueriesFile']);
Expand Down Expand Up @@ -166,7 +168,7 @@ private function getDbalDefinition($dbal)
->setClass('Nextras\Migrations\IDbal')
->setFactory($factory);

} elseif ($dbal === NULL) {
} elseif ($dbal === null) {
return '@Nextras\Migrations\IDbal';

} else {
Expand All @@ -187,7 +189,7 @@ private function getDbalFactory($dbal)
return $dbal;

} else {
return NULL;
return null;
}
}

Expand All @@ -202,7 +204,7 @@ private function getDriverDefinition($driver, $dbal)
->setClass('Nextras\Migrations\IDriver')
->setFactory($factory);

} elseif ($driver === NULL) {
} elseif ($driver === null) {
return '@Nextras\Migrations\IDriver';

} else {
Expand All @@ -220,7 +222,7 @@ private function getDriverFactory($driver, $dbal)
return new Nette\DI\Statement($this->drivers[$driver], [$dbal]);

} else {
return NULL;
return null;
}
}

Expand All @@ -235,7 +237,7 @@ private function getPrinterDefinition($printer)
->setClass('Nextras\Migrations\IPrinter')
->setFactory($factory);

} elseif ($printer === NULL) {
} elseif ($printer === null) {
return '@Nextras\Migrations\IPrinter';

} else {
Expand All @@ -256,7 +258,7 @@ private function getPrinterFactory($printer)
return $printer;

} else {
return NULL;
return null;
}
}

Expand Down Expand Up @@ -293,7 +295,7 @@ private function createDefaultGroupConfiguration($dir, $withDummyData)

foreach ($groups as $groupName => $groupConfig) {
$serviceName = $this->prefix("diffGenerator.$groupName");
$diffGenerator = $builder->hasDefinition($serviceName) ? $builder->getDefinition($serviceName) : NULL;
$diffGenerator = $builder->hasDefinition($serviceName) ? $builder->getDefinition($serviceName) : null;
$groups[$groupName]['generator'] = $diffGenerator;
}

Expand All @@ -317,7 +319,7 @@ private function createGroupDefinitions(array $groups)
$serviceName = lcfirst(str_replace('-', '', ucwords($groupName, '-')));
$groupDefinitions[] = $builder->addDefinition($this->prefix("group.$serviceName"))
->addTag(self::TAG_GROUP, ['for' => [$this->name]])
->setAutowired(FALSE)
->setAutowired(false)
->setClass('Nextras\Migrations\Entities\Group')
->addSetup('$name', [$groupName])
->addSetup('$enabled', [$enabled])
Expand All @@ -336,14 +338,14 @@ private function createExtensionHandlerDefinitions($driver, $phpParams)

$sqlHandler = $builder->addDefinition($this->prefix('extensionHandler.sql'))
->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'sql'])
->setAutowired(FALSE)
->setAutowired(false)
->setClass('Nextras\Migrations\Extensions\SqlHandler')
->setArguments([$driver]);

$phpHandler = $builder->addDefinition($this->prefix('extensionHandler.php'))
->addTag(self::TAG_EXTENSION_HANDLER, ['for' => [$this->name], 'extension' => 'php'])
->setClass('Nextras\Migrations\Extensions\PhpHandler')
->setAutowired(FALSE)
->setAutowired(false)
->setArguments([$phpParams]);

return [$sqlHandler, $phpHandler];
Expand All @@ -364,7 +366,7 @@ private function createDoctrineStructureDiffGeneratorDefinition($ignoredQueriesF
$builder = $this->getContainerBuilder();

return $builder->addDefinition($this->prefix('diffGenerator.structures'))
->setAutowired(FALSE)
->setAutowired(false)
->setClass('Nextras\Migrations\IDiffGenerator')
->setFactory('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator')
->setArguments(['@Doctrine\ORM\EntityManagerInterface', $ignoredQueriesFile]);
Expand Down
1 change: 0 additions & 1 deletion src/Bridges/NetteDatabase/NetteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,4 @@ public function escapeIdentifier($value)
{
return $this->conn->getSupplementalDriver()->delimite($value);
}

}
1 change: 0 additions & 1 deletion src/Bridges/NextrasDbal/NextrasAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ public function escapeIdentifier($value)
return $this->conn->getDriver()->convertToSql($value, IDriver::TYPE_IDENTIFIER);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ public function load(array $configs, ContainerBuilder $container)

$dbalAlias = $config['dbal'];
$dbalDefinition = new Definition($this->dbals[$dbalAlias]);
$dbalDefinition->setAutowired(TRUE);
$dbalDefinition->setAutowired(true);

$driverAlias = $config['driver'];
$driverDefinition = new Definition($this->drivers[$driverAlias]);
$driverDefinition->setArgument('$dbal', $dbalDefinition);

$printerAlias = $config['printer'];
$printerDefinition = new Definition($this->printers[$printerAlias]);
$printerDefinition->setAutowired(TRUE);
$printerDefinition->setAutowired(true);

$container->addDefinitions([
'nextras_migrations.dbal' => $dbalDefinition,
Expand All @@ -69,11 +69,11 @@ public function load(array $configs, ContainerBuilder $container)

if ($config['diff_generator'] === 'doctrine') {
$structureDiffGeneratorDefinition = new Definition('Nextras\Migrations\Bridges\DoctrineOrm\StructureDiffGenerator');
$structureDiffGeneratorDefinition->setAutowired(TRUE);
$structureDiffGeneratorDefinition->setAutowired(true);
$structureDiffGeneratorDefinition->setArgument('$ignoredQueriesFile', $config['ignored_queries_file']);

} else {
$structureDiffGeneratorDefinition = NULL;
$structureDiffGeneratorDefinition = null;
}

foreach ($config['php_params'] as $phpParamKey => $phpParamValue) {
Expand Down
1 change: 0 additions & 1 deletion src/Bridges/SymfonyConsole/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ protected function runMigrations($mode, $config)

return 0;
}

}
1 change: 0 additions & 1 deletion src/Bridges/SymfonyConsole/ContinueCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->runMigrations(Runner::MODE_CONTINUE, $this->config);
}

}
19 changes: 9 additions & 10 deletions src/Bridges/SymfonyConsole/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ protected function configure()
$this->addArgument('type', InputArgument::REQUIRED, $this->getTypeArgDescription());
$this->addArgument('label', InputArgument::REQUIRED, 'short description');

$this->addOption('empty', NULL, InputOption::VALUE_NONE, 'create empty file');
$this->addOption('diff', NULL, InputOption::VALUE_NONE, 'use schema diff as file content');
$this->addOption('stdin', NULL, InputOption::VALUE_NONE, 'use stdin as file content');
$this->addOption('empty', null, InputOption::VALUE_NONE, 'create empty file');
$this->addOption('diff', null, InputOption::VALUE_NONE, 'use schema diff as file content');
$this->addOption('stdin', null, InputOption::VALUE_NONE, 'use stdin as file content');
}


Expand Down Expand Up @@ -171,24 +171,24 @@ class_exists('Symfony\Component\String\Slugger\AsciiSlugger')


/**
* @param string $dir
* @param string $dir
* @param string|NULL $found
* @return bool
*/
protected function hasNumericSubdirectory($dir, & $found)
protected function hasNumericSubdirectory($dir, &$found)
{
$items = @scandir($dir); // directory may not exist

if ($items) {
foreach ($items as $item) {
if ($item !== '.' && $item !== '..' && is_dir($dir . '/' . $item)) {
$found = $dir . '/' . $item;
return TRUE;
return true;
}
}
}

return FALSE;
return false;
}


Expand Down Expand Up @@ -249,7 +249,7 @@ protected function getFileContentSource(InputInterface $input)
*/
protected function getFileContent(Group $group, $source)
{
if ($source === self::CONTENT_SOURCE_DIFF && $group->generator !== NULL) {
if ($source === self::CONTENT_SOURCE_DIFF && $group->generator !== null) {
return $group->generator->generateContent();

} elseif ($source === self::CONTENT_SOURCE_STDIN) {
Expand All @@ -269,12 +269,11 @@ protected function getFileContent(Group $group, $source)
*/
protected function createFile($path, $content, OutputInterface $output)
{
@mkdir(dirname($path), 0777, TRUE); // directory may already exist
@mkdir(dirname($path), 0777, true); // directory may already exist

if (file_put_contents("$path.tmp", $content) !== strlen($content) || !rename("$path.tmp", $path)) {
$output->writeln("Unable to write to '$path'.");
exit(1);
}
}

}
2 changes: 1 addition & 1 deletion src/Bridges/SymfonyConsole/ResetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ResetCommand extends BaseCommand
/** @var string */
protected static $defaultDescription = 'Drops current database and recreates it from scratch';


protected function configure()
{
$this->setName(self::$defaultName);
Expand All @@ -34,5 +35,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
return $this->runMigrations(Runner::MODE_RESET, $this->config);
}

}
4 changes: 2 additions & 2 deletions src/Configurations/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Configuration implements IConfiguration


/**
* @param Group[] $groups
* @param IExtensionHandler[] $extensionHandlers (extension => IExtensionHandler)
* @param Group[] $groups
* @param IExtensionHandler[] $extensionHandlers (extension => IExtensionHandler)
*/
public function __construct(array $groups, array $extensionHandlers)
{
Expand Down
Loading

0 comments on commit 78069ee

Please sign in to comment.