PageController   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 138
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 3
dl 0
loc 138
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A newAction() 0 4 1
A newPostAction() 0 4 1
A settingsAction() 0 4 1
A settingsPostAction() 0 4 1
A deleteAction() 0 4 1
A getNewPageType() 0 4 1
A getPageSettingsType() 0 4 1
A getBusinessPageType() 0 4 1
A getNewPage() 0 4 1
A getBaseTemplatePath() 0 4 1
1
<?php
2
3
namespace Victoire\Bundle\PageBundle\Controller;
4
5
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
6
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
9
use Symfony\Component\HttpFoundation\JsonResponse;
10
use Symfony\Component\HttpFoundation\Request;
11
use Victoire\Bundle\PageBundle\Entity\BasePage;
12
use Victoire\Bundle\PageBundle\Entity\Page;
13
use Victoire\Bundle\PageBundle\Form\PageSettingsType;
14
use Victoire\Bundle\PageBundle\Form\PageType;
15
16
/**
17
 * Page Controller.
18
 *
19
 * @Route("/victoire-dcms/page")
20
 **/
21
class PageController extends BasePageController
22
{
23
    /**
24
     * Display a form to create a new Page.
25
     *
26
     * @param Request $request
27
     * @param bool    $isHomepage Is the page a homepage
28
     *
29
     * @Route("/new", name="victoire_core_page_new", defaults={"isHomepage" : false})
30
     * @Route("/homepage/new", name="victoire_core_homepage_new", defaults={"isHomepage" : true})
31
     * @Method("GET")
32
     * @Template()
33
     *
34
     * @return JsonResponse
35
     */
36
    public function newAction(Request $request, $isHomepage = false)
37
    {
38
        return new JsonResponse(parent::newAction($request, $isHomepage));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Symfony\Comp...request, $isHomepage)); (Symfony\Component\HttpFoundation\JsonResponse) is incompatible with the return type of the parent method Victoire\Bundle\PageBund...geController::newAction of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
39
    }
40
41
    /**
42
     * Create a new Page.
43
     *
44
     * @param Request $request
45
     *
46
     * @Route("/new", name="victoire_core_page_new_post")
47
     * @Route("/homepage/new", name="victoire_core_homepage_new")
48
     * @Method("POST")
49
     * @Template()
50
     *
51
     * @return JsonResponse
52
     */
53
    public function newPostAction(Request $request)
54
    {
55
        return new JsonResponse(parent::newPostAction($request));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Symfony\Comp...wPostAction($request)); (Symfony\Component\HttpFoundation\JsonResponse) is incompatible with the return type of the parent method Victoire\Bundle\PageBund...ntroller::newPostAction of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
56
    }
57
58
    /**
59
     * Display a form to edit Page settings.
60
     *
61
     * @param Request  $request
62
     * @param BasePage $page
63
     *
64
     * @Route("/{id}/settings", name="victoire_core_page_settings")
65
     * @Method("GET")
66
     * @Template()
67
     * @ParamConverter("page", class="VictoirePageBundle:BasePage")
68
     *
69
     * @return JsonResponse The settings
70
     */
71
    public function settingsAction(Request $request, BasePage $page)
72
    {
73
        return new JsonResponse(parent::settingsAction($request, $page));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Symfony\Comp...tion($request, $page)); (Symfony\Component\HttpFoundation\JsonResponse) is incompatible with the return type of the parent method Victoire\Bundle\PageBund...troller::settingsAction of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
74
    }
75
76
    /**
77
     * Save Page settings.
78
     *
79
     * @param Request  $request
80
     * @param BasePage $page
81
     *
82
     * @Route("/{id}/settings", name="victoire_core_page_settings_post")
83
     * @Method("POST")
84
     * @Template()
85
     * @ParamConverter("page", class="VictoirePageBundle:BasePage")
86
     *
87
     * @return JsonResponse The settings
88
     */
89
    public function settingsPostAction(Request $request, BasePage $page)
90
    {
91
        return new JsonResponse(parent::settingsPostAction($request, $page));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Symfony\Comp...tion($request, $page)); (Symfony\Component\HttpFoundation\JsonResponse) is incompatible with the return type of the parent method Victoire\Bundle\PageBund...ler::settingsPostAction of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
92
    }
93
94
    /**
95
     * Page delete.
96
     *
97
     * @param BasePage $page
98
     *
99
     * @return JsonResponse
100
     * @Route("/{id}/delete", name="victoire_core_page_delete")
101
     * @Template()
102
     * @ParamConverter("page", class="VictoirePageBundle:BasePage")
103
     */
104
    public function deleteAction(BasePage $page)
105
    {
106
        return new JsonResponse(parent::deleteAction($page));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return new \Symfony\Comp...::deleteAction($page)); (Symfony\Component\HttpFoundation\JsonResponse) is incompatible with the return type of the parent method Victoire\Bundle\PageBund...ontroller::deleteAction of type array<string,boolean|string>.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
107
    }
108
109
    /**
110
     * getNewPageType.
111
     *
112
     * @return string
113
     */
114
    protected function getNewPageType()
115
    {
116
        return PageType::class;
117
    }
118
119
    /**
120
     * getPageSettingsType.
121
     *
122
     * @return string
123
     */
124
    protected function getPageSettingsType()
125
    {
126
        return PageSettingsType::class;
127
    }
128
129
    /**
130
     * getBusinessPageType.
131
     *
132
     * @return string
133
     */
134
    protected function getBusinessPageType()
135
    {
136
        return PageSettingsType::class;
137
    }
138
139
    /**
140
     * getNewPage.
141
     *
142
     * @return \Victoire\Bundle\PageBundle\Entity\Page
143
     */
144
    protected function getNewPage()
145
    {
146
        return new Page();
147
    }
148
149
    /**
150
     * getBaseTemplatePath.
151
     *
152
     * @return string
153
     */
154
    protected function getBaseTemplatePath()
155
    {
156
        return 'VictoirePageBundle:Page';
157
    }
158
}
159