JavascriptController   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 7 1
A indexAction() 0 31 5
1
<?php
2
/**
3
 * @copyright Copyright (c) 2011 - 2014 Aleksandr Torosh (http://wezoom.com.ua)
4
 * @author Aleksandr Torosh <[email protected]>
5
 */
6
7
namespace Cms\Controller;
8
9
use Application\Mvc\Controller;
10
use Cms\Model\Javascript;
11
use Cms\Form\JavascriptForm;
12
13
class JavascriptController extends Controller
14
{
15
16
    public function initialize()
17
    {
18
        $this->setAdminEnvironment();
19
        $this->helper->activeMenu()->setActive('admin-javascript');
20
        $this->view->languages_disabled = true;
0 ignored issues
show
Bug introduced by
Accessing languages_disabled on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
21
22
    }
23
24
    public function indexAction()
25
    {
26
        $head = Javascript::findFirst("id = 'head'");
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $head is correct as \Cms\Model\Javascript::findFirst('id = \'head\'') (which targets Phalcon\Mvc\Model::findFirst()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
27
        $body = Javascript::findFirst("id = 'body'");
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $body is correct as \Cms\Model\Javascript::findFirst('id = \'body\'') (which targets Phalcon\Mvc\Model::findFirst()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
28
29
        $form = new JavascriptForm();
30
31
        if ($this->request->isPost()) {
32
            if ($form->isValid($this->request->getPost())) {
33
                $head->setText($this->request->getPost('head'));
0 ignored issues
show
Bug introduced by
The method setText cannot be called on $head (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
34
                $body->setText($this->request->getPost('body'));
0 ignored issues
show
Bug introduced by
The method setText cannot be called on $body (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
35
                if ($head->save() && $body->save()) {
0 ignored issues
show
Bug introduced by
The method save cannot be called on $head (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method save cannot be called on $body (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
36
                    $this->flash->success($this->helper->at('Updated has been successful'));
37
                    return $this->redirect($this->url->get() . 'cms/javascript');
38
                } else {
39
                    $this->flash->error($this->helper->at('Errors saving'));
40
                }
41
            } else {
42
                $this->flashErrors($form);
43
            }
44
        } else {
45
            $form->get('head')->setDefault($head->getText());
0 ignored issues
show
Bug introduced by
The method getText cannot be called on $head (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method setDefault cannot be called on $form->get('head') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
46
            $form->get('body')->setDefault($body->getText());
0 ignored issues
show
Bug introduced by
The method getText cannot be called on $body (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
Bug introduced by
The method setDefault cannot be called on $form->get('body') (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
47
        }
48
49
        $title = htmlentities('<head>, <body> javascript');
50
        $this->helper->title($title);
51
        $this->view->title = $title;
0 ignored issues
show
Bug introduced by
Accessing title on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
52
53
        $this->view->form = $form;
0 ignored issues
show
Bug introduced by
Accessing form on the interface Phalcon\Mvc\ViewInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
54
    }
55
56
57
}