TestMessage::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SfCod\EmailEngineBundle\Example\Params;
4
5
use SfCod\EmailEngineBundle\Example\TestTemplateOptions;
6
use SfCod\EmailEngineBundle\Template\Params\ParameterInterface;
7
use SfCod\EmailEngineBundle\Template\TemplateOptionsInterface;
8
9
/**
10
 * Class TestMessage
11
 *
12
 * @author Virchenko Maksim <[email protected]>
13
 *
14
 * @package SfCod\EmailEngineBundle\Example\Params
15
 */
16
class TestMessage implements ParameterInterface
17
{
18
    /**
19
     * Get parameter name
20
     *
21
     * @return string
22
     */
23
    public static function getName(): string
24
    {
25
        return 'message';
26
    }
27
28
    /**
29
     * Get parameter value
30
     *
31
     * @param TestTemplateOptions|TemplateOptionsInterface $options
32
     *
33
     * @return mixed
34
     */
35
    public function getValue(TemplateOptionsInterface $options)
36
    {
37
        return '<b>' . $options->message . '</b>';
0 ignored issues
show
Bug introduced by
Accessing message on the interface SfCod\EmailEngineBundle\...emplateOptionsInterface suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
38
    }
39
40
    /**
41
     * Get parameter description
42
     *
43
     * @return string
44
     */
45
    public static function getDescription(): string
46
    {
47
        return 'Test message.';
48
    }
49
}
50