AbstractJsCall   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 3 1
A __construct() 0 2 1
A _expr() 0 6 2
A __get() 0 3 1
1
<?php
2
3
namespace Jaxon\Script\Call;
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\Script\Action\Attr;
18
use Jaxon\Script\Action\Selector;
19
use Jaxon\Script\JsExpr;
20
use Closure;
21
22
abstract class AbstractJsCall extends AbstractCall
23
{
24
    /**
25
     * The constructor.
26
     *
27
     * @param Closure|null $xExprCb
28
     */
29
    protected function __construct(protected ?Closure $xExprCb)
30
    {}
31
32
    /**
33
     * Get the call to add to the expression
34
     *
35
     * @return Attr|Selector
36
     */
37
    abstract protected function _exprCall(): Attr|Selector;
38
39
    /**
40
     * Get the json expression
41
     *
42
     * @return JsExpr
43
     */
44
    protected function _expr(): JsExpr
45
    {
46
        $xJsExpr = new JsExpr($this->_exprCall());
47
        // Apply the callback, if one was defined.
48
        $this->xExprCb !== null && ($this->xExprCb)($xJsExpr);
49
        return $xJsExpr;
50
    }
51
52
    /**
53
     * Get the value of an attribute of the current object
54
     *
55
     * @param string  $sAttribute
56
     *
57
     * @return JsExpr
58
     */
59
    public function __get(string $sAttribute): JsExpr
60
    {
61
        return $this->_expr()->__get( $sAttribute);
62
    }
63
64
    /**
65
     * Set the value of an attribute of the current object
66
     *
67
     * @param string $sAttribute
68
     * @param mixed $xValue
69
     *
70
     * @return void
71
     */
72
    public function __set(string $sAttribute, $xValue)
73
    {
74
        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...
75
    }
76
}
77