MethodExample   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 5
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A demonstrate() 0 28 1
1
<?php
2
/**
3
 * @author stev leibelt <[email protected]>
4
 * @since 2014-05-24 
5
 */
6
7
require_once 'AbstractExample.php';
8
require_once __DIR__ . '/../vendor/autoload.php';
9
10
/**
11
 * Class MethodExample
12
 * @package Net\Bazzline\Component\CodeGenerator\Example
13
 */
14
class MethodExample extends AbstractExample
15
{
16
    /**
17
     * @return string
18
     */
19
    function demonstrate()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
20
    {
21
        $blockFactory           = $this->getBlockGeneratorFactory();
22
        $documentationFactory   = $this->getDocumentationGeneratorFactory();
23
        $methodFactory          = $this->getMethodGeneratorFactory();
24
25
        $myMethod = $methodFactory->create();
26
        $myMethod->setDocumentation($documentationFactory->create());
27
        $myMethod->markAsPublic();
28
        $myMethod->markAsFinal();
29
        $myMethod->setName('myMethod');
30
        $myMethod->addParameter('foo', null, 'Foo');
31
        $myMethod->addParameter('bar', 'null', 'Bar');
32
        $myMethodBody = $blockFactory->create();
33
        $myMethodBody
34
            ->add('$foobar = $foo->toString();')
35
            ->add('')
36
            ->add('if (!is_null($bar)) {')
37
            ->startIndention()
38
                ->add('$foobar .= $bar->toString();')
39
            ->stopIndention()
40
            ->add('}')
41
            ->add('')
42
            ->add('return $foobar');
43
        $myMethod->setBody($myMethodBody, 'string');
0 ignored issues
show
Documentation introduced by
'string' is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
45
        echo $myMethod->generate() . PHP_EOL;
46
    }
47
}
48
49
$example = new MethodExample();
50
$example->demonstrate();