Completed
Push — namespace2 ( 8a6673...791eac )
by Fabio
08:25
created

TJuiCallbackPageStateTracker::addStatesToTrack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * TJuiControlAdapter class file.
4
 *
5
 * @author Fabio Bas <[email protected]>
6
 * @link https://github.com/pradosoft/prado
7
 * @copyright Copyright &copy; 2013-2015 PradoSoft
8
 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9
 * @package Prado\Web\UI\JuiControls
10
 */
11
12
namespace Prado\Web\UI\JuiControls;
13
14
use Prado\TPropertyValue;
15
use Prado\Web\UI\ActiveControls\TCallbackPageStateTracker;
16
17
/**
18
 * TJuiCallbackPageStateTracker class.
19
 *
20
 * Tracking changes to the page state during callback, including {@link TJuiControlOptions}.
21
 *
22
 * @author LANDWEHR Computer und Software GmbH
23
 * @package Prado\Web\UI\JuiControls
24
 * @since 3.3
25
 */
26
class TJuiCallbackPageStateTracker extends TCallbackPageStateTracker {
27
28
  /**
29
   * Add the {@link TJuiControlOptions} to the states to track.
30
   */
31
  protected function addStatesToTrack()
32
  {
33
    parent::addStatesToTrack();
0 ignored issues
show
Unused Code introduced by
The call to the method Prado\Web\UI\ActiveContr...ker::addStatesToTrack() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
34
    $states = $this->getStatesToTrack();
35
    $states['JuiOptions'] = array('TMapCollectionDiff', array($this, 'updateJuiOptions'));
36
  }
37
38
	/**
39
	 * Updates the options of the jQueryUI widget.
40
	 * @param array list of widget options to change.
41
	 */
42
  protected function updateJuiOptions($options)
43
  {
44
    foreach ($options as $key => $value) $options[$key] = $key . ': ' . (is_string($value) ? "'{$value}'" : TPropertyValue::ensureString($value));
45
    $code = "jQuery('#{$this->_control->getWidgetID()}').{$this->_control->getWidget()}('option', { " . implode(', ', $options) . " });";
46
    $this->_control->getPage()->getClientScript()->registerEndScript(sprintf('%08X', crc32($code)), $code);
47
  }
48
49
}