1
0
mirror of synced 2024-12-14 07:06:04 +03:00

fix CS and use php constants

This commit is contained in:
Fabio B. Silva 2011-12-24 11:45:51 -02:00
parent 8bdb713073
commit 1eddb53d6c
6 changed files with 51 additions and 49 deletions

View File

@ -23,6 +23,7 @@ use ReflectionClass, ReflectionProperty;
use Doctrine\Common\Persistence\Mapping\ClassMetadata AS IClassMetadata;
use Doctrine\ORM\DefaultNamingStrategy;
use Doctrine\ORM\NamingStrategy;
/**
* A <tt>ClassMetadata</tt> instance holds all the object-relational mapping metadata
* of an entity and it's associations.

View File

@ -30,52 +30,53 @@ namespace Doctrine\ORM;
*/
interface NamingStrategy
{
/**
* Return a table name for an entity class
*
* @param string $className The fully-qualified class name
* @return string A table name
* @param string $className The fully-qualified class name
* @return string A table name
*/
function classToTableName($className);
/**
* Return a column name for a property
*
* @param string $propertyName A property
* @return string A column name
* @param string $propertyName A property
* @return string A column name
*/
function propertyToColumnName($propertyName);
/**
* Return the default reference column name
*
* @return string A column name
* @return string A column name
*/
function referenceColumnName();
/**
* Return a join column name for a property
*
* @param string $propertyName A property
* @return string A column name
* @param string $propertyName A property
* @return string A join column name
*/
function joinColumnName($propertyName);
/**
* Return a join table name
*
* @param string $sourceEntity
* @param string $targetEntity
* @param string $propertyName
* @param string $sourceEntity The source entity
* @param string $targetEntity The target entity
* @param string $propertyName A property
* @return string A join table name
*/
function joinTableName($sourceEntity, $targetEntity, $propertyName = null);
/**
* Return the foreign key column name for the given parameters
*
* @param string $entityName
* @param string $referencedColumnName
* @param string $entityName A entity
* @param string $referencedColumnName A property
* @return string A join column name
*/
function joinKeyColumnName($entityName, $referencedColumnName = null);
}

View File

@ -30,24 +30,23 @@ namespace Doctrine\ORM;
*/
class UnderscoreNamingStrategy implements NamingStrategy
{
const CASE_LOWER = 'lower';
const CASE_UPPER = 'upper';
/**
* @var string
*/
private $case;
/**
* @param string $case
* Underscore naming strategy construct
*
* @param integer $case CASE_LOWER | CASE_UPPER
*/
public function __construct($case = self::CASE_LOWER)
public function __construct($case = CASE_LOWER)
{
$this->case = $case;
}
/**
* @return string
* @return integer
*/
public function getCase()
{
@ -55,7 +54,10 @@ class UnderscoreNamingStrategy implements NamingStrategy
}
/**
* @param string $case
* Sets string case CASE_LOWER | CASE_UPPER
* Alphabetic characters converted to lowercase or uppercase
*
* @param integer $case
*/
public function setCase($case)
{
@ -87,7 +89,7 @@ class UnderscoreNamingStrategy implements NamingStrategy
*/
public function referenceColumnName()
{
return $this->case == self::CASE_UPPER ? 'ID' : 'id';
return $this->case === CASE_UPPER ? 'ID' : 'id';
}
/**
@ -116,17 +118,17 @@ class UnderscoreNamingStrategy implements NamingStrategy
}
/**
* @param string $string
* @return string
* @param string $string
* @return string
*/
private function underscore($string)
{
$string = preg_replace('/(?<=[a-z])([A-Z])/', '_$1', $string);
if ($this->case == self::CASE_UPPER) {
if ($this->case === CASE_UPPER) {
return strtoupper($string);
}
return strtolower($string);
}
}

View File

@ -406,7 +406,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$this->assertInstanceOf('Doctrine\ORM\DefaultNamingStrategy', $em->getConfiguration()->getNamingStrategy());
$em->getConfiguration()->setNamingStrategy(new \Doctrine\ORM\UnderscoreNamingStrategy('upper'));
$em->getConfiguration()->setNamingStrategy(new \Doctrine\ORM\UnderscoreNamingStrategy(CASE_UPPER));
$this->assertInstanceOf('Doctrine\ORM\UnderscoreNamingStrategy', $em->getConfiguration()->getNamingStrategy());
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');

View File

@ -298,7 +298,7 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
*/
public function testUnderscoreNamingStrategyDefaults()
{
$namingStrategy = new \Doctrine\ORM\UnderscoreNamingStrategy(\Doctrine\ORM\UnderscoreNamingStrategy::CASE_UPPER);
$namingStrategy = new \Doctrine\ORM\UnderscoreNamingStrategy(CASE_UPPER);
$oneToOneMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);
$manyToManyMetadata = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress', $namingStrategy);

View File

@ -26,7 +26,7 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
*/
static private function underscoreNamingLower()
{
return new UnderscoreNamingStrategy(UnderscoreNamingStrategy::CASE_LOWER);
return new UnderscoreNamingStrategy(CASE_LOWER);
}
/**
@ -34,7 +34,7 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
*/
static private function underscoreNamingUpper()
{
return new UnderscoreNamingStrategy(UnderscoreNamingStrategy::CASE_UPPER);
return new UnderscoreNamingStrategy(CASE_UPPER);
}
/**
@ -118,9 +118,9 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
/**
* @dataProvider dataPropertyToColumnName
*
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyName
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyName
*/
public function testPropertyToColumnName(NamingStrategy $strategy, $expected, $propertyName)
{
@ -147,10 +147,8 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
/**
* @dataProvider dataReferenceColumnName
*
* @param NamingStrategy $strategy
* @param string $expected
* @param string $joinedColumn
* @param string $joinedTable
* @param NamingStrategy $strategy
* @param string $expected
*/
public function testReferenceColumnName(NamingStrategy $strategy, $expected)
{
@ -186,9 +184,9 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
/**
* @dataProvider dataJoinColumnName
*
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyName
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyName
*/
public function testJoinColumnName(NamingStrategy $strategy, $expected, $propertyName)
{
@ -240,11 +238,11 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
/**
* @dataProvider dataJoinTableName
*
* @param NamingStrategy $strategy
* @param string $expected
* @param string $ownerEntity
* @param string $associatedEntity
* @param string $propertyName
* @param NamingStrategy $strategy
* @param string $expected
* @param string $ownerEntity
* @param string $associatedEntity
* @param string $propertyName
*/
public function testJoinTableName(NamingStrategy $strategy, $expected, $ownerEntity, $associatedEntity, $propertyName = null)
{
@ -287,11 +285,11 @@ class NamingStrategyTest extends \Doctrine\Tests\OrmTestCase
/**
* @dataProvider dataJoinKeyColumnName
*
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyEntityName
* @param string $referencedColumnName
* @param string $propertyName
* @param NamingStrategy $strategy
* @param string $expected
* @param string $propertyEntityName
* @param string $referencedColumnName
* @param string $propertyName
*/
public function testJoinKeyColumnName(NamingStrategy $strategy, $expected, $propertyEntityName, $referencedColumnName = null, $propertyName = null)
{