Skip to content

Commit

Permalink
Merge pull request Sylius#8447 from pamil/scalar-types/taxonomy
Browse files Browse the repository at this point in the history
[Taxonomy] Use typehints introduced by PHP7+
  • Loading branch information
Zales0123 committed Aug 24, 2017
2 parents 7433564 + 4d330b4 commit b80ab40
Show file tree
Hide file tree
Showing 23 changed files with 175 additions and 233 deletions.
4 changes: 4 additions & 0 deletions UPGRADE.md
Expand Up @@ -80,6 +80,10 @@
* `TranslationInterface::setTranslatable`
* `Archivable::setArchivedAt`
* `SlugAwareInterface::setSlug`

### Taxonomy / TaxonomyBundle

* `TaxonInterface::getParents` method was removed (taxon has at most one parent).

### Shipping / ShippingBundle

Expand Down
Expand Up @@ -19,6 +19,7 @@
use Sylius\Component\Taxonomy\Model\TaxonInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

final class TaxonSlugController
{
Expand All @@ -44,9 +45,9 @@ public function __construct(
/**
* @param Request $request
*
* @return JsonResponse
* @return Response
*/
public function generateAction(Request $request)
public function generateAction(Request $request): Response
{
$name = $request->query->get('name');
$locale = $request->query->get('locale');
Expand Down
Expand Up @@ -38,7 +38,7 @@ final class Configuration implements ConfigurationInterface
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('sylius_taxonomy');
Expand All @@ -58,7 +58,7 @@ public function getConfigTreeBuilder()
/**
* @param ArrayNodeDefinition $node
*/
private function addResourcesSection(ArrayNodeDefinition $node)
private function addResourcesSection(ArrayNodeDefinition $node): void
{
$node
->children()
Expand Down
Expand Up @@ -26,7 +26,7 @@ final class SyliusTaxonomyExtension extends AbstractResourceExtension
/**
* {@inheritdoc}
*/
public function load(array $config, ContainerBuilder $container)
public function load(array $config, ContainerBuilder $container): void
{
$config = $this->processConfiguration($this->getConfiguration([], $container), $config);
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
Expand Down
Expand Up @@ -15,6 +15,7 @@

use Doctrine\ORM\QueryBuilder;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Component\Taxonomy\Model\TaxonInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;

/**
Expand All @@ -25,7 +26,7 @@ class TaxonRepository extends EntityRepository implements TaxonRepositoryInterfa
/**
* {@inheritdoc}
*/
public function findChildren($parentCode, $locale = null)
public function findChildren(string $parentCode, ?string $locale = null): array
{
return $this->createTranslationBasedQueryBuilder($locale)
->addSelect('child')
Expand All @@ -42,7 +43,7 @@ public function findChildren($parentCode, $locale = null)
/**
* {@inheritdoc}
*/
public function findOneBySlug($slug, $locale)
public function findOneBySlug(string $slug, string $locale): ?TaxonInterface
{
return $this->createQueryBuilder('o')
->addSelect('translation')
Expand All @@ -59,7 +60,7 @@ public function findOneBySlug($slug, $locale)
/**
* {@inheritdoc}
*/
public function findByName($name, $locale)
public function findByName(string $name, string $locale): array
{
return $this->createQueryBuilder('o')
->addSelect('translation')
Expand All @@ -76,7 +77,7 @@ public function findByName($name, $locale)
/**
* {@inheritdoc}
*/
public function findRootNodes()
public function findRootNodes(): array
{
return $this->createQueryBuilder('o')
->andWhere('o.parent IS NULL')
Expand All @@ -89,7 +90,7 @@ public function findRootNodes()
/**
* {@inheritdoc}
*/
public function findByNamePart($phrase, $locale = null)
public function findByNamePart(string $phrase, ?string $locale = null): array
{
return $this->createTranslationBasedQueryBuilder($locale)
->andWhere('translation.name LIKE :name')
Expand All @@ -102,7 +103,7 @@ public function findByNamePart($phrase, $locale = null)
/**
* {@inheritdoc}
*/
public function createListQueryBuilder()
public function createListQueryBuilder(): QueryBuilder
{
return $this->createQueryBuilder('o')->leftJoin('o.translations', 'translation');
}
Expand All @@ -112,7 +113,7 @@ public function createListQueryBuilder()
*
* @return QueryBuilder
*/
private function createTranslationBasedQueryBuilder($locale)
private function createTranslationBasedQueryBuilder(?string $locale): QueryBuilder
{
$queryBuilder = $this->createQueryBuilder('o')
->addSelect('translation')
Expand Down
Expand Up @@ -27,7 +27,7 @@ final class TaxonAutocompleteChoiceType extends AbstractType
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'resource' => 'sylius.taxon',
Expand All @@ -39,7 +39,7 @@ public function configureOptions(OptionsResolver $resolver)
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$view->vars['remote_criteria_type'] = 'contains';
$view->vars['remote_criteria_name'] = 'phrase';
Expand All @@ -48,15 +48,15 @@ public function buildView(FormView $view, FormInterface $form, array $options)
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'sylius_taxon_autocomplete_choice';
}

/**
* {@inheritdoc}
*/
public function getParent()
public function getParent(): string
{
return ResourceAutocompleteChoiceType::class;
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ final class TaxonPositionType extends AbstractResourceType
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('position', IntegerType::class, [
Expand All @@ -50,7 +50,7 @@ public function configureOptions(OptionsResolver $resolver): void
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'sylius_taxon_position';
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ final class TaxonTranslationType extends AbstractResourceType
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name', TextType::class, [
Expand All @@ -45,7 +45,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'sylius_taxon_translation';
}
Expand Down
6 changes: 3 additions & 3 deletions src/Sylius/Bundle/TaxonomyBundle/Form/Type/TaxonType.php
Expand Up @@ -30,15 +30,15 @@ final class TaxonType extends AbstractResourceType
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('translations', ResourceTranslationsType::class, [
'entry_type' => TaxonTranslationType::class,
'label' => 'sylius.form.taxon.name',
])
->addEventSubscriber(new AddCodeFormSubscriber())
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event): void {
if (null === $event->getData()) {
return;
}
Expand All @@ -54,7 +54,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
public function getBlockPrefix(): string
{
return 'sylius_taxon';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Component/Taxonomy/Factory/TaxonFactory.php
Expand Up @@ -37,15 +37,15 @@ public function __construct(FactoryInterface $factory)
/**
* {@inheritdoc}
*/
public function createNew()
public function createNew(): TaxonInterface
{
return $this->factory->createNew();
}

/**
* {@inheritdoc}
*/
public function createForParent(TaxonInterface $parent)
public function createForParent(TaxonInterface $parent): TaxonInterface
{
$taxon = $this->createNew();
$taxon->setParent($parent);
Expand Down
Expand Up @@ -26,5 +26,5 @@ interface TaxonFactoryInterface extends FactoryInterface
*
* @return TaxonInterface
*/
public function createForParent(TaxonInterface $parent);
public function createForParent(TaxonInterface $parent): TaxonInterface;
}
Expand Up @@ -22,7 +22,7 @@ final class TaxonSlugGenerator implements TaxonSlugGeneratorInterface
/**
* {@inheritdoc}
*/
public function generate(TaxonInterface $taxon, $locale = null)
public function generate(TaxonInterface $taxon, ?string $locale = null): string
{
$name = $taxon->getTranslation($locale)->getName();

Expand All @@ -45,7 +45,7 @@ public function generate(TaxonInterface $taxon, $locale = null)
*
* @return string
*/
private function transliterate($string)
private function transliterate(string $string): string
{
// Manually replacing apostrophes since Transliterator started removing them at v1.2.
return Transliterator::transliterate(str_replace('\'', '-', $string));
Expand Down
Expand Up @@ -23,5 +23,5 @@ interface TaxonSlugGeneratorInterface
*
* @return string
*/
public function generate(TaxonInterface $taxon, $locale = null);
public function generate(TaxonInterface $taxon, ?string $locale = null): string;
}

0 comments on commit b80ab40

Please sign in to comment.