Completed
Push — middleware-wip ( 106169...2ebda9 )
by Romain
02:43
created

dispatchBeforeSignal()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Middleware\State;
15
16
use Romm\Formz\Middleware\Signal\SendsMiddlewareSignal;
17
18
trait StateMiddlewareDependencyTrait
19
{
20
    /**
21
     * @var MiddlewareState
22
     */
23
    private $state;
24
25
    /**
26
     * @see \Romm\Formz\Middleware\Signal\SendsMiddlewareSignal::dispatchBeforeSignal()
27
     */
28
    final public function dispatchBeforeSignal()
29
    {
30
        if (false === $this instanceof SendsMiddlewareSignal) {
31
            // @todo exception
32
        }
33
34
        /** @var SendsMiddlewareSignal $this */
35
        $this->state->dispatchBeforeSignal($this);
0 ignored issues
show
Bug introduced by
Accessing state on the interface Romm\Formz\Middleware\Signal\SendsMiddlewareSignal 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...
36
    }
37
38
    /**
39
     * @see \Romm\Formz\Middleware\Signal\SendsMiddlewareSignal::dispatchAfterSignal()
40
     */
41
    final public function dispatchAfterSignal()
42
    {
43
        if (false === $this instanceof SendsMiddlewareSignal) {
44
            // @todo exception
45
        }
46
47
        /** @var SendsMiddlewareSignal $this */
48
        $this->state->dispatchAfterSignal($this);
0 ignored issues
show
Bug introduced by
Accessing state on the interface Romm\Formz\Middleware\Signal\SendsMiddlewareSignal 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...
49
    }
50
51
    /**
52
     * @param MiddlewareState $middlewareState
53
     */
54
    final public function attachMiddlewareState(MiddlewareState $middlewareState)
55
    {
56
        $this->state = $middlewareState;
57
    }
58
}
59
60
61