AbstractJsCall   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A _initExpr() 0 4 2
A __get() 0 3 1
A __set() 0 3 1
1
<?php
2
3
namespace Jaxon\Script;
4
5
/**
6
 * AbstractJsCall
7
 *
8
 * Base class for js (not Jaxon) calls and selectors.
9
 *
10
 * @package jaxon-core
11
 * @author Thierry Feuzeu
12
 * @copyright 2024 Thierry Feuzeu <[email protected]>
13
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
14
 * @link https://github.com/jaxon-php/jaxon-core
15
 */
16
17
use Jaxon\Plugin\Response\Dialog\DialogCommand;
18
use Closure;
19
20
abstract class AbstractJsCall extends AbstractCall
21
{
22
    /**
23
     * A function to call when the expression is created
24
     *
25
     * @var Closure
26
     */
27
    protected $xExprCb;
28
29
    /**
30
     * The constructor.
31
     *
32
     * @param DialogCommand $xDialog
33
     * @param Closure|null $xExprCb
34
     */
35
    protected function __construct(DialogCommand $xDialog, ?Closure $xExprCb)
36
    {
37
        $this->xDialog = $xDialog;
38
        $this->xExprCb = $xExprCb;
39
    }
40
41
    /**
42
     * Call the js expression callback
43
     *
44
     * @param JsExpr $xJsExpr
45
     *
46
     * @return JsExpr
47
     */
48
    protected function _initExpr(JsExpr $xJsExpr): JsExpr
49
    {
50
        $this->xExprCb !== null && ($this->xExprCb)($xJsExpr);
51
        return $xJsExpr;
52
    }
53
54
    /**
55
     * Get the value of an attribute of the current object
56
     *
57
     * @param string  $sAttribute
58
     *
59
     * @return JsExpr
60
     */
61
    public function __get(string $sAttribute): JsExpr
62
    {
63
        return $this->_expr()->__get( $sAttribute);
64
    }
65
66
    /**
67
     * Set the value of an attribute of the current object
68
     *
69
     * @param string $sAttribute
70
     * @param mixed $xValue
71
     *
72
     * @return void
73
     */
74
    public function __set(string $sAttribute, $xValue)
75
    {
76
        return $this->_expr()->__set($sAttribute, $xValue);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->_expr()->__set($sAttribute, $xValue) targeting Jaxon\Script\JsExpr::__set() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

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

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

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

Loading history...
77
    }
78
}
79