Permalink
Browse files

Merge pull request #299 from hhamon/various_psr2_cs_fixes

Fixed various PSR-2 violations thanks to Sonar Source.
  • Loading branch information...
2 parents f86db9e + 6d87ad2 commit 99e125ebc6eee35bdf3f1f3ed682e3646efff350 @willdurand willdurand committed Aug 23, 2012
@@ -24,7 +24,7 @@ class ArchivableBehavior extends Behavior
// default parameters value
protected $parameters = array(
'archive_table' => '',
- 'archive_phpname' => NULL,
+ 'archive_phpname' => null,
'archive_class' => '',
'log_archived_at' => 'true',
'archived_at_column' => 'archived_at',
@@ -41,10 +41,14 @@ public function objectMethods($builder)
$this->cleanupParameters();
$this->builder = $builder;
-
- $this->builder->declareClasses('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', 'Symfony\\Component\\Validator\\Validator',
-'Symfony\\Component\\Validator\\Mapping\\Loader\\StaticMethodLoader', 'Symfony\\Component\\Validator\\ConstraintValidatorFactory',
-'Symfony\\Component\\Validator\\Mapping\\ClassMetadataFactory', 'Symfony\\Component\\Validator\\ConstraintViolationList');
+ $this->builder->declareClasses(
+ 'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
+ 'Symfony\\Component\\Validator\\Validator',
+ 'Symfony\\Component\\Validator\\Mapping\\Loader\\StaticMethodLoader',
+ 'Symfony\\Component\\Validator\\ConstraintValidatorFactory',
+ 'Symfony\\Component\\Validator\\Mapping\\ClassMetadataFactory',
+ 'Symfony\\Component\\Validator\\ConstraintViolationList'
+ );
$script = $this->addLoadValidatorMetadataMethod();
$script .= $this->addValidateMethod();
@@ -77,7 +81,7 @@ public function getParametersFromColumnName($columnName = null)
$this->cleanupParameters();
foreach ($this->getParameters() as $key => $parameter) {
if ($parameter['column'] === $columnName) {
- $array[$key] = $parameter;
+ $array[$key] = $parameter;
}
}
}
@@ -114,13 +118,16 @@ public function removeParametersFromColumnName($columnName = null)
*/
public function addRuleOnPk()
{
- if (count($this->getParameters()) <= 0) {
- $pk = $this->getTable()->getPrimaryKey();
- $rule['auto_rule']['column'] = $pk[0]->getName();
- $rule['auto_rule']['validator'] = 'Type';
- $rule['auto_rule']['options'] = array('type' => $pk[0]->getPhpType());
-
- $this->setParameters($rule);
+ if (!count($this->getParameters())) {
+ $pk = $this->getTable()->getPrimaryKey();
+ $parameters = array('auto_rule' => array(
+ 'column' => $pk[0]->getName(),
+ 'validators' => 'Type',
+ 'options' => array(
+ 'type' => $pk[0]->getPhpType(),
+ ),
+ ));
+ $this->setParameters($parameters);
}
}
@@ -154,14 +161,14 @@ public function mergeParameters(array $params = null)
*/
protected function cleanupParameters()
{
- $parser = new Parser();
- $params = $this->getParameters();
- foreach ($params as $key => $value) {
- if (is_string($value)) {
- $params[$key] = $parser->parse($value);
- }
- }
- $this->setParameters($params);
+ $parser = new Parser();
+ $params = $this->getParameters();
+ foreach ($params as $key => $value) {
+ if (is_string($value)) {
+ $params[$key] = $parser->parse($value);
+ }
+ }
+ $this->setParameters($params);
}
/**
@@ -302,10 +302,11 @@ public function declareClassNamespace($class, $namespace = '', $alias = false)
return $this->declareClassNamespace($class, $namespace, 'Child' . $class);
}
- throw new LogicException(
- sprintf('The class %s duplicates the class %s and can\'t be used without alias',
- $namespace . '\\' . $class, $this->declaredShortClassesOrAlias[$aliasWanted])
- );
+ throw new LogicException(sprintf(
+ 'The class %s duplicates the class %s and can\'t be used without alias',
+ $namespace . '\\' . $class,
+ $this->declaredShortClassesOrAlias[$aliasWanted]
+ ));
}
/**
@@ -324,18 +325,23 @@ protected function needAliasForClassName($class, $namespace)
}
if (empty($namespace) && 'Base' === $this->getNamespace()) {
- if (str_replace(array('Peer','Query'), '', $class) == str_replace(array('Peer','Query'), '', $this->getUnqualifiedClassName())) {
+ if (str_replace(array('Peer', 'Query'), '', $class) == str_replace(array('Peer', 'Query'), '', $this->getUnqualifiedClassName())) {
return true;
- } elseif ((false !== strpos($class,'Peer') || false !== strpos($class,'Query'))) {
+ }
+
+ if ((false !== strpos($class, 'Peer') || false !== strpos($class, 'Query'))) {
return true;
- } elseif (false === array_search($class, $this->whiteListOfDeclaredClasses, true)) { //force alias for model without namespace
+ }
+ // force alias for model without namespace
+ if (false === array_search($class, $this->whiteListOfDeclaredClasses, true)) {
return true;
}
}
- if ('Base' == $namespace && '' == $this->getNamespace()) {
- if (false === array_search($class, $this->whiteListOfDeclaredClasses, true)) { //force alias for model without namespace
+ if ('Base' === $namespace && '' === $this->getNamespace()) {
+ // force alias for model without namespace
+ if (false === array_search($class, $this->whiteListOfDeclaredClasses, true)) {
return true;
}
@@ -768,10 +774,7 @@ public function renderTemplate($filename, $vars = array(), $templateDir = '/temp
// try with '.php' at the end
$filePath = $filePath . '.php';
if (!file_exists($filePath)) {
- throw new \InvalidArgumentException(sprintf('Template "%s" not found in "%s" directory',
- $filename,
- __DIR__ . $templateDir
- ));
+ throw new \InvalidArgumentException(sprintf('Template "%s" not found in "%s" directory', $filename, __DIR__ . $templateDir));
}
}
$template = new PropelTemplate();
@@ -236,7 +236,7 @@ protected function addClassOpen(&$script)
if ($interface = $this->getInterface()) {
$script .= ", Child" . ClassTools::classname($interface);
if ($interface !== ClassTools::classname($interface)) {
- $this->declareClass($interface);
+ $this->declareClass($interface);
} else {
$this->declareClassFromBuilder($this->getInterfaceBuilder());
}
@@ -894,7 +894,10 @@ public function addTemporalAccessorOpen(&$script, Column $column)
} elseif ($column->getType() === PropelTypes::TIMESTAMP) {
$defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
}
- if (empty($defaultfmt)) { $defaultfmt = null; }
+
+ if (empty($defaultfmt)) {
+ $defaultfmt = null;
+ }
$script .= "
".$visibility." function get$cfc(\$format = ".var_export($defaultfmt, true)."";
@@ -953,7 +956,10 @@ protected function addTemporalAccessorBody(&$script, Column $column)
} elseif ($column->getType() === PropelTypes::TIMESTAMP) {
$defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
}
- if (empty($defaultfmt)) { $defaultfmt = null; }
+
+ if (empty($defaultfmt)) {
+ $defaultfmt = null;
+ }
if ($column->isLazyLoad()) {
$script .= $this->getAccessorLazyLoadSnippet($column);
@@ -3300,7 +3306,7 @@ protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK)
$peerClassName = $this->getClassNameFromBuilder($this->getStubPeerBuilder());
$fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
- $relCol = $this->getRefFKPhpNameAffix($refFK, $plural=true);
+ $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$collName = $this->getRefFKCollVarName($refFK);
$fkPeerBuilder = $this->getNewPeerBuilder($tblFK);
@@ -4324,7 +4330,7 @@ protected function doInsert(ConnectionInterface \$con)
if ($this->getPlatform() instanceof MssqlPlatform) {
if ($table->hasAutoIncrementPrimaryKey() ) {
$script .= "
- \$this->modifiedColumns[] = " . $this->getColumnConstant($table->getAutoIncrementPrimaryKey() ) . ";";
+ \$this->modifiedColumns[] = " . $this->getColumnConstant($table->getAutoIncrementPrimaryKey()).';';
}
$script .= "
\$criteria = \$this->buildCriteria();";
@@ -2082,7 +2082,7 @@ public function addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder
\$criteria->addJoin(%s, %s, \$joinBehavior);
",
$this->getColumnConstant($table->getColumn($lftCol)),
- $joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn($lfMap[$lftCol] ))
+ $joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn($lfMap[$lftCol]))
);
} else {
// composite foreign key
@@ -2094,8 +2094,8 @@ public function addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder
" array(%s, %s),
",
$this->getColumnConstant($table->getColumn($columnName)),
- $joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn( $lfMap[$columnName])
- ));
+ $joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn($lfMap[$columnName]))
+ );
}
$script .= " ), \$joinBehavior);
";
@@ -2423,7 +2423,7 @@ public static function doSelectJoinAll(Criteria \$criteria, \$con = null, \$join
";
$index = 1;
- foreach ($table->getForeignKeys() as $fk ) {
+ foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet.
// Why not? -because we'd have to alias the tables in the JOIN
if ($fk->getForeignTableName() != $table->getName()) {
@@ -25,18 +25,20 @@ class ArrayToPhpConverter
*/
public static function convert($c)
{
- $conf = "\$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();";
- // set datasources
- if (isset($c['datasources'])) {
+ $conf = "\$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();";
+ // set datasources
+ if (isset($c['datasources'])) {
foreach ($c['datasources'] as $name => $params) {
if (!is_array($params)) {
continue;
}
+
// set adapters
if (isset($params['adapter'])) {
$conf .= "
\$serviceContainer->setAdapterClass('{$name}', '{$params['adapter']}');";
}
+
// set connection settings
if (isset($params['slaves'])) {
$conf .= "
@@ -48,15 +50,18 @@ public static function convert($c)
} else {
continue;
}
+
if (isset($params['connection'])) {
$masterConfigurationSetter = isset($params['slaves']) ? 'setWriteConfiguration' : 'setConfiguration';
$conf .= "
\$manager->{$masterConfigurationSetter}(". var_export($params['connection'], true) . ");";
}
+
$conf .= "
\$manager->setName('{$name}');
\$serviceContainer->setConnectionManager('{$name}', \$manager);";
}
+
// set default datasource
if (isset($c['datasources']['default'])) {
$defaultDatasource = $c['datasources']['default'];
@@ -65,9 +70,11 @@ public static function convert($c)
$datasourceNames = array_keys($c['datasources']);
$defaultDatasource = $datasourceNames[0];
}
+
$conf .= "
\$serviceContainer->setDefaultDatasource('{$defaultDatasource}');";
}
+
// set profiler
if (isset($c['profiler'])) {
$profilerConf = $c['profiler'];
@@ -82,14 +89,15 @@ public static function convert($c)
}
unset($c['profiler']);
}
+
// set logger
if (isset($c['log']) && isset($c['log']['logger'])) {
$loggerConfiguration = $c['log']['logger'];
// is it a single logger or a list of loggers?
if (isset($loggerConfiguration[0])) {
- foreach ($loggerConfiguration as $singleLoggerConfiguration) {
- $conf .= self::getLoggerCode($singleLoggerConfiguration);
- }
+ foreach ($loggerConfiguration as $singleLoggerConfiguration) {
+ $conf .= self::getLoggerCode($singleLoggerConfiguration);
+ }
} else {
$conf .= self::getLoggerCode($loggerConfiguration);
}
@@ -110,5 +118,4 @@ protected static function getLoggerCode($conf)
return "
\$serviceContainer->setLoggerConfiguration('{$name}', " . var_export($conf, true) . ");";
}
-
}
@@ -59,7 +59,7 @@ protected static function simpleXmlToArray($xml)
$ar = array();
foreach ($xml->children() as $k => $v) {
// recurse the child
- $child = self::simpleXmlToArray( $v );
+ $child = self::simpleXmlToArray($v);
// if it's not an array, then it was empty, thus a value/string
if (count($child) == 0) {
@@ -80,7 +80,7 @@ protected static function simpleXmlToArray($xml)
// if the $k is already in our children list, we need to transform
// it into an array, else we add it as a value
- if (!in_array( $k, array_keys($ar))) {
+ if (!in_array($k, array_keys($ar))) {
$ar[$k] = $child;
} else {
// (This only applies to nested nodes that do not have an @id attribute)
@@ -1047,13 +1047,14 @@ public function isTemporalType()
}
/**
- * Utility method to know whether column is an array column.
+ * Returns whether or not the column is an array column.
+ *
* @return boolean
*/
- public function isPhpArrayType()
- {
- return PropelTypes::isPhpArrayType($this->getType());
- }
+ public function isPhpArrayType()
+ {
+ return PropelTypes::isPhpArrayType($this->getType());
+ }
/**
* Returns whether or not this column is an ENUM column.
@@ -439,7 +439,7 @@ public function getRemovedIndices()
*
* @param $modifiedIndices
*/
- public function setModifiedIndices( $modifiedIndices)
+ public function setModifiedIndices($modifiedIndices)
{
$this->modifiedIndices = $modifiedIndices;
}
@@ -60,7 +60,7 @@ public function getColumn()
*
* @param Column $column
*/
- public function setColumn(Column $column)
+ public function setColumn(Column $column)
{
$this->column = $column;
}
@@ -558,7 +558,7 @@ public function getIndexDDL(Index $index)
*/
public function getUniqueDDL(Unique $unique)
{
- return sprintf('UNIQUE (%s)' , $this->getColumnListDDL($unique->getColumns()));
+ return sprintf('UNIQUE (%s)', $this->getColumnListDDL($unique->getColumns()));
}
/**
@@ -1240,7 +1240,7 @@ public function getColumnBindingPHP($column, $identifier, $columnValueAccessor,
"
\$stmt->bindValue(%s, %s, %s);",
$identifier,
- $columnValueAccessor ,
+ $columnValueAccessor,
PropelTypes::getPdoTypeString($column->getType())
);
@@ -249,12 +249,12 @@ protected function getTableOptions(Table $table)
);
foreach ($supportedOptions as $name => $sqlName) {
- $parameterValue = NULL;
+ $parameterValue = null;
if ($vi->hasParameter($name)) {
- $parameterValue = $vi->getParameter( $name );
+ $parameterValue = $vi->getParameter($name);
} elseif ($vi->hasParameter($sqlName)) {
- $parameterValue = $vi->getParameter( $sqlName );
+ $parameterValue = $vi->getParameter($sqlName);
}
// if we have a param value, then parse it out
Oops, something went wrong.

0 comments on commit 99e125e

Please sign in to comment.