Passed
Push — master ( cb3898...d20083 )
by Fabio
05:58
created

TPageTopAnchorBehavior   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 46
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getTopAnchor() 0 3 1
A addFormANameAnchor() 0 6 2
A setTopAnchor() 0 3 1
A events() 0 3 1
1
<?php
2
3
/**
4
 * TPageTopAnchorBehavior class file.
5
 *
6
 * @author Brad Anderson <[email protected]>
7
 * @link https://github.com/pradosoft/prado
8
 * @license https://github.com/pradosoft/prado/blob/master/LICENSE
9
 */
10
11
namespace Prado\Util\Behaviors;
12
13
use Prado\Util\TBehavior;
14
use Prado\TPropertyValue;
15
16
/**
17
 * TPageTopAnchorBehavior class.
18
 *
19
 * TPageTopAnchorBehavior adds an "<a name='top'>" anchor at the top of
20
 * every page just before the TForm.
21
 * @author Brad Anderson <[email protected]>
22
 * @package Prado\Util\Behaviors
23
 * @since 4.2.0
24
 */
25
class TPageTopAnchorBehavior extends TBehavior
26
{
27
	/**
28
	 * @var string the page theme is set to this parameter key
29
	 */
30
	private $_topAnchor = 'top';
31
	
32
	/**
33
	 * This handles the TPage.OnSaveStateComplete event to place the
34
	 * '<a name="">' at the last moment and have least interference with
35
	 * anything else
36
	 * @return array of events as keys and methods as values
37
	 */
38
	public function events()
39
	{
40
		return ['OnSaveStateComplete' => 'addFormANameAnchor'];
41
	}
42
	
43
	/**
44
	 * This method places an '<a name="">' before the TForm
45
	 * @param $page object raising the event
46
	 * @param $param mixed the parameter of the raised event
47
	 */
48
	public function addFormANameAnchor($page, $param)
0 ignored issues
show
Unused Code introduced by
The parameter $param is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

48
	public function addFormANameAnchor($page, /** @scrutinizer ignore-unused */ $param)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
49
	{
50
		$topanchor = '<a name="' . $this->_topAnchor . '"></a>';
51
		
52
		if ($form = $page->getForm()) {
53
			$form->getParent()->getControls()->insertBefore($form, $topanchor);
54
		}
55
	}
56
	 
57
	/**
58
	 * @return string the top anchor name, defaults to 'top'.
59
	 */
60
	public function getTopAnchor()
61
	{
62
		return $this->_topAnchor;
63
	}
64
	 
65
	/**
66
	 * @param $value string the top anchor name.
67
	 */
68
	public function setTopAnchor($value)
69
	{
70
		$this->_topAnchor = TPropertyValue::ensureString($value);
71
	}
72
}
73