Passed
Push — up-php7 ( a2fe11...4e1c1e )
by Erik
05:48
created

AliasOverviewType::getUrlAliases()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 6
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 9
cp 0
crap 6
rs 9.4285
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\UrlBundle\Admin;
8
9
use Symfony\Bridge\Doctrine\RegistryInterface;
10
use Symfony\Component\Form\AbstractType;
11
use Symfony\Component\Form\FormInterface;
12
use Symfony\Component\Form\FormView;
13
use Symfony\Component\OptionsResolver\OptionsResolver;
14
use Zicht\Bundle\UrlBundle\Exception\UnsupportedException;
15
use Zicht\Bundle\UrlBundle\Url\Provider;
16
17
/**
18
 * Form type to render all available url aliases
19
 */
20
class AliasOverviewType extends AbstractType
21
{
22
    /** @var Provider */
23
    protected $provider;
24
25
    /** @var RegistryInterface */
26
    protected $doctrine;
27
28
    /**
29
     * AliasOverviewType constructor.
30
     *
31
     * @param Provider $provider
32
     * @param RegistryInterface $doctrine
33
     */
34
    public function __construct(Provider $provider, RegistryInterface $doctrine)
35
    {
36
        $this->provider = $provider;
37
        $this->doctrine = $doctrine;
38
    }
39
40
    /**
41
     * @{inheritDoc}
42
     */
43
    public function configureOptions(OptionsResolver $resolver)
44
    {
45
        parent::configureOptions($resolver);
46
        $resolver->setRequired('record');
47
        $resolver->setDefaults(
48
            [
49
                'translation_domain' => 'admin',
50
                'label' => 'admin.alias_overview_admin.label',
51
                'required' => false,
52
                'virtual' => true,
53
            ]
54
        );
55
    }
56
57
    /**
58
     * @{inheritDoc}
59
     */
60
    public function buildView(FormView $view, FormInterface $form, array $options)
61
    {
62
        parent::buildView($view, $form, $options);
63
        $view->vars['record'] = $options['record'];
64
        $view->vars['url_aliases'] = $this->getUrlAliases($options['record']);
65
    }
66
67
    /**
68
     * Returns all UrlAlias entities associated to an object
69
     *
70
     * @param mixed $object
71
     */
72
    protected function getUrlAliases($object)
73
    {
74
        try {
75
            $internalUrl = $this->provider->url($object);
76
        } catch (UnsupportedException $exception) {
77
            return [];
78
        }
79
80
        return $this->doctrine->getRepository('ZichtUrlBundle:UrlAlias')
81
            ->findAllByInternalUrl($internalUrl);
0 ignored issues
show
Bug introduced by
The method findAllByInternalUrl() does not exist on Doctrine\Common\Persistence\ObjectRepository. Did you maybe mean findAll()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

81
            ->/** @scrutinizer ignore-call */ findAllByInternalUrl($internalUrl);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
    }
83
84
    /**
85
     * @{inheritDoc}
86
     */
87
    public function getName()
88
    {
89
        return 'alias_overview_type';
90
    }
91
}
92