GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch master (2347b0)
by Robert
01:25
created

ServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 42

Test Coverage

Coverage 12.7%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 42
dl 0
loc 108
ccs 8
cts 63
cp 0.127
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 21 1
A registerHttp() 0 17 1
A registerDriver() 0 18 3
A registerConsole() 0 43 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the "php-ipfs" package.
7
 *
8
 * (c) Robert Schönthal <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace IPFS\Container;
15
16
use Http\Client\Common\PluginClient;
17
use Http\Client\HttpAsyncClient;
18
use Http\Discovery\HttpAsyncClientDiscovery;
19
use Http\Discovery\MessageFactoryDiscovery;
20
use Http\Discovery\UriFactoryDiscovery;
21
use Http\Message\MessageFactory;
22
use Http\Message\UriFactory;
23
use IPFS\Api;
24
use IPFS\Console\ApiBuildCommand;
25
use IPFS\Console\CommandBuilder;
26
use IPFS\Driver\Cli;
27
use IPFS\Driver\Http;
28
use IPFS\Utils\AnnotationReader;
29
use phpDocumentor\Reflection\DocBlockFactory;
30
use PhpParser\BuilderFactory;
31
use Pimple\Container;
32
use Pimple\ServiceProviderInterface;
33
use Symfony\Component\Console\Application;
34
use Symfony\Component\DomCrawler\Crawler;
35
use Symfony\Component\Process\Process;
36
37
class ServiceProvider implements ServiceProviderInterface
38
{
39
    /**
40
     * {@inheritdoc}
41
     */
42 4
    public function register(Container $pimple)
43
    {
44 4
        $this->registerDriver($pimple);
0 ignored issues
show
Unused Code introduced by
The call to the method IPFS\Container\ServiceProvider::registerDriver() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
45 4
        $this->registerConsole($pimple);
0 ignored issues
show
Unused Code introduced by
The call to the method IPFS\Container\ServiceProvider::registerConsole() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
46
47
        $pimple[AnnotationReader::class] = function () {
48
            return new AnnotationReader(
49
                new \Doctrine\Common\Annotations\AnnotationReader(),
50
                DocBlockFactory::createInstance()
51
            );
52
        };
53
54
        $pimple[Api\ApiBuilder::class] = function () use ($pimple) {
55
            $this->registerHttp($pimple);
0 ignored issues
show
Unused Code introduced by
The call to the method IPFS\Container\ServiceProvider::registerHttp() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
56
57
            $parser = new Api\ApiParser($pimple[HttpAsyncClient::class], $pimple[MessageFactory::class], new Crawler());
58
            $generator = new Api\ApiGenerator(new BuilderFactory());
59
60
            return new Api\ApiBuilder($parser, $generator);
61
        };
62 4
    }
63
64
    public function registerHttp(Container $pimple)
65
    {
66
        $pimple[HttpAsyncClient::class] = function () {
67
            return new PluginClient(
68
                HttpAsyncClientDiscovery::find(),
69
                []
70
            );
71
        };
72
73
        $pimple[MessageFactory::class] = function () {
74
            return MessageFactoryDiscovery::find();
75
        };
76
77
        $pimple[UriFactory::class] = function () {
78
            return UriFactoryDiscovery::find();
79
        };
80
    }
81
82 4
    private function registerDriver(Container $pimple)
83
    {
84
        $pimple[Http::class] = function () use ($pimple) {
85
            $this->registerHttp($pimple);
0 ignored issues
show
Unused Code introduced by
The call to the method IPFS\Container\ServiceProvider::registerHttp() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
86
87
            return new Http(
88
                $pimple[HttpAsyncClient::class],
89
                $pimple[MessageFactory::class],
90
                $pimple[UriFactory::class],
91
                $pimple[AnnotationReader::class],
92
                getenv('IPFS_API') ?: 'http://localhost:5001/api/v0'
93
            );
94
        };
95
96
        $pimple[Cli::class] = function () use ($pimple) {
97
            return new Cli(new Process([]), $pimple[AnnotationReader::class], getenv('IPFS_BINARY') ?: 'ipfs');
98
        };
99 4
    }
100
101 4
    private function registerConsole(Container $pimple)
102
    {
103
        $pimple[CommandBuilder::class] = function (Container $pimple) {
104
            $builder = new CommandBuilder([
105
                new Api\Basics(),
106
                new Api\Bitswap(),
107
                new Api\Block(),
108
                new Api\Bootstrap(),
109
                new Api\Config(),
110
                new Api\Dag(),
111
                new Api\Dht(),
112
                new Api\Diag(),
113
                new Api\File(),
114
                new Api\Files(),
115
                new Api\Filestore(),
116
                new Api\Key(),
117
                new Api\Log(),
118
                new Api\Name(),
119
                new Api\CObject(),
120
                new Api\P2p(),
121
                new Api\Pin(),
122
                new Api\Pubsub(),
123
                new Api\Refs(),
124
                new Api\Repo(),
125
                new Api\Stats(),
126
                new Api\Swarm(),
127
                new Api\Tar(),
128
            ], $pimple[AnnotationReader::class]);
129
130
            $builder->addDriver(Cli::class, $pimple->raw(Cli::class));
131
            $builder->addDriver(Http::class, $pimple->raw(Http::class));
132
133
            return $builder;
134
        };
135
136
        $pimple[Application::class] = function (Container $pimple) {
137
            $app = new Application('ipfs', '@git-version@');
138
            $app->addCommands($pimple[CommandBuilder::class]->generateCommands());
139
            $app->add(new ApiBuildCommand($pimple->raw(Api\ApiBuilder::class)));
140
141
            return $app;
142
        };
143 4
    }
144
}
145