Skip to content

Commit

Permalink
Add a real configuration for CS-Fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Jul 1, 2017
1 parent 822c877 commit f808b01
Show file tree
Hide file tree
Showing 170 changed files with 2,339 additions and 2,312 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
/bin/*
!/bin/console
!/bin/symfony_requirements
.php_cs.cache

# Parameters
/app/config/parameters.yml
Expand Down
47 changes: 47 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => [
'syntax' => 'short'
],
'combine_consecutive_unsets' => true,
'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => [
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block'
],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
// 'psr4' => true,
'strict_comparison' => true,
'strict_param' => true,
'concat_space' => [
'spacing' => 'one'
],
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude([
'vendor',
'var',
'web'
])
->in(__DIR__)
)
;
14 changes: 7 additions & 7 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\Kernel;

class AppKernel extends Kernel
{
Expand Down Expand Up @@ -64,25 +64,25 @@ public function getRootDir()

public function getCacheDir()
{
return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
return dirname(__DIR__) . '/var/cache/' . $this->getEnvironment();
}

public function getLogDir()
{
return dirname(__DIR__).'/var/logs';
return dirname(__DIR__) . '/var/logs';
}

public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
$loader->load($this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.yml');
$loader->load(function ($container) {
if ($container->getParameter('use_webpack_dev_server')) {
$container->loadFromExtension('framework', [
if ($container->getParameter('use_webpack_dev_server')) {
$container->loadFromExtension('framework', [
'assets' => [
'base_url' => 'http://localhost:8080/',
],
]);
}
}
});
}
}
16 changes: 8 additions & 8 deletions app/DoctrineMigrations/Version20160410190541.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public function setContainer(ContainerInterface $container = null)
$this->container = $container;
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix').$tableName;
}

/**
* @param Schema $schema
*/
Expand All @@ -44,10 +39,10 @@ public function up(Schema $schema)
$sharePublic = $this->container
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchArray('SELECT * FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_public'");
->fetchArray('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_public'");

if (false === $sharePublic) {
$this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('share_public', '1', 'entry')");
$this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('share_public', '1', 'entry')");
}
}

Expand All @@ -59,6 +54,11 @@ public function down(Schema $schema)
$entryTable = $schema->getTable($this->getTable('entry'));
$entryTable->dropColumn('uid');

$this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'share_public'");
$this->addSql('DELETE FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'share_public'");
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix') . $tableName;
}
}
10 changes: 5 additions & 5 deletions app/DoctrineMigrations/Version20160812120952.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public function setContainer(ContainerInterface $container = null)
$this->container = $container;
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix').$tableName;
}

/**
* @param Schema $schema
*/
Expand All @@ -46,4 +41,9 @@ public function down(Schema $schema)
$clientsTable = $schema->getTable($this->getTable('oauth2_clients'));
$clientsTable->dropColumn('name');
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix') . $tableName;
}
}
22 changes: 11 additions & 11 deletions app/DoctrineMigrations/Version20160911214952.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public function setContainer(ContainerInterface $container = null)
$this->container = $container;
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix').$tableName;
}

