Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed various PSR-2 violations thanks to Sonar Source. #299

Merged
merged 1 commit into from Aug 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,7 +24,7 @@ class ArchivableBehavior extends Behavior
// default parameters value // default parameters value
protected $parameters = array( protected $parameters = array(
'archive_table' => '', 'archive_table' => '',
'archive_phpname' => NULL, 'archive_phpname' => null,
'archive_class' => '', 'archive_class' => '',
'log_archived_at' => 'true', 'log_archived_at' => 'true',
'archived_at_column' => 'archived_at', 'archived_at_column' => 'archived_at',
Expand Down
47 changes: 27 additions & 20 deletions src/Propel/Generator/Behavior/Validate/ValidateBehavior.php
Expand Up @@ -41,10 +41,14 @@ public function objectMethods($builder)
$this->cleanupParameters(); $this->cleanupParameters();


$this->builder = $builder; $this->builder = $builder;

$this->builder->declareClasses(
$this->builder->declareClasses('Symfony\\Component\\Validator\\Mapping\\ClassMetadata', 'Symfony\\Component\\Validator\\Validator', 'Symfony\\Component\\Validator\\Mapping\\ClassMetadata',
'Symfony\\Component\\Validator\\Mapping\\Loader\\StaticMethodLoader', 'Symfony\\Component\\Validator\\ConstraintValidatorFactory', 'Symfony\\Component\\Validator\\Validator',
'Symfony\\Component\\Validator\\Mapping\\ClassMetadataFactory', 'Symfony\\Component\\Validator\\ConstraintViolationList'); 'Symfony\\Component\\Validator\\Mapping\\Loader\\StaticMethodLoader',
'Symfony\\Component\\Validator\\ConstraintValidatorFactory',
'Symfony\\Component\\Validator\\Mapping\\ClassMetadataFactory',
'Symfony\\Component\\Validator\\ConstraintViolationList'
);


$script = $this->addLoadValidatorMetadataMethod(); $script = $this->addLoadValidatorMetadataMethod();
$script .= $this->addValidateMethod(); $script .= $this->addValidateMethod();
Expand Down Expand Up @@ -77,7 +81,7 @@ public function getParametersFromColumnName($columnName = null)
$this->cleanupParameters(); $this->cleanupParameters();
foreach ($this->getParameters() as $key => $parameter) { foreach ($this->getParameters() as $key => $parameter) {
if ($parameter['column'] === $columnName) { if ($parameter['column'] === $columnName) {
$array[$key] = $parameter; $array[$key] = $parameter;
} }
} }
} }
Expand Down Expand Up @@ -114,13 +118,16 @@ public function removeParametersFromColumnName($columnName = null)
*/ */
public function addRuleOnPk() public function addRuleOnPk()
{ {
if (count($this->getParameters()) <= 0) { if (!count($this->getParameters())) {
$pk = $this->getTable()->getPrimaryKey(); $pk = $this->getTable()->getPrimaryKey();
$rule['auto_rule']['column'] = $pk[0]->getName(); $parameters = array('auto_rule' => array(
$rule['auto_rule']['validator'] = 'Type'; 'column' => $pk[0]->getName(),
$rule['auto_rule']['options'] = array('type' => $pk[0]->getPhpType()); 'validators' => 'Type',

'options' => array(
$this->setParameters($rule); 'type' => $pk[0]->getPhpType(),
),
));
$this->setParameters($parameters);
} }
} }


Expand Down Expand Up @@ -154,14 +161,14 @@ public function mergeParameters(array $params = null)
*/ */
protected function cleanupParameters() protected function cleanupParameters()
{ {
$parser = new Parser(); $parser = new Parser();
$params = $this->getParameters(); $params = $this->getParameters();
foreach ($params as $key => $value) { foreach ($params as $key => $value) {
if (is_string($value)) { if (is_string($value)) {
$params[$key] = $parser->parse($value); $params[$key] = $parser->parse($value);
} }
} }
$this->setParameters($params); $this->setParameters($params);
} }


