EmbedViewHelper   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 8

Importance

Changes 3
Bugs 2 Features 2
Metric Value
wmc 7
c 3
b 2
f 2
cbo 8
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C execute() 0 30 7
1
<?php
2
namespace Fwk\Core\Components\ViewHelper;
3
4
class EmbedViewHelper extends AbstractViewHelper implements ViewHelper
5
{
6
    public function execute(array $arguments)
7
    {
8
        $actionName = (isset($arguments[0]) ? $arguments[0] : null);
9
        $parameters = (isset($arguments[1]) ? $arguments[1] : array());
10
        
11
        if (empty($actionName)) {
12
            throw new Exception(sprintf('Empty action name'));
13
        }
14
        
15
        if (!is_array($parameters)) {
16
            throw new Exception(sprintf('Parameters should be an array'));
17
        }
18
        
19
        $context = $this->getViewHelperService()->getContext()->newParent();
20
        $context->setActionName($actionName);
21
        
22
        foreach ($parameters as $key => $value) {
23
            $context->getRequest()->query->set($key, $value);
24
        }
25
        
26
        $result = $this->getViewHelperService()
27
                    ->getApplication()
28
                    ->runAction($context);
29
        
30
        if ($context->getResponse() instanceof \Symfony\Component\HttpFoundation\Response) {
31
            return $context->getResponse()->getContent();
32
        }
33
        
34
        return $result;
35
    }
36
}