/**
* @param Schema $schema
*/
Expand All @@ -35,19 +30,19 @@ public function up(Schema $schema)
$redis = $this->container
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchArray('SELECT * FROM '.$this->getTable('craue_config_setting')." WHERE name = 'import_with_redis'");
->fetchArray('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_redis'");

if (false === $redis) {
$this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('import_with_redis', 0, 'import')");
$this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('import_with_redis', 0, 'import')");
}

$rabbitmq = $this->container
->get('doctrine.orm.default_entity_manager')
->getConnection()
->fetchArray('SELECT * FROM '.$this->getTable('craue_config_setting')." WHERE name = 'import_with_rabbitmq'");
->fetchArray('SELECT * FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_rabbitmq'");

if (false === $rabbitmq) {
$this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('import_with_rabbitmq', 0, 'import')");
$this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('import_with_rabbitmq', 0, 'import')");
}

$this->skipIf(false !== $rabbitmq && false !== $redis, 'It seems that you already played this migration.');
Expand All @@ -58,7 +53,12 @@ public function up(Schema $schema)
*/
public function down(Schema $schema)
{
$this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'import_with_redis';");
$this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'import_with_rabbitmq';");
$this->addSql('DELETE FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_redis';");
$this->addSql('DELETE FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'import_with_rabbitmq';");
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix') . $tableName;
}
}
14 changes: 7 additions & 7 deletions app/DoctrineMigrations/Version20160916201049.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ public function setContainer(ContainerInterface $container = null)
$this->container = $container;
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix').$tableName;
}

/**
* @param Schema $schema
*/
Expand All @@ -37,7 +32,7 @@ public function up(Schema $schema)
$this->skipIf($configTable->hasColumn('pocket_consumer_key'), 'It seems that you already played this migration.');

$configTable->addColumn('pocket_consumer_key', 'string', ['notnull' => false]);
$this->addSql('DELETE FROM '.$this->getTable('craue_config_setting')." WHERE name = 'pocket_consumer_key';");
$this->addSql('DELETE FROM ' . $this->getTable('craue_config_setting') . " WHERE name = 'pocket_consumer_key';");
}

/**
Expand All @@ -47,6 +42,11 @@ public function down(Schema $schema)
{
$configTable = $schema->getTable($this->getTable('config'));
$configTable->dropColumn('pocket_consumer_key');
$this->addSql('INSERT INTO '.$this->getTable('craue_config_setting')." (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')");
$this->addSql('INSERT INTO ' . $this->getTable('craue_config_setting') . " (name, value, section) VALUES ('pocket_consumer_key', NULL, 'import')");
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix') . $tableName;
}
}
42 changes: 20 additions & 22 deletions app/DoctrineMigrations/Version20161001072726.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Migrations\SkipMigrationException;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Doctrine\DBAL\Migrations\SkipMigrationException;

/**
* Added pocket_consumer_key field on wallabag_config.
Expand All @@ -23,34 +23,28 @@ public function setContainer(ContainerInterface $container = null)
$this->container = $container;
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix').$tableName;
}

/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
$this->skipIf($this->connection->getDatabasePlatform()->getName() === 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');

// remove all FK from entry_tag
switch ($this->connection->getDatabasePlatform()->getName()) {
case 'mysql':
$query = $this->connection->query("
SELECT CONSTRAINT_NAME
FROM information_schema.key_column_usage
WHERE TABLE_NAME = '".$this->getTable('entry_tag')."' AND CONSTRAINT_NAME LIKE 'FK_%'
AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'"
WHERE TABLE_NAME = '" . $this->getTable('entry_tag') . "' AND CONSTRAINT_NAME LIKE 'FK_%'
AND TABLE_SCHEMA = '" . $this->connection->getDatabase() . "'"
);
$query->execute();

foreach ($query->fetchAll() as $fk) {
$this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']);
$this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' DROP FOREIGN KEY ' . $fk['CONSTRAINT_NAME']);
}
break;

case 'postgresql':
// http://dba.stackexchange.com/questions/36979/retrieving-all-pk-and-fk
$query = $this->connection->query("
Expand All @@ -60,19 +54,19 @@ public function up(Schema $schema)
FROM pg_constraint c
JOIN pg_namespace n ON n.oid = c.connamespace
WHERE contype = 'f'
AND conrelid::regclass::text = '".$this->getTable('entry_tag')."'
AND conrelid::regclass::text = '" . $this->getTable('entry_tag') . "'
AND n.nspname = 'public';"
);
$query->execute();

foreach ($query->fetchAll() as $fk) {
$this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' DROP CONSTRAINT '.$fk['conname']);
$this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' DROP CONSTRAINT ' . $fk['conname']);
}
break;
}

$this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_entry_tag_entry FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE '.$this->getTable('entry_tag').' ADD CONSTRAINT FK_entry_tag_tag FOREIGN KEY (tag_id) REFERENCES '.$this->getTable('tag').' (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' ADD CONSTRAINT FK_entry_tag_entry FOREIGN KEY (entry_id) REFERENCES ' . $this->getTable('entry') . ' (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE ' . $this->getTable('entry_tag') . ' ADD CONSTRAINT FK_entry_tag_tag FOREIGN KEY (tag_id) REFERENCES ' . $this->getTable('tag') . ' (id) ON DELETE CASCADE');

// remove entry FK from annotation

Expand All @@ -81,18 +75,17 @@ public function up(Schema $schema)
$query = $this->connection->query("
SELECT CONSTRAINT_NAME
FROM information_schema.key_column_usage
WHERE TABLE_NAME = '".$this->getTable('annotation')."'
WHERE TABLE_NAME = '" . $this->getTable('annotation') . "'
AND CONSTRAINT_NAME LIKE 'FK_%'
AND COLUMN_NAME = 'entry_id'
AND TABLE_SCHEMA = '".$this->connection->getDatabase()."'"
AND TABLE_SCHEMA = '" . $this->connection->getDatabase() . "'"
);
$query->execute();

foreach ($query->fetchAll() as $fk) {
$this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP FOREIGN KEY '.$fk['CONSTRAINT_NAME']);
$this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' DROP FOREIGN KEY ' . $fk['CONSTRAINT_NAME']);
}
break;

case 'postgresql':
// http://dba.stackexchange.com/questions/36979/retrieving-all-pk-and-fk
$query = $this->connection->query("
Expand All @@ -102,19 +95,19 @@ public function up(Schema $schema)
FROM pg_constraint c
JOIN pg_namespace n ON n.oid = c.connamespace
WHERE contype = 'f'
AND conrelid::regclass::text = '".$this->getTable('annotation')."'
AND conrelid::regclass::text = '" . $this->getTable('annotation') . "'
AND n.nspname = 'public'
AND pg_get_constraintdef(c.oid) LIKE '%entry_id%';"
);
$query->execute();

foreach ($query->fetchAll() as $fk) {
$this->addSql('ALTER TABLE '.$this->getTable('annotation').' DROP CONSTRAINT '.$fk['conname']);
$this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' DROP CONSTRAINT ' . $fk['conname']);
}
break;
}

$this->addSql('ALTER TABLE '.$this->getTable('annotation').' ADD CONSTRAINT FK_annotation_entry FOREIGN KEY (entry_id) REFERENCES '.$this->getTable('entry').' (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE ' . $this->getTable('annotation') . ' ADD CONSTRAINT FK_annotation_entry FOREIGN KEY (entry_id) REFERENCES ' . $this->getTable('entry') . ' (id) ON DELETE CASCADE');
}

/**
Expand All @@ -124,4 +117,9 @@ public function down(Schema $schema)
{
throw new SkipMigrationException('Too complex ...');
}

private function getTable($tableName)
{
return $this->container->getParameter('database_table_prefix') . $tableName;
}
}
Loading

0 comments on commit f808b01

Please sign in to comment.