Skip to content

Commit

Permalink
Fixed issues according to code review.
Browse files Browse the repository at this point in the history
  • Loading branch information
Spea committed Dec 18, 2012
1 parent 083a2a9 commit daad766
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $dumper->dump('/your/workspace/src/Acme/DemoBundle/DataFixtures/ORM', 'array');

#### Options

`Dumper#dump` accepts a third `$options` argument that is an array
`AbstractDumper#dump` accepts a third `$options` argument that is an array
with the following keys:

- namespace: The namespace for the generated class to use
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
*
* @author Martin Parsiegla <[email protected]>
*/
abstract class Dumper
abstract class AbstractDumper
{

/**
* @var Generator\AbstractGenerator
* @var \PhpCollection\MapInterface
*/
protected $generator;
protected $generators;

/**
* @var \Doctrine\Common\Persistence\ObjectManager
Expand Down Expand Up @@ -104,7 +105,7 @@ public function setDumpMultipleFiles($dumpMultipleFiles)
/**
* @return bool
*/
public function getDumpMultipleFiles()
public function shouldDumpMultipleFiles()
{
return $this->dumpMultipleFiles;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sp/FixtureDumper/Converter/DefaultNavigator.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(HandlerRegistryInterface $handlerRegistry, $format)
* @param mixed $value
* @param null|string $type
*
* @return string
* @return mixed
*/
public function accept(VisitorInterface $visitor, $value, $type = null)
{
Expand Down
17 changes: 9 additions & 8 deletions src/Sp/FixtureDumper/Generator/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
abstract class AbstractGenerator
{
/**
* @var NamingStrategy
* @var NamingStrategyInterface
*/
protected $namingStrategy;

Expand All @@ -50,12 +50,13 @@ abstract class AbstractGenerator
*/
protected $models;


/**
* @param \Doctrine\Common\Persistence\ObjectManager $manager
* @param NamingStrategy $namingStrategy
* @param \Sp\FixtureDumper\Converter\VisitorInterface $visitor
* @param \Doctrine\Common\Persistence\ObjectManager $manager
* @param NamingStrategyInterface|null $namingStrategy
* @param \Sp\FixtureDumper\Converter\VisitorInterface|null $visitor
*/
public function __construct(ObjectManager $manager, NamingStrategy $namingStrategy = null, VisitorInterface $visitor = null)
public function __construct(ObjectManager $manager, NamingStrategyInterface $namingStrategy = null, VisitorInterface $visitor = null)
{
$this->manager = $manager;
$this->namingStrategy = $namingStrategy ?: $this->getDefaultNamingStrategy();
Expand All @@ -64,7 +65,7 @@ public function __construct(ObjectManager $manager, NamingStrategy $namingStrate

/**
* @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata
* @param array $models
* @param array|null $models
* @param array $options
*
* @return string
Expand Down Expand Up @@ -191,15 +192,15 @@ public function getManager()
}

/**
* @param \Sp\FixtureDumper\Generator\NamingStrategy $namingStrategy
* @param \Sp\FixtureDumper\Generator\NamingStrategyInterface $namingStrategy
*/
public function setNamingStrategy($namingStrategy)
{
$this->namingStrategy = $namingStrategy;
}

/**
* @return \Sp\FixtureDumper\Generator\NamingStrategy
* @return \Sp\FixtureDumper\Generator\NamingStrategyInterface
*/
public function getNamingStrategy()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected function prepareData(ClassMetadata $metadata, array $data)
*
* @param mixed $value
*
* @return string
* @return object|integer|double|string|null|boolean
*/
protected function convertValue($value)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Sp/FixtureDumper/Generator/ClassFixtureGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ protected function addDependentFixtureInterface(PhpClass $class, ClassMetadata $
$method = PhpMethod::create('getDependencies');

$writer->writeln("return array(");
$assocCount = count($metadata->getAssociationNames());
$associations = array();
foreach ($metadata->getAssociationNames() as $assocName) {
$targetClass = $metadata->getAssociationTargetClass($assocName);
Expand Down Expand Up @@ -193,7 +192,7 @@ protected function setDefaultOptions(OptionsResolver $resolver)
* @param mixed $obj
* @param string $key
*
* @return string
* @return string|null
*/
private function findAdderMethod($obj, $key)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sp/FixtureDumper/Generator/DefaultNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Martin Parsiegla <[email protected]>
*/
class DefaultNamingStrategy implements NamingStrategy
class DefaultNamingStrategy implements NamingStrategyInterface
{
/**
* {@inheritdoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author Martin Parsiegla <[email protected]>
*/
interface NamingStrategy
interface NamingStrategyInterface
{
/**
* Return a fixture class name for the given model class name.
Expand Down
9 changes: 5 additions & 4 deletions src/Sp/FixtureDumper/Mapping/MongoDB/ClassMetadataProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use InvalidArgumentException;
use Doctrine\Common\Persistence\Mapping\ClassMetadata;
use \Doctrine\ODM\MongoDB\Mapping\ClassMetadata as BaseClassMetadata;

/**
* @author Martin Parsiegla <[email protected]>
Expand All @@ -30,7 +31,7 @@ class ClassMetadataProxy implements ClassMetadata
public $origFieldMappings;

/**
* @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo
* @var \Doctrine\ODM\MongoDB\Mapping\ClassMetadata
*/
protected $classMetadata;

Expand All @@ -50,9 +51,9 @@ class ClassMetadataProxy implements ClassMetadata
protected $associationMappings = array();

/**
* @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo $classMetadata
* @param \Doctrine\ODM\MongoDB\Mapping\ClassMetadata $classMetadata
*/
public function __construct(ClassMetadata $classMetadata)
public function __construct(BaseClassMetadata $classMetadata)
{
$this->name = $classMetadata->name;
$this->origFieldMappings = $classMetadata->fieldMappings;
Expand Down Expand Up @@ -97,7 +98,7 @@ public function getFieldNames()
* Initialize the mappings from the class metadata.
* The mapping will be split in field mappings and association mappings.
*
* @return MongoODMClassMetadataProxy
* @return \Sp\FixtureDumper\Mapping\MongoDB\ClassMetadataProxy
*/
protected function initMappings()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Sp/FixtureDumper/MongoDBDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Martin Parsiegla <[email protected]>
*/
class MongoDBDumper extends Dumper
class MongoDBDumper extends AbstractDumper
{
/**
* {@inheritdoc}
Expand Down Expand Up @@ -87,6 +87,7 @@ private function addDependencies(ClassMetadataProxy $class, CommitOrderCalculato
continue;
}

$newNodes = array();
foreach ($targetClass->subClasses as $subClassName) {
$targetSubClass = $this->dm->getClassMetadata($subClassName);

Expand Down
2 changes: 1 addition & 1 deletion src/Sp/FixtureDumper/ORMDumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author Martin Parsiegla <[email protected]>
*/
class ORMDumper extends Dumper
class ORMDumper extends AbstractDumper
{
protected function getDumpOrder(array $classes)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sp/FixtureDumper/Util/ClassUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @author Martin Parsiegla <[email protected]>
*/
class ClassUtils
final class ClassUtils
{
private function __construct()
{}
Expand Down
2 changes: 1 addition & 1 deletion tests/Sp/FixtureDumper/Tests/DumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function setUp()
$this->manager = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
$this->generator = $this->getMockBuilder('Sp\FixtureDumper\Generator\AbstractGenerator')->disableOriginalConstructor()->setMethods(array('generate', 'setNavigator'))->getMockForAbstractClass();
$this->handlerRegistry = $this->getMock('Sp\FixtureDumper\Converter\Handler\HandlerRegistryInterface');
$this->dumper = $this->getMockForAbstractClass('Sp\FixtureDumper\Dumper', array($this->manager, $this->handlerRegistry, new Map(array('php' => $this->generator))), '', true, true, true, array('writeFixture', 'getAllMetadata'));
$this->dumper = $this->getMockForAbstractClass('Sp\FixtureDumper\AbstractDumper', array($this->manager, $this->handlerRegistry, new Map(array('php' => $this->generator))), '', true, true, true, array('writeFixture', 'getAllMetadata'));

$this->dumper->expects($this->once())->method('getAllMetadata')->will($this->returnValue($this->metadata));
$this->dumper->expects($this->once())->method('getDumpOrder')->will($this->returnValue($this->metadata));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ protected function getOptions()

protected function setUp()
{
$this->namingStrategy = $this->getMock('Sp\FixtureDumper\Generator\NamingStrategy');
$this->namingStrategy = $this->getMock('Sp\FixtureDumper\Generator\NamingStrategyInterface');
$this->manager = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
$this->metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
$this->repository = $this->getMock('Doctrine\Common\Persistence\ObjectRepository');
Expand Down

0 comments on commit daad766

Please sign in to comment.