Completed
Push — master ( 77699e...d0af27 )
by thomas
03:51
created

nrew.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
require_once "vendor/autoload.php";
4
5
use BitWasp\Bitcoin\Networking\Peer\Peer;
6
7
$loop = React\EventLoop\Factory::create();
8
$factory = new \BitWasp\Bitcoin\Networking\Factory($loop);
9
10
$msgs = $factory->getMessages(new \BitWasp\Bitcoin\Crypto\Random\Random());
11
$dns = $factory->getDns();
12
$host = $factory->getAddress('80.57.227.14');
13
$local = $factory->getAddress('192.168.192.39');
14
15
$params = new \BitWasp\Bitcoin\Networking\Peer\ConnectionParams();
16
$params->requestTxRelay(true);
17
18
$connector = new \BitWasp\Bitcoin\Networking\Peer\Connector(
19
    $msgs,
20
    $params,
21
    $loop,
22
    $dns
23
);
24
25
$connector
0 ignored issues
show
The method then does only exist in React\Promise\PromiseInterface, but not in BitWasp\Bitcoin\Networking\Peer\Connector.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
26
    ->connect($host)
27
    ->then(function (Peer $peer) {
28
        $remoteVersion = $peer->getRemoteVersion();
29
        $protoVersion = $remoteVersion->getVersion();
30
        $services = $remoteVersion->getServices();
31
32
        if ($protoVersion < 70012) {
33
            echo "Found peer with version: ".$protoVersion. " - disconnecting\n";
34
            $peer->close();
35
        }
36
37
        if ($services->getInt() != '5') {
38
            echo "Peer was not a full node - disconnecting\n";
39
            $peer->close();
40
        }
41
    });
42
43
$loop->run();
44