ChooserController::chooserShowFolderAction()   B
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 20
nc 2
nop 2
1
<?php
2
3
namespace Victoire\Bundle\MediaBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Request;
10
use Victoire\Bundle\MediaBundle\Entity\Folder;
11
use Victoire\Bundle\MediaBundle\Entity\Media;
12
use Victoire\Bundle\MediaBundle\Helper\MediaManager;
13
14
/**
15
 * chooser controller.
16
 *
17
 * @Route("/victoire-media/chooser")
18
 */
19
class ChooserController extends Controller
20
{
21
    /**
22
     * @Route("/", name="VictoireMediaBundle_chooser", options={"expose"=true})
23
     *
24
     * @param Request $request
25
     *
26
     * @throws \Doctrine\ORM\EntityNotFoundException
27
     *
28
     * @return RedirectResponse
29
     */
30
    public function chooserIndexAction(Request $request)
31
    {
32
        $type = $request->get('type');
33
        $cKEditorFuncNum = $request->get('CKEditorFuncNum');
34
35
        $em = $this->getDoctrine()->getManager();
36
37
        /* @var \Victoire\Bundle\MediaBundle\Entity\Folder $firstFolder */
38
        $firstFolder = $em->getRepository('VictoireMediaBundle:Folder')->getFirstTopFolder();
39
40
        return $this->redirect($this->generateUrl('VictoireMediaBundle_chooser_show_folder', ['folderId' => $firstFolder->getId(), 'type' => $type, 'CKEditorFuncNum' => $cKEditorFuncNum]));
41
    }
42
43
    /**
44
     * @param Request $request
45
     * @param int     $folderId The filder id
46
     *
47
     * @throws \Doctrine\ORM\EntityNotFoundException
48
     *
49
     * @return array
50
     * @Route("/{folderId}", requirements={"folderId" = "\d+"}, name="VictoireMediaBundle_chooser_show_folder")
51
     * @Template()
52
     */
53
    public function chooserShowFolderAction(Request $request, $folderId)
54
    {
55
        $type = $request->get('type');
56
        $cKEditorFuncNum = $request->get('CKEditorFuncNum');
57
58
        $em = $this->getDoctrine()->getManager();
59
        /* @var MediaManager $mediaHandler */
60
        $mediaHandler = $this->get('victoire_media.media_manager');
61
62
        /* @var \Victoire\Bundle\MediaBundle\Entity\Folder $folder */
63
        $folder = $em->getRepository('VictoireMediaBundle:Folder')->getFolder($folderId);
64
        /* @var array $mediaHandler */
65
        $folders = $em->getRepository('VictoireMediaBundle:Folder')->getAllFolders();
66
67
        $handler = null;
68
        if ($type) {
69
            $handler = $mediaHandler->getHandlerForType($type);
70
        }
71
72
        return [
73
                'cKEditorFuncNum' => $cKEditorFuncNum,
74
                'mediamanager'    => $mediaHandler,
75
                'handler'         => $handler,
76
                'type'            => $type,
77
                'folder'          => $folder,
78
                'folders'         => $folders,
79
                'fileform'        => $this->createTypeFormView($mediaHandler, 'file'),
0 ignored issues
show
Documentation introduced by
$mediaHandler is of type array, but the function expects a object<Victoire\Bundle\M...le\Helper\MediaManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
80
                'videoform'       => $this->createTypeFormView($mediaHandler, 'video'),
0 ignored issues
show
Documentation introduced by
$mediaHandler is of type array, but the function expects a object<Victoire\Bundle\M...le\Helper\MediaManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81
                'slideform'       => $this->createTypeFormView($mediaHandler, 'slide'),
0 ignored issues
show
Documentation introduced by
$mediaHandler is of type array, but the function expects a object<Victoire\Bundle\M...le\Helper\MediaManager>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
82
        ];
83
    }
84
85
    /**
86
     * @param MediaManager $mediaManager
87
     * @param string       $type
88
     *
89
     * @return \Symfony\Component\Form\FormView
90
     */
91
    private function createTypeFormView(MediaManager $mediaManager, $type)
92
    {
93
        $handler = $mediaManager->getHandlerForType($type);
94
        $media = new Media();
95
        $helper = $handler->getFormHelper($media);
96
97
        return $this->createForm($handler->getFormType(), $helper)->createView();
98
    }
99
}
100