/** /**
Expand Down
29 changes: 16 additions & 13 deletions src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
Expand Up @@ -302,10 +302,11 @@ public function declareClassNamespace($class, $namespace = '', $alias = false)
return $this->declareClassNamespace($class, $namespace, 'Child' . $class); return $this->declareClassNamespace($class, $namespace, 'Child' . $class);
} }


throw new LogicException( throw new LogicException(sprintf(
sprintf('The class %s duplicates the class %s and can\'t be used without alias', 'The class %s duplicates the class %s and can\'t be used without alias',
$namespace . '\\' . $class, $this->declaredShortClassesOrAlias[$aliasWanted]) $namespace . '\\' . $class,
); $this->declaredShortClassesOrAlias[$aliasWanted]
));
} }


/** /**
Expand All @@ -324,18 +325,23 @@ protected function needAliasForClassName($class, $namespace)
} }


if (empty($namespace) && 'Base' === $this->getNamespace()) { 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; return true;
} elseif ((false !== strpos($class,'Peer') || false !== strpos($class,'Query'))) { }

if ((false !== strpos($class, 'Peer') || false !== strpos($class, 'Query'))) {
return true; 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; return true;
} }
} }


if ('Base' == $namespace && '' == $this->getNamespace()) { if ('Base' === $namespace && '' === $this->getNamespace()) {
if (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; return true;
} }
Expand Down Expand Up @@ -768,10 +774,7 @@ public function renderTemplate($filename, $vars = array(), $templateDir = '/temp
// try with '.php' at the end // try with '.php' at the end
$filePath = $filePath . '.php'; $filePath = $filePath . '.php';
if (!file_exists($filePath)) { if (!file_exists($filePath)) {
throw new \InvalidArgumentException(sprintf('Template "%s" not found in "%s" directory', throw new \InvalidArgumentException(sprintf('Template "%s" not found in "%s" directory', $filename, __DIR__ . $templateDir));
$filename,
__DIR__ . $templateDir
));
} }
} }
$template = new PropelTemplate(); $template = new PropelTemplate();
Expand Down
16 changes: 11 additions & 5 deletions src/Propel/Generator/Builder/Om/ObjectBuilder.php
Expand Up @@ -236,7 +236,7 @@ abstract class ".$this->getUnqualifiedClassName().$parentClass." implements Acti
if ($interface = $this->getInterface()) { if ($interface = $this->getInterface()) {
$script .= ", Child" . ClassTools::classname($interface); $script .= ", Child" . ClassTools::classname($interface);
if ($interface !== ClassTools::classname($interface)) { if ($interface !== ClassTools::classname($interface)) {
$this->declareClass($interface); $this->declareClass($interface);
} else { } else {
$this->declareClassFromBuilder($this->getInterfaceBuilder()); $this->declareClassFromBuilder($this->getInterfaceBuilder());
} }
Expand Down Expand Up @@ -894,7 +894,10 @@ public function addTemporalAccessorOpen(&$script, Column $column)
} elseif ($column->getType() === PropelTypes::TIMESTAMP) { } elseif ($column->getType() === PropelTypes::TIMESTAMP) {
$defaultfmt = $this->getBuildProperty('defaultTimeStampFormat'); $defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
} }
if (empty($defaultfmt)) { $defaultfmt = null; }
if (empty($defaultfmt)) {
$defaultfmt = null;
}


$script .= " $script .= "
".$visibility." function get$cfc(\$format = ".var_export($defaultfmt, true).""; ".$visibility." function get$cfc(\$format = ".var_export($defaultfmt, true)."";
Expand Down Expand Up @@ -953,7 +956,10 @@ protected function addTemporalAccessorBody(&$script, Column $column)
} elseif ($column->getType() === PropelTypes::TIMESTAMP) { } elseif ($column->getType() === PropelTypes::TIMESTAMP) {
$defaultfmt = $this->getBuildProperty('defaultTimeStampFormat'); $defaultfmt = $this->getBuildProperty('defaultTimeStampFormat');
} }
if (empty($defaultfmt)) { $defaultfmt = null; }
if (empty($defaultfmt)) {
$defaultfmt = null;
}


if ($column->isLazyLoad()) { if ($column->isLazyLoad()) {
$script .= $this->getAccessorLazyLoadSnippet($column); $script .= $this->getAccessorLazyLoadSnippet($column);
Expand Down Expand Up @@ -3300,7 +3306,7 @@ protected function addRefFKGetJoinMethods(&$script, ForeignKey $refFK)


$peerClassName = $this->getClassNameFromBuilder($this->getStubPeerBuilder()); $peerClassName = $this->getClassNameFromBuilder($this->getStubPeerBuilder());
$fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable())); $fkQueryClassName = $this->getClassNameFromBuilder($this->getNewStubQueryBuilder($refFK->getTable()));
$relCol = $this->getRefFKPhpNameAffix($refFK, $plural=true); $relCol = $this->getRefFKPhpNameAffix($refFK, $plural = true);
$collName = $this->getRefFKCollVarName($refFK); $collName = $this->getRefFKCollVarName($refFK);


$fkPeerBuilder = $this->getNewPeerBuilder($tblFK); $fkPeerBuilder = $this->getNewPeerBuilder($tblFK);
Expand Down Expand Up @@ -4324,7 +4330,7 @@ protected function doInsert(ConnectionInterface \$con)
if ($this->getPlatform() instanceof MssqlPlatform) { if ($this->getPlatform() instanceof MssqlPlatform) {
if ($table->hasAutoIncrementPrimaryKey() ) { if ($table->hasAutoIncrementPrimaryKey() ) {
$script .= " $script .= "
\$this->modifiedColumns[] = " . $this->getColumnConstant($table->getAutoIncrementPrimaryKey() ) . ";"; \$this->modifiedColumns[] = " . $this->getColumnConstant($table->getAutoIncrementPrimaryKey()).';';
} }
$script .= " $script .= "
\$criteria = \$this->buildCriteria();"; \$criteria = \$this->buildCriteria();";
Expand Down
8 changes: 4 additions & 4 deletions src/Propel/Generator/Builder/Om/PeerBuilder.php
Expand Up @@ -2082,7 +2082,7 @@ public function addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder
\$criteria->addJoin(%s, %s, \$joinBehavior); \$criteria->addJoin(%s, %s, \$joinBehavior);
", ",
$this->getColumnConstant($table->getColumn($lftCol)), $this->getColumnConstant($table->getColumn($lftCol)),
$joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn($lfMap[$lftCol] )) $joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn($lfMap[$lftCol]))
); );
} else { } else {
// composite foreign key // composite foreign key
Expand All @@ -2094,8 +2094,8 @@ public function addCriteriaJoin($fk, $table, $joinTable, $joinedTablePeerBuilder
" array(%s, %s), " array(%s, %s),
", ",
$this->getColumnConstant($table->getColumn($columnName)), $this->getColumnConstant($table->getColumn($columnName)),
$joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn( $lfMap[$columnName]) $joinedTablePeerBuilder->getColumnConstant($joinTable->getColumn($lfMap[$columnName]))
)); );
} }
$script .= " ), \$joinBehavior); $script .= " ), \$joinBehavior);
"; ";
Expand Down Expand Up @@ -2423,7 +2423,7 @@ public static function doSelectJoinAll(Criteria \$criteria, \$con = null, \$join
"; ";


$index = 1; $index = 1;
foreach ($table->getForeignKeys() as $fk ) { foreach ($table->getForeignKeys() as $fk) {
// want to cover this case, but the code is not there yet. // 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 // Why not? -because we'd have to alias the tables in the JOIN
if ($fk->getForeignTableName() != $table->getName()) { if ($fk->getForeignTableName() != $table->getName()) {
Expand Down
21 changes: 14 additions & 7 deletions src/Propel/Generator/Config/ArrayToPhpConverter.php
Expand Up @@ -25,18 +25,20 @@ class ArrayToPhpConverter
*/ */
public static function convert($c) public static function convert($c)
{ {
$conf = "\$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();"; $conf = "\$serviceContainer = \Propel\Runtime\Propel::getServiceContainer();";
// set datasources // set datasources
if (isset($c['datasources'])) { if (isset($c['datasources'])) {
foreach ($c['datasources'] as $name => $params) { foreach ($c['datasources'] as $name => $params) {
if (!is_array($params)) { if (!is_array($params)) {
continue; continue;
} }

// set adapters // set adapters
if (isset($params['adapter'])) { if (isset($params['adapter'])) {
$conf .= " $conf .= "
\$serviceContainer->setAdapterClass('{$name}', '{$params['adapter']}');"; \$serviceContainer->setAdapterClass('{$name}', '{$params['adapter']}');";
} }

// set connection settings // set connection settings
if (isset($params['slaves'])) { if (isset($params['slaves'])) {
$conf .= " $conf .= "
Expand All @@ -48,15 +50,18 @@ public static function convert($c)
} else { } else {
continue; continue;
} }

if (isset($params['connection'])) { if (isset($params['connection'])) {
$masterConfigurationSetter = isset($params['slaves']) ? 'setWriteConfiguration' : 'setConfiguration'; $masterConfigurationSetter = isset($params['slaves']) ? 'setWriteConfiguration' : 'setConfiguration';
$conf .= " $conf .= "
\$manager->{$masterConfigurationSetter}(". var_export($params['connection'], true) . ");"; \$manager->{$masterConfigurationSetter}(". var_export($params['connection'], true) . ");";
} }

$conf .= " $conf .= "
\$manager->setName('{$name}'); \$manager->setName('{$name}');
\$serviceContainer->setConnectionManager('{$name}', \$manager);"; \$serviceContainer->setConnectionManager('{$name}', \$manager);";
} }

// set default datasource // set default datasource
if (isset($c['datasources']['default'])) { if (isset($c['datasources']['default'])) {
$defaultDatasource = $c['datasources']['default']; $defaultDatasource = $c['datasources']['default'];
Expand All @@ -65,9 +70,11 @@ public static function convert($c)
$datasourceNames = array_keys($c['datasources']); $datasourceNames = array_keys($c['datasources']);
$defaultDatasource = $datasourceNames[0]; $defaultDatasource = $datasourceNames[0];
} }

$conf .= " $conf .= "
\$serviceContainer->setDefaultDatasource('{$defaultDatasource}');"; \$serviceContainer->setDefaultDatasource('{$defaultDatasource}');";
} }

// set profiler // set profiler
if (isset($c['profiler'])) { if (isset($c['profiler'])) {
$profilerConf = $c['profiler']; $profilerConf = $c['profiler'];
Expand All @@ -82,14 +89,15 @@ public static function convert($c)
} }
unset($c['profiler']); unset($c['profiler']);
} }

