mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
[Review] CS fixes
This commit is contained in:
parent
5a11a2ea8a
commit
a2167e3ae3
29 changed files with 140 additions and 141 deletions
|
|
@ -1,5 +1,14 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Sylius\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
|
|
|
|||
|
|
@ -12,10 +12,8 @@
|
|||
namespace Sylius\Bundle\CoreBundle\EventListener;
|
||||
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
|
||||
use Sylius\Component\Core\Model\CustomerInterface;
|
||||
use Sylius\Component\Core\Model\ProductInterface;
|
||||
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
|
||||
use Sylius\Component\Review\Calculator\AverageRatingCalculatorInterface;
|
||||
use Sylius\Component\Review\Model\ReviewableInterface;
|
||||
|
|
@ -64,9 +62,9 @@ class CustomerDeleteListener
|
|||
throw new UnexpectedTypeException($author, 'Sylius\Component\Core\Model\CustomerInterface');
|
||||
}
|
||||
|
||||
$reviewSubjectsToRecalculate = array();
|
||||
$reviewSubjectsToRecalculate = [];
|
||||
|
||||
foreach ($this->reviewRepository->findBy(array('author' => $author)) as $review) {
|
||||
foreach ($this->reviewRepository->findBy(['author' => $author]) as $review) {
|
||||
$reviewSubjectsToRecalculate = $this->removeReviewsAndExtractSubject($review, $reviewSubjectsToRecalculate);
|
||||
}
|
||||
$this->reviewManager->flush();
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ namespace Sylius\Bundle\CoreBundle\EventListener;
|
|||
|
||||
use Doctrine\ORM\Event\LifecycleEventArgs;
|
||||
use Sylius\Component\Core\Model\ProductInterface;
|
||||
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -46,7 +45,7 @@ class ProductDeleteListener
|
|||
|
||||
$reviewManager = $args->getEntityManager();
|
||||
$reviewRepository = $this->container->get('sylius.repository.product_review');
|
||||
$reviews = $reviewRepository->findBy(array('reviewSubject' => $product));
|
||||
$reviews = $reviewRepository->findBy(['reviewSubject' => $product]);
|
||||
|
||||
foreach ($reviews as $review) {
|
||||
$reviewManager->remove($review);
|
||||
|
|
|
|||
|
|
@ -29,16 +29,16 @@ class ProductReviewAdminType extends ProductReviewType
|
|||
parent::buildForm($builder, $options);
|
||||
|
||||
$builder
|
||||
->add('reviewSubject', 'entity', array(
|
||||
'class' => 'Sylius\Component\Core\Model\Product',
|
||||
'label' => 'sylius.form.review.product',
|
||||
->add('reviewSubject', 'entity', [
|
||||
'class' => 'Sylius\Component\Core\Model\Product',
|
||||
'label' => 'sylius.form.review.product',
|
||||
'property' => 'name',
|
||||
))
|
||||
->add('author', 'entity', array(
|
||||
'class' => 'Sylius\Component\Core\Model\Customer',
|
||||
'label' => 'sylius.form.review.author',
|
||||
])
|
||||
->add('author', 'entity', [
|
||||
'class' => 'Sylius\Component\Core\Model\Customer',
|
||||
'label' => 'sylius.form.review.author',
|
||||
'property' => 'email',
|
||||
))
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
|
@ -47,11 +47,11 @@ class ProductReviewAdminType extends ProductReviewType
|
|||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'rating_steps' => 5,
|
||||
'data_class' => $this->dataClass,
|
||||
$resolver->setDefaults([
|
||||
'rating_steps' => 5,
|
||||
'data_class' => $this->dataClass,
|
||||
'validation_groups' => $this->validationGroups,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class CustomerDeleteListenerSpec extends ObjectBehavior
|
|||
) {
|
||||
$event->getSubject()->willReturn($author)->shouldBeCalled();
|
||||
|
||||
$reviewRepository->findBy(array('author' => $author))->willReturn(array($review))->shouldBeCalled();
|
||||
$reviewRepository->findBy(['author' => $author])->willReturn([$review])->shouldBeCalled();
|
||||
$review->getReviewSubject()->willReturn($reviewSubject)->shouldBeCalled();
|
||||
|
||||
$reviewManager->remove($review)->shouldBeCalled();
|
||||
|
|
@ -64,6 +64,6 @@ class CustomerDeleteListenerSpec extends ObjectBehavior
|
|||
{
|
||||
$event->getSubject()->willReturn('badObject')->shouldBeCalled();
|
||||
|
||||
$this->shouldThrow(new UnexpectedTypeException('badObject', 'Sylius\Component\Core\Model\CustomerInterface'))->during('removeCustomerReviews', array($event));
|
||||
$this->shouldThrow(new UnexpectedTypeException('badObject', 'Sylius\Component\Core\Model\CustomerInterface'))->during('removeCustomerReviews', [$event]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ use Doctrine\ORM\Event\LifecycleEventArgs;
|
|||
use PhpSpec\ObjectBehavior;
|
||||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
|
||||
use Sylius\Component\Core\Model\Product;
|
||||
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
|
||||
use Sylius\Component\Review\Model\ReviewInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
|
||||
|
|
@ -49,7 +48,7 @@ class ProductDeleteListenerSpec extends ObjectBehavior
|
|||
$args->getEntityManager()->willReturn($reviewManager)->shouldBeCalled();
|
||||
$container->get('sylius.repository.product_review')->willReturn($reviewRepository)->shouldBeCalled();
|
||||
|
||||
$reviewRepository->findBy(array('reviewSubject' => $product))->willReturn(array($review))->shouldBeCalled();
|
||||
$reviewRepository->findBy(['reviewSubject' => $product])->willReturn([$review])->shouldBeCalled();
|
||||
|
||||
$reviewManager->remove($review)->shouldBeCalled();
|
||||
$reviewManager->flush()->shouldBeCalled();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
namespace spec\Sylius\Bundle\CoreBundle\Form\Type;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
/**
|
||||
|
|
@ -22,7 +21,7 @@ class ProductReviewAdminTypeSpec extends ObjectBehavior
|
|||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('dataClass', array('validation_group'), 'product');
|
||||
$this->beConstructedWith('dataClass', ['validation_group'], 'product');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
|
|
@ -38,61 +37,61 @@ class ProductReviewAdminTypeSpec extends ObjectBehavior
|
|||
function it_builds_form(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('rating', 'choice', array(
|
||||
'choices' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5),
|
||||
->add('rating', 'choice', [
|
||||
'choices' => [1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5],
|
||||
'label' => 'sylius.form.review.rating',
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
))
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('author', 'sylius_customer_guest', array(
|
||||
'label' => false,
|
||||
))
|
||||
->add('author', 'sylius_customer_guest', [
|
||||
'label' => false,
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('title', 'text', array(
|
||||
'label' => 'sylius.form.review.title'
|
||||
))
|
||||
->add('title', 'text', [
|
||||
'label' => 'sylius.form.review.title',
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('comment', 'textarea', array(
|
||||
'label' => 'sylius.form.review.comment'
|
||||
))
|
||||
->add('comment', 'textarea', [
|
||||
'label' => 'sylius.form.review.comment',
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('author', 'entity', array(
|
||||
'class' => 'Sylius\Component\Core\Model\Customer',
|
||||
'label' => 'sylius.form.review.author',
|
||||
->add('author', 'entity', [
|
||||
'class' => 'Sylius\Component\Core\Model\Customer',
|
||||
'label' => 'sylius.form.review.author',
|
||||
'property' => 'email',
|
||||
))
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('reviewSubject', 'entity', array(
|
||||
'class' => 'Sylius\Component\Core\Model\Product',
|
||||
'label' => 'sylius.form.review.product',
|
||||
->add('reviewSubject', 'entity', [
|
||||
'class' => 'Sylius\Component\Core\Model\Product',
|
||||
'label' => 'sylius.form.review.product',
|
||||
'property' => 'name',
|
||||
))
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$this->buildForm($builder, array('rating_steps' => 5));
|
||||
$this->buildForm($builder, ['rating_steps' => 5]);
|
||||
}
|
||||
|
||||
function it_has_name()
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ProductReviewTypeSpec extends ObjectBehavior
|
|||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('dataClass', array('validation_group'), 'product');
|
||||
$this->beConstructedWith('dataClass', ['validation_group'], 'product');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
|
|
|
|||
|
|
@ -53,10 +53,10 @@ class ReviewContext extends DefaultContext
|
|||
$review->setRating((int) $reviewHash['rating']);
|
||||
$review->setComment($reviewHash['comment']);
|
||||
|
||||
$product = $this->getRepository('product')->findOneBy(array('name' => $reviewHash['product']));
|
||||
$product = $this->getRepository('product')->findOneBy(['name' => $reviewHash['product']]);
|
||||
$review->setReviewSubject($product);
|
||||
|
||||
$author = $this->getRepository('customer')->findOneBy(array('email' => $reviewHash['author']));
|
||||
$author = $this->getRepository('customer')->findOneBy(['email' => $reviewHash['author']]);
|
||||
$review->setAuthor($author);
|
||||
|
||||
$review->setStatus((isset($reviewHash['status']) && '' !== $reviewHash['status']) ? $reviewHash['status'] : ReviewInterface::STATUS_ACCEPTED);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface;
|
|||
class Configuration implements ConfigurationInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfigTreeBuilder()
|
||||
{
|
||||
|
|
@ -85,11 +85,11 @@ class Configuration implements ConfigurationInterface
|
|||
->children()
|
||||
->arrayNode('default')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius', 'sylius_review'))
|
||||
->defaultValue(['sylius', 'sylius_review'])
|
||||
->end()
|
||||
->arrayNode('admin')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius'))
|
||||
->defaultValue(['sylius'])
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
@ -110,11 +110,11 @@ class Configuration implements ConfigurationInterface
|
|||
->children()
|
||||
->arrayNode('default')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius', 'sylius_review'))
|
||||
->defaultValue(['sylius', 'sylius_review'])
|
||||
->end()
|
||||
->arrayNode('admin')
|
||||
->prototype('scalar')->end()
|
||||
->defaultValue(array('sylius'))
|
||||
->defaultValue(['sylius'])
|
||||
->end()
|
||||
->end()
|
||||
->end()
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SyliusReviewExtension extends AbstractResourceExtension
|
|||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $reviewSubjects = array();
|
||||
private $reviewSubjects = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
@ -45,9 +45,9 @@ class SyliusReviewExtension extends AbstractResourceExtension
|
|||
$this->addProperTagToReviewDeleteListener($subject, $container);
|
||||
}
|
||||
|
||||
$configFiles = array(
|
||||
$configFiles = [
|
||||
'services.xml',
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($configFiles as $configFile) {
|
||||
$loader->load($configFile);
|
||||
|
|
@ -59,7 +59,7 @@ class SyliusReviewExtension extends AbstractResourceExtension
|
|||
*/
|
||||
private function resolveResources(array $resources, ContainerBuilder $container)
|
||||
{
|
||||
$subjects = array();
|
||||
$subjects = [];
|
||||
|
||||
foreach ($resources as $subject => $parameters) {
|
||||
$this->reviewSubjects[] = $subject;
|
||||
|
|
@ -68,7 +68,7 @@ class SyliusReviewExtension extends AbstractResourceExtension
|
|||
|
||||
$container->setParameter('sylius.review.subjects', $subjects);
|
||||
|
||||
$resolvedResources = array();
|
||||
$resolvedResources = [];
|
||||
|
||||
foreach ($resources as $subjectName => $subjectConfig) {
|
||||
foreach ($subjectConfig as $resourceName => $resourceConfig) {
|
||||
|
|
@ -110,6 +110,6 @@ class SyliusReviewExtension extends AbstractResourceExtension
|
|||
}
|
||||
|
||||
$listenerDefinition = $container->getDefinition('sylius.listener.review_delete');
|
||||
$listenerDefinition->addTag('kernel.event_listener', array('event' => 'sylius.'.$resourceName.'_review.post_delete', 'method' => 'recalculateSubjectRating'));
|
||||
$listenerDefinition->addTag('kernel.event_listener', ['event' => 'sylius.'.$resourceName.'_review.post_delete', 'method' => 'recalculateSubjectRating']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,8 +66,8 @@ class LoadMetadataSubscriber implements EventSubscriber
|
|||
'referencedColumnName' => $reviewableEntityMetadata->fieldMappings['id']['columnName'],
|
||||
'nullable' => false,
|
||||
'onDelete' => 'CASCADE',
|
||||
]
|
||||
]
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$reviewerMapping = [
|
||||
|
|
@ -86,7 +86,6 @@ class LoadMetadataSubscriber implements EventSubscriber
|
|||
$metadata->mapManyToOne($reviewerMapping);
|
||||
}
|
||||
|
||||
|
||||
if ($class['subject'] === $metadata->getName()) {
|
||||
$reviewEntity = $class['review']['classes']['model'];
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
namespace Sylius\Bundle\ReviewBundle\Form\Type;
|
||||
|
||||
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType;
|
||||
use Sylius\Bundle\ReviewBundle\Form\Transformer\ReviewerTransformer;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
|
|
@ -32,7 +31,7 @@ class ReviewType extends AbstractResourceType
|
|||
* @param array $validationGroups
|
||||
* @param string $subject
|
||||
*/
|
||||
public function __construct($dataClass, array $validationGroups = array(), $subject)
|
||||
public function __construct($dataClass, array $validationGroups = [], $subject)
|
||||
{
|
||||
$this->subject = $subject;
|
||||
|
||||
|
|
@ -45,21 +44,21 @@ class ReviewType extends AbstractResourceType
|
|||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('rating', 'choice', array(
|
||||
'choices' => $this->createRatingList($options['rating_steps']),
|
||||
'label' => 'sylius.form.review.rating',
|
||||
->add('rating', 'choice', [
|
||||
'choices' => $this->createRatingList($options['rating_steps']),
|
||||
'label' => 'sylius.form.review.rating',
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
))
|
||||
->add('author', 'sylius_customer_guest', array(
|
||||
])
|
||||
->add('author', 'sylius_customer_guest', [
|
||||
'label' => false,
|
||||
))
|
||||
->add('title', 'text', array(
|
||||
'label' => 'sylius.form.review.title',
|
||||
))
|
||||
->add('comment', 'textarea', array(
|
||||
'label' => 'sylius.form.review.comment',
|
||||
))
|
||||
])
|
||||
->add('title', 'text', [
|
||||
'label' => 'sylius.form.review.title',
|
||||
])
|
||||
->add('comment', 'textarea', [
|
||||
'label' => 'sylius.form.review.comment',
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
|
|
@ -68,10 +67,10 @@ class ReviewType extends AbstractResourceType
|
|||
*/
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(array(
|
||||
'rating_steps' => 5,
|
||||
$resolver->setDefaults([
|
||||
'rating_steps' => 5,
|
||||
'validation_groups' => $this->validationGroups,
|
||||
));
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -89,8 +88,8 @@ class ReviewType extends AbstractResourceType
|
|||
*/
|
||||
private function createRatingList($maxRate)
|
||||
{
|
||||
$ratings = array();
|
||||
for ($i = 1; $i <= $maxRate; $i++) {
|
||||
$ratings = [];
|
||||
for ($i = 1; $i <= $maxRate; ++$i) {
|
||||
$ratings[$i] = $i;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ class SyliusReviewBundle extends AbstractResourceBundle
|
|||
*/
|
||||
public static function getSupportedDrivers()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
SyliusResourceBundle::DRIVER_DOCTRINE_ORM,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class UniqueUserEmailValidator extends ConstraintValidator
|
|||
$this->context->addViolationAt(
|
||||
'author',
|
||||
$constraint->message,
|
||||
array(),
|
||||
[],
|
||||
null
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ class LoadMetadataSubscriberSpec extends ObjectBehavior
|
|||
'reviewable' => [
|
||||
'subject' => 'AcmeBundle\Entity\ReviewableModel',
|
||||
'review' => [
|
||||
'classes' => [
|
||||
'classes' => [
|
||||
'model' => 'AcmeBundle\Entity\ReviewModel',
|
||||
],
|
||||
],
|
||||
'reviewer' => [
|
||||
'classes' => [
|
||||
'classes' => [
|
||||
'model' => 'AcmeBundle\Entity\ReviewerModel',
|
||||
],
|
||||
],
|
||||
|
|
@ -47,7 +47,7 @@ class LoadMetadataSubscriberSpec extends ObjectBehavior
|
|||
{
|
||||
$this->shouldHaveType('Sylius\Bundle\ReviewBundle\EventListener\LoadMetadataSubscriber');
|
||||
}
|
||||
|
||||
|
||||
function it_implements_event_subscriber()
|
||||
{
|
||||
$this->shouldImplement('Doctrine\Common\EventSubscriber');
|
||||
|
|
@ -76,10 +76,10 @@ class LoadMetadataSubscriberSpec extends ObjectBehavior
|
|||
$metadata->getName()->willReturn('AcmeBundle\Entity\ReviewModel');
|
||||
|
||||
$metadata->mapManyToOne([
|
||||
'fieldName' => 'reviewSubject',
|
||||
'fieldName' => 'reviewSubject',
|
||||
'targetEntity' => 'AcmeBundle\Entity\ReviewableModel',
|
||||
'inversedBy' => 'reviews',
|
||||
'joinColumns' => [
|
||||
'inversedBy' => 'reviews',
|
||||
'joinColumns' => [
|
||||
[
|
||||
'name' => 'reviewable_id',
|
||||
'referencedColumnName' => 'id',
|
||||
|
|
@ -136,12 +136,12 @@ class LoadMetadataSubscriberSpec extends ObjectBehavior
|
|||
'reviewable' => [
|
||||
'subject' => 'AcmeBundle\Entity\ReviewableModel',
|
||||
'review' => [
|
||||
'classes' => [
|
||||
'classes' => [
|
||||
'model' => 'AcmeBundle\Entity\BadReviewModel',
|
||||
],
|
||||
],
|
||||
'reviewer' => [
|
||||
'classes' => [
|
||||
'classes' => [
|
||||
'model' => 'AcmeBundle\Entity\ReviewerModel',
|
||||
],
|
||||
],
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ class ReviewCreateListenerSpec extends ObjectBehavior
|
|||
{
|
||||
$event->getSubject()->willReturn('badObject')->shouldBeCalled();
|
||||
|
||||
$this->shouldThrow(new UnexpectedTypeException('badObject', 'Sylius\Component\Review\Model\ReviewInterface'))->during('ensureReviewHasAuthor', array($event));
|
||||
$this->shouldThrow(new UnexpectedTypeException('badObject', 'Sylius\Component\Review\Model\ReviewInterface'))->during('ensureReviewHasAuthor', [$event]);
|
||||
}
|
||||
|
||||
function it_does_nothing_if_review_already_has_author(
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class ReviewDeleteListenerSpec extends ObjectBehavior
|
|||
|
||||
$this
|
||||
->shouldThrow(new UnexpectedTypeException('badObject', 'Sylius\Component\Review\Model\ReviewInterface'))
|
||||
->during('recalculateSubjectRating', array($event))
|
||||
->during('recalculateSubjectRating', [$event])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class ReviewerTransformerSpec extends ObjectBehavior
|
|||
|
||||
function it_throws_exception_if_given_value_is_not_reviewer_interface_object()
|
||||
{
|
||||
$this->shouldThrow(new UnexpectedTypeException('badObject', 'Sylius\Component\Review\Model\ReviewerInterface'))->during('transform', array('badObject'));
|
||||
$this->shouldThrow(new UnexpectedTypeException('badObject', 'Sylius\Component\Review\Model\ReviewerInterface'))->during('transform', ['badObject']);
|
||||
}
|
||||
|
||||
function it_reverse_transforms_form_data(ReviewerInterface $author)
|
||||
|
|
@ -62,7 +62,7 @@ class ReviewerTransformerSpec extends ObjectBehavior
|
|||
|
||||
public function getMatchers()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
'beSameAs' => function ($subject, $key) {
|
||||
if (!$subject instanceof ReviewerInterface || !$key instanceof ReviewerInterface) {
|
||||
return false;
|
||||
|
|
@ -70,6 +70,6 @@ class ReviewerTransformerSpec extends ObjectBehavior
|
|||
|
||||
return $subject->getEmail() === $key->getEmail();
|
||||
},
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
namespace spec\Sylius\Bundle\ReviewBundle\Form\Type;
|
||||
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ class ReviewTypeSpec extends ObjectBehavior
|
|||
{
|
||||
function let()
|
||||
{
|
||||
$this->beConstructedWith('dataClass', array('validation_group'), 'subject');
|
||||
$this->beConstructedWith('dataClass', ['validation_group'], 'subject');
|
||||
}
|
||||
|
||||
function it_is_initializable()
|
||||
|
|
@ -39,50 +38,50 @@ class ReviewTypeSpec extends ObjectBehavior
|
|||
function it_builds_form(FormBuilderInterface $builder)
|
||||
{
|
||||
$builder
|
||||
->add('rating', 'choice', array(
|
||||
'choices' => array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5),
|
||||
'label' => 'sylius.form.review.rating',
|
||||
->add('rating', 'choice', [
|
||||
'choices' => [1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5],
|
||||
'label' => 'sylius.form.review.rating',
|
||||
'expanded' => true,
|
||||
'multiple' => false,
|
||||
))
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('author', 'sylius_customer_guest', array(
|
||||
'label' => false,
|
||||
))
|
||||
->add('author', 'sylius_customer_guest', [
|
||||
'label' => false,
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('title', 'text', array(
|
||||
'label' => 'sylius.form.review.title'
|
||||
))
|
||||
->add('title', 'text', [
|
||||
'label' => 'sylius.form.review.title',
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$builder
|
||||
->add('comment', 'textarea', array(
|
||||
'label' => 'sylius.form.review.comment'
|
||||
))
|
||||
->add('comment', 'textarea', [
|
||||
'label' => 'sylius.form.review.comment',
|
||||
])
|
||||
->willReturn($builder)
|
||||
->shouldBeCalled()
|
||||
;
|
||||
|
||||
$this->buildForm($builder, array('rating_steps' => 5));
|
||||
$this->buildForm($builder, ['rating_steps' => 5]);
|
||||
}
|
||||
|
||||
function it_sets_default_options(OptionsResolverInterface $resolver)
|
||||
{
|
||||
$resolver->setDefaults(
|
||||
array(
|
||||
'rating_steps' => 5,
|
||||
'validation_groups' => array('validation_group'),
|
||||
)
|
||||
[
|
||||
'rating_steps' => 5,
|
||||
'validation_groups' => ['validation_group'],
|
||||
]
|
||||
)->shouldBeCalled();
|
||||
|
||||
$this->setDefaultOptions($resolver);
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class UniqueUserEmailValidatorSpec extends ObjectBehavior
|
|||
$userRepository->findOneByEmail('john.doe@example.com')->willReturn($existingUser)->shouldBeCalled();
|
||||
$constraint->message = 'This email is already registered. Please log in.';
|
||||
|
||||
$context->addViolationAt('author', 'This email is already registered. Please log in.', array(), null)->shouldBeCalled();
|
||||
$context->addViolationAt('author', 'This email is already registered. Please log in.', [], null)->shouldBeCalled();
|
||||
|
||||
$this->validate($review, $constraint);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ class GuestCustomerFormSubscriber implements EventSubscriberInterface
|
|||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
return [
|
||||
FormEvents::PRE_SUBMIT => 'preSubmit',
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -71,7 +71,7 @@ class GuestCustomerFormSubscriber implements EventSubscriberInterface
|
|||
$form = $event->getForm();
|
||||
|
||||
if (null == $rawData) {
|
||||
$rawData = array();
|
||||
$rawData = [];
|
||||
}
|
||||
|
||||
$customer = $this->getCustomerFromProperSource($rawData, $form);
|
||||
|
|
@ -106,7 +106,7 @@ class GuestCustomerFormSubscriber implements EventSubscriberInterface
|
|||
*/
|
||||
protected function createCustomerIfNecessary($email)
|
||||
{
|
||||
$customer = $this->customerRepository->findOneBy(array('email' => $email));
|
||||
$customer = $this->customerRepository->findOneBy(['email' => $email]);
|
||||
|
||||
// if this email is already a registered user, do not assign this customer (force login)
|
||||
if (null !== $customer && null !== $customer->getUser()) {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
namespace Sylius\Bundle\UserBundle\Validator\Constraints;
|
||||
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Sylius\Component\User\Context\CustomerContextInterface;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class GuestCustomerFormSubscriberSpec extends ObjectBehavior
|
|||
FormEvent $event,
|
||||
FormInterface $form
|
||||
) {
|
||||
$event->getData()->willReturn(array('email' => null));
|
||||
$event->getData()->willReturn(['email' => null]);
|
||||
$event->getForm()->willReturn($form);
|
||||
|
||||
$customerContext->getCustomer()->willReturn($customer);
|
||||
|
|
@ -65,11 +65,11 @@ class GuestCustomerFormSubscriberSpec extends ObjectBehavior
|
|||
FormEvent $event,
|
||||
FormInterface $form
|
||||
) {
|
||||
$event->getData()->willReturn(array('email' => 'john.doe@example.com'));
|
||||
$event->getData()->willReturn(['email' => 'john.doe@example.com']);
|
||||
$event->getForm()->willReturn($form);
|
||||
|
||||
$customerContext->getCustomer()->willReturn(null);
|
||||
$customerRepository->findOneBy(array('email' => 'john.doe@example.com'))->willReturn(null);
|
||||
$customerRepository->findOneBy(['email' => 'john.doe@example.com'])->willReturn(null);
|
||||
|
||||
$customerFactory->createNew()->willReturn($customer);
|
||||
$customer->setEmail('john.doe@example.com')->shouldBeCalled();
|
||||
|
|
@ -84,7 +84,7 @@ class GuestCustomerFormSubscriberSpec extends ObjectBehavior
|
|||
FormEvent $event,
|
||||
FormInterface $form
|
||||
) {
|
||||
$event->getData()->willReturn(array());
|
||||
$event->getData()->willReturn([]);
|
||||
$event->getForm()->willReturn($form);
|
||||
|
||||
$customerContext->getCustomer()->willReturn(null);
|
||||
|
|
@ -102,11 +102,11 @@ class GuestCustomerFormSubscriberSpec extends ObjectBehavior
|
|||
FormInterface $form,
|
||||
UserInterface $user
|
||||
) {
|
||||
$event->getData()->willReturn(array('email' => 'john.doe@example.com'));
|
||||
$event->getData()->willReturn(['email' => 'john.doe@example.com']);
|
||||
$event->getForm()->willReturn($form);
|
||||
|
||||
$customerContext->getCustomer()->willReturn(null);
|
||||
$customerRepository->findOneBy(array('email' => 'john.doe@example.com'))->willReturn($customer);
|
||||
$customerRepository->findOneBy(['email' => 'john.doe@example.com'])->willReturn($customer);
|
||||
$customer->getUser()->willReturn($user);
|
||||
|
||||
$form->setData(null);
|
||||
|
|
|
|||
|
|
@ -384,10 +384,10 @@ class BackendMenuBuilder extends MenuBuilder
|
|||
->setLabel($this->translate(sprintf('sylius.backend.menu.%s.review', $section)))
|
||||
;
|
||||
|
||||
$child->addChild('reviews', array(
|
||||
'route' => 'sylius_backend_product_review_index',
|
||||
'labelAttributes' => array('icon' => 'glyphicon glyphicon-pencil'),
|
||||
))->setLabel($this->translate(sprintf('sylius.backend.menu.%s.product_review', $section)));
|
||||
$child->addChild('reviews', [
|
||||
'route' => 'sylius_backend_product_review_index',
|
||||
'labelAttributes' => ['icon' => 'glyphicon glyphicon-pencil'],
|
||||
])->setLabel($this->translate(sprintf('sylius.backend.menu.%s.product_review', $section)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class AverageRatingCalculator implements AverageRatingCalculatorInterface
|
|||
|
||||
foreach ($reviews as $review) {
|
||||
if (ReviewInterface::STATUS_ACCEPTED === $review->getStatus()) {
|
||||
$reviewsNumber++;
|
||||
++$reviewsNumber;
|
||||
|
||||
$sum = $sum + $review->getRating();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace Sylius\Component\Review\Model;
|
|||
class Review implements ReviewInterface
|
||||
{
|
||||
/**
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ class Review implements ReviewInterface
|
|||
protected $title;
|
||||
|
||||
/**
|
||||
* @var integer
|
||||
* @var int
|
||||
*/
|
||||
protected $rating;
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ interface ReviewInterface extends TimestampableInterface, ResourceInterface
|
|||
{
|
||||
const REVIEW_STATE_MACHINE_GRAPH = 'sylius_review';
|
||||
|
||||
const STATUS_NEW = 'new';
|
||||
const STATUS_NEW = 'new';
|
||||
const STATUS_ACCEPTED = 'accepted';
|
||||
const STATUS_REJECTED = 'rejected';
|
||||
|
||||
|
|
@ -38,12 +38,12 @@ interface ReviewInterface extends TimestampableInterface, ResourceInterface
|
|||
public function getTitle();
|
||||
|
||||
/**
|
||||
* @param integer $rating
|
||||
* @param int $rating
|
||||
*/
|
||||
public function setRating($rating);
|
||||
|
||||
/**
|
||||
* @return integer
|
||||
* @return int
|
||||
*/
|
||||
public function getRating();
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ namespace spec\Sylius\Component\Review\Calculator;
|
|||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Component\Review\Model\ReviewableInterface;
|
||||
use Sylius\Component\Review\Model\ReviewInterface;
|
||||
|
||||
|
|
@ -60,7 +59,7 @@ class AverageRatingCalculatorSpec extends ObjectBehavior
|
|||
|
||||
function it_returns_zero_if_given_reviewable_object_has_no_reviews(ReviewableInterface $reviewable)
|
||||
{
|
||||
$reviewable->getReviews()->willReturn(array())->shouldBeCalled();
|
||||
$reviewable->getReviews()->willReturn([])->shouldBeCalled();
|
||||
|
||||
$this->calculate($reviewable)->shouldReturn(0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue