Completed
Push — master ( 0b2e6b...2c86a7 )
by Paul
49:42 queued 39:17
created

CurrentViewHelper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 57
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrentView() 0 4 1
A __invoke() 0 6 2
A getUpdatedCurrentView() 0 4 1
A setCurrentView() 0 9 2
1
<?php
2
3
namespace Victoire\Bundle\CoreBundle\Helper;
4
5
use Victoire\Bundle\CoreBundle\Entity\View;
6
7
/**
8
 * This Helper give you the current view (BasePage or Template)
9
 * ~ victoire_core.current_view.
10
 */
11
class CurrentViewHelper
12
{
13
    protected $currentView;
14
    protected $updatedCurrentView;
15
16
    /**
17
     * Get currentView.
18
     *
19
     * @return View
20
     */
21
    public function getCurrentView()
22
    {
23
        return $this->currentView;
24
    }
25
26
    /**
27
     * Get updatedCurrentView.
28
     *
29
     * @return View
30
     */
31
    public function getUpdatedCurrentView()
32
    {
33
        return $this->updatedCurrentView;
34
    }
35
36
    /**
37
     * Set currentView.
38
     *
39
     * @param View $currentView
40
     *
41
     * @return $this
42
     */
43
    public function setCurrentView(View $currentView)
44
    {
45
        if ($this->currentView == null) {
46
            $this->currentView = clone $currentView;
47
        }
48
        $this->updatedCurrentView = $currentView;
49
50
        return $this;
51
    }
52
53
    /**
54
     * This method allow you to get the current view using a Current View Helper as a method
55
     * ex.
56
     * $currentViewHelper = $this->get('victoire_core.current_view');
57
     * $currentView = $currentViewHelper();.
58
     *
59
     * @return View The current View
60
     */
61
    public function __invoke()
62
    {
63
        if ($this->currentView) {
64
            return $this->currentView;
65
        }
66
    }
67
}
68