// set logger // set logger
if (isset($c['log']) && isset($c['log']['logger'])) { if (isset($c['log']) && isset($c['log']['logger'])) {
$loggerConfiguration = $c['log']['logger']; $loggerConfiguration = $c['log']['logger'];
// is it a single logger or a list of loggers? // is it a single logger or a list of loggers?
if (isset($loggerConfiguration[0])) { if (isset($loggerConfiguration[0])) {
foreach ($loggerConfiguration as $singleLoggerConfiguration) { foreach ($loggerConfiguration as $singleLoggerConfiguration) {
$conf .= self::getLoggerCode($singleLoggerConfiguration); $conf .= self::getLoggerCode($singleLoggerConfiguration);
} }
} else { } else {
$conf .= self::getLoggerCode($loggerConfiguration); $conf .= self::getLoggerCode($loggerConfiguration);
} }
Expand All @@ -110,5 +118,4 @@ protected static function getLoggerCode($conf)
return " return "
\$serviceContainer->setLoggerConfiguration('{$name}', " . var_export($conf, true) . ");"; \$serviceContainer->setLoggerConfiguration('{$name}', " . var_export($conf, true) . ");";
} }

} }
4 changes: 2 additions & 2 deletions src/Propel/Generator/Config/XmlToArrayConverter.php
Expand Up @@ -59,7 +59,7 @@ protected static function simpleXmlToArray($xml)
$ar = array(); $ar = array();
foreach ($xml->children() as $k => $v) { foreach ($xml->children() as $k => $v) {
// recurse the child // 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 it's not an array, then it was empty, thus a value/string
if (count($child) == 0) { if (count($child) == 0) {
Expand All @@ -80,7 +80,7 @@ protected static function simpleXmlToArray($xml)


// if the $k is already in our children list, we need to transform // if the $k is already in our children list, we need to transform
// it into an array, else we add it as a value // 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; $ar[$k] = $child;
} else { } else {
// (This only applies to nested nodes that do not have an @id attribute) // (This only applies to nested nodes that do not have an @id attribute)
Expand Down
11 changes: 6 additions & 5 deletions src/Propel/Generator/Model/Column.php
Expand Up @@ -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 * @return boolean
*/ */
public function isPhpArrayType() public function isPhpArrayType()
{ {
return PropelTypes::isPhpArrayType($this->getType()); return PropelTypes::isPhpArrayType($this->getType());
} }


/** /**
* Returns whether or not this column is an ENUM column. * Returns whether or not this column is an ENUM column.
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Model/Diff/TableDiff.php
Expand Up @@ -439,7 +439,7 @@ public function getRemovedIndices()
* *
* @param $modifiedIndices * @param $modifiedIndices
*/ */
public function setModifiedIndices( $modifiedIndices) public function setModifiedIndices($modifiedIndices)
{ {
$this->modifiedIndices = $modifiedIndices; $this->modifiedIndices = $modifiedIndices;
} }
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Model/Inheritance.php
Expand Up @@ -60,7 +60,7 @@ public function getColumn()
* *
* @param Column $column * @param Column $column
*/ */
public function setColumn(Column $column) public function setColumn(Column $column)
{ {
$this->column = $column; $this->column = $column;
} }
Expand Down
4 changes: 2 additions & 2 deletions src/Propel/Generator/Platform/DefaultPlatform.php
Expand Up @@ -558,7 +558,7 @@ public function getIndexDDL(Index $index)
*/ */
public function getUniqueDDL(Unique $unique) public function getUniqueDDL(Unique $unique)
{ {
return sprintf('UNIQUE (%s)' , $this->getColumnListDDL($unique->getColumns())); return sprintf('UNIQUE (%s)', $this->getColumnListDDL($unique->getColumns()));
} }


/** /**
Expand Down Expand Up @@ -1240,7 +1240,7 @@ public function getColumnBindingPHP($column, $identifier, $columnValueAccessor,
" "
\$stmt->bindValue(%s, %s, %s);", \$stmt->bindValue(%s, %s, %s);",
$identifier, $identifier,
$columnValueAccessor , $columnValueAccessor,
PropelTypes::getPdoTypeString($column->getType()) PropelTypes::getPdoTypeString($column->getType())
); );


Expand Down
6 changes: 3 additions & 3 deletions src/Propel/Generator/Platform/MysqlPlatform.php
Expand Up @@ -249,12 +249,12 @@ protected function getTableOptions(Table $table)
); );


foreach ($supportedOptions as $name => $sqlName) { foreach ($supportedOptions as $name => $sqlName) {
$parameterValue = NULL; $parameterValue = null;


if ($vi->hasParameter($name)) { if ($vi->hasParameter($name)) {
$parameterValue = $vi->getParameter( $name ); $parameterValue = $vi->getParameter($name);
} elseif ($vi->hasParameter($sqlName)) { } elseif ($vi->hasParameter($sqlName)) {
$parameterValue = $vi->getParameter( $sqlName ); $parameterValue = $vi->getParameter($sqlName);
} }


// if we have a param value, then parse it out // if we have a param value, then parse it out
Expand Down