From bb4618c101e8cda1419414688fa3020b3dfb40c6 Mon Sep 17 00:00:00 2001 From: Tim Nagel Date: Fri, 13 Mar 2015 19:34:56 +1100 Subject: [PATCH] Even more QA --- Event/IndexEvent.php | 38 +++++++++++++++++++ Event/IndexPopulateEvent.php | 20 ++-------- Event/IndexResetEvent.php | 22 ++--------- Event/TypeResetEvent.php | 18 ++------- Propel/Provider.php | 2 +- Provider/AbstractProvider.php | 2 +- Serializer/Callback.php | 4 +- Tests/Persister/ObjectPersisterTest.php | 2 +- .../ObjectSerializerPersisterTest.php | 2 +- Tests/RepositoryTest.php | 4 +- .../ModelToElasticaAutoTransformerTest.php | 2 +- ...delToElasticaIdentifierTransformerTest.php | 2 +- 12 files changed, 58 insertions(+), 60 deletions(-) create mode 100644 Event/IndexEvent.php diff --git a/Event/IndexEvent.php b/Event/IndexEvent.php new file mode 100644 index 0000000..ed71d78 --- /dev/null +++ b/Event/IndexEvent.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace FOS\ElasticaBundle\Event; + +use Symfony\Component\EventDispatcher\Event; + +class IndexEvent extends Event +{ + /** + * @var string + */ + private $index; + + /** + * @param string $index + */ + public function __construct($index) + { + $this->index = $index; + } + + /** + * @return string + */ + public function getIndex() + { + return $this->index; + } +} diff --git a/Event/IndexPopulateEvent.php b/Event/IndexPopulateEvent.php index ab61f0a..b35105a 100644 --- a/Event/IndexPopulateEvent.php +++ b/Event/IndexPopulateEvent.php @@ -11,23 +11,16 @@ namespace FOS\ElasticaBundle\Event; -use Symfony\Component\EventDispatcher\Event; - /** * Index Populate Event. * * @author Oleg Andreyev */ -class IndexPopulateEvent extends Event +class IndexPopulateEvent extends IndexEvent { const PRE_INDEX_POPULATE = 'elastica.index.index_pre_populate'; const POST_INDEX_POPULATE = 'elastica.index.index_post_populate'; - /** - * @var string - */ - private $index; - /** * @var bool */ @@ -45,19 +38,12 @@ class IndexPopulateEvent extends Event */ public function __construct($index, $reset, $options) { - $this->index = $index; + parent::__construct($index); + $this->reset = $reset; $this->options = $options; } - /** - * @return string - */ - public function getIndex() - { - return $this->index; - } - /** * @return boolean */ diff --git a/Event/IndexResetEvent.php b/Event/IndexResetEvent.php index 3fb3625..871915a 100644 --- a/Event/IndexResetEvent.php +++ b/Event/IndexResetEvent.php @@ -11,14 +11,12 @@ namespace FOS\ElasticaBundle\Event; -use Symfony\Component\EventDispatcher\Event; - /** * Index ResetEvent. * * @author Oleg Andreyev */ -class IndexResetEvent extends Event +class IndexResetEvent extends IndexEvent { const PRE_INDEX_RESET = 'elastica.index.pre_reset'; const POST_INDEX_RESET = 'elastica.index.post_reset'; @@ -28,11 +26,6 @@ class IndexResetEvent extends Event */ private $force; - /** - * @var string - */ - private $index; - /** * @var bool */ @@ -45,17 +38,10 @@ class IndexResetEvent extends Event */ public function __construct($index, $populating, $force) { - $this->force = $force; - $this->index = $index; - $this->populating = $populating; - } + parent::__construct($index); - /** - * @return string - */ - public function getIndex() - { - return $this->index; + $this->force = $force; + $this->populating = $populating; } /** diff --git a/Event/TypeResetEvent.php b/Event/TypeResetEvent.php index 0b21a06..98fa2f4 100644 --- a/Event/TypeResetEvent.php +++ b/Event/TypeResetEvent.php @@ -18,16 +18,11 @@ use Symfony\Component\EventDispatcher\Event; * * @author Oleg Andreyev */ -class TypeResetEvent extends Event +class TypeResetEvent extends IndexEvent { const PRE_TYPE_RESET = 'elastica.index.type_pre_reset'; const POST_TYPE_RESET = 'elastica.index.type_post_reset'; - /** - * @var string - */ - private $index; - /** * @var string */ @@ -39,16 +34,9 @@ class TypeResetEvent extends Event */ public function __construct($index, $type) { - $this->type = $type; - $this->index = $index; - } + parent::__construct($index); - /** - * @return string - */ - public function getIndex() - { - return $this->index; + $this->type = $type; } /** diff --git a/Propel/Provider.php b/Propel/Provider.php index f8397f9..f28faa4 100644 --- a/Propel/Provider.php +++ b/Propel/Provider.php @@ -30,7 +30,7 @@ class Provider extends AbstractProvider ->getArrayCopy(); $objects = array_filter($objects, array($this, 'isObjectIndexable')); - if ($objects) { + if (!empty($objects)) { $this->objectPersister->insertMany($objects); } diff --git a/Provider/AbstractProvider.php b/Provider/AbstractProvider.php index 05fa525..a743d17 100644 --- a/Provider/AbstractProvider.php +++ b/Provider/AbstractProvider.php @@ -25,7 +25,7 @@ abstract class AbstractProvider implements ProviderInterface protected $options; /** - * @var Indexable + * @var IndexableInterface */ private $indexable; diff --git a/Serializer/Callback.php b/Serializer/Callback.php index 004d133..61da997 100644 --- a/Serializer/Callback.php +++ b/Serializer/Callback.php @@ -8,7 +8,7 @@ use JMS\Serializer\SerializerInterface; class Callback { protected $serializer; - protected $groups; + protected $groups = array(); protected $version; public function setSerializer($serializer) @@ -41,7 +41,7 @@ class Callback { $context = $this->serializer instanceof SerializerInterface ? SerializationContext::create()->enableMaxDepthChecks() : array(); - if ($this->groups) { + if (!empty($this->groups)) { $context->setGroups($this->groups); } diff --git a/Tests/Persister/ObjectPersisterTest.php b/Tests/Persister/ObjectPersisterTest.php index c3da687..06039f0 100644 --- a/Tests/Persister/ObjectPersisterTest.php +++ b/Tests/Persister/ObjectPersisterTest.php @@ -203,7 +203,7 @@ class ObjectPersisterTest extends \PHPUnit_Framework_TestCase private function getTransformer() { $transformer = new ModelToElasticaAutoTransformer(); - $transformer->setPropertyAccessor(PropertyAccess::getPropertyAccessor()); + $transformer->setPropertyAccessor(PropertyAccess::createPropertyAccessor()); return $transformer; } diff --git a/Tests/Persister/ObjectSerializerPersisterTest.php b/Tests/Persister/ObjectSerializerPersisterTest.php index 0b348d1..0536d06 100644 --- a/Tests/Persister/ObjectSerializerPersisterTest.php +++ b/Tests/Persister/ObjectSerializerPersisterTest.php @@ -112,7 +112,7 @@ class ObjectSerializerPersisterTest extends \PHPUnit_Framework_TestCase private function getTransformer() { $transformer = new ModelToElasticaIdentifierTransformer(); - $transformer->setPropertyAccessor(PropertyAccess::getPropertyAccessor()); + $transformer->setPropertyAccessor(PropertyAccess::createPropertyAccessor()); return $transformer; } diff --git a/Tests/RepositoryTest.php b/Tests/RepositoryTest.php index 3f0509a..7702af2 100644 --- a/Tests/RepositoryTest.php +++ b/Tests/RepositoryTest.php @@ -57,10 +57,10 @@ class RepositoryTest extends \PHPUnit_Framework_TestCase /** * @param string $testQuery - * @param int $testLimit + * @param mixed $testLimit * @param string $method * - * @return \FOS\ElasticaBundle\Finder\TransformedFinder|\PHPUnit_Framework_MockObject_MockObject + * @return \FOS\ElasticaBundle\Finder\TransformedFinder */ private function getFinderMock($testQuery, $testLimit = null, $method = 'find') { diff --git a/Tests/Transformer/ModelToElasticaAutoTransformerTest.php b/Tests/Transformer/ModelToElasticaAutoTransformerTest.php index 8d07aeb..f45134e 100644 --- a/Tests/Transformer/ModelToElasticaAutoTransformerTest.php +++ b/Tests/Transformer/ModelToElasticaAutoTransformerTest.php @@ -417,7 +417,7 @@ class ModelToElasticaAutoTransformerTest extends \PHPUnit_Framework_TestCase private function getTransformer($dispatcher = null) { $transformer = new ModelToElasticaAutoTransformer(array(), $dispatcher); - $transformer->setPropertyAccessor(PropertyAccess::getPropertyAccessor()); + $transformer->setPropertyAccessor(PropertyAccess::createPropertyAccessor()); return $transformer; } diff --git a/Tests/Transformer/ModelToElasticaIdentifierTransformerTest.php b/Tests/Transformer/ModelToElasticaIdentifierTransformerTest.php index 14d678e..aa3d7b7 100644 --- a/Tests/Transformer/ModelToElasticaIdentifierTransformerTest.php +++ b/Tests/Transformer/ModelToElasticaIdentifierTransformerTest.php @@ -51,7 +51,7 @@ class ModelToElasticaIdentifierTransformerTest extends \PHPUnit_Framework_TestCa private function getTransformer() { $transformer = new ModelToElasticaIdentifierTransformer(); - $transformer->setPropertyAccessor(PropertyAccess::getPropertyAccessor()); + $transformer->setPropertyAccessor(PropertyAccess::createPropertyAccessor()); return $transformer; }