testMagicCallDelegatesToWrappedPHPDependFunction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Node;
19
20
use PDepend\Source\AST\ASTFunction;
21
use PHPMD\AbstractTest;
22
23
/**
24
 * Test case for the function node implementation.
25
 *
26
 * @covers \PHPMD\Node\FunctionNode
27
 * @covers \PHPMD\Node\AbstractCallableNode
28
 */
29
class FunctionNodeTest extends AbstractTest
30
{
31
    /**
32
     * testMagicCallDelegatesToWrappedPHPDependFunction
33
     *
34
     * @return void
35
     */
36
    public function testMagicCallDelegatesToWrappedPHPDependFunction()
37
    {
38
        $function = $this->getMock(ASTFunction::class, array(), array(null));
0 ignored issues
show
Deprecated Code introduced by
The method PHPMD\AbstractTest::getMock() has been deprecated with message: Method deprecated since Release 5.4.0; use createMock() or getMockBuilder() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
39
        $function->expects($this->once())
40
            ->method('getStartLine');
41
42
        $node = new FunctionNode($function);
43
        $node->getStartLine();
0 ignored issues
show
Documentation Bug introduced by
The method getStartLine does not exist on object<PHPMD\Node\FunctionNode>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
44
    }
45
46
    /**
47
     * testMagicCallThrowsExceptionWhenNoMatchingMethodExists
48
     *
49
     * @return void
50
     * @expectedException BadMethodCallException
51
     */
52
    public function testMagicCallThrowsExceptionWhenNoMatchingMethodExists()
53
    {
54
        $node = new FunctionNode(new ASTFunction(null));
55
        $node->getFooBar();
0 ignored issues
show
Documentation Bug introduced by
The method getFooBar does not exist on object<PHPMD\Node\FunctionNode>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
56
    }
57
}
58