ServiceProvider::setupServices()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace XHGui\ServiceProvider;
4
5
use Pimple\Container;
6
use Pimple\ServiceProviderInterface;
7
use XHGui\Saver\NormalizingSaver;
8
9
class ServiceProvider implements ServiceProviderInterface
10
{
11
    public function register(Container $app): void
12
    {
13
        $this->setupPaths($app);
14
        $this->setupServices($app);
0 ignored issues
show
Unused Code introduced by
The call to the method XHGui\ServiceProvider\Se...ovider::setupServices() 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...
15
    }
16
17
    private function setupPaths(Container $app): void
18
    {
19
        $app['app.dir'] = dirname(__DIR__, 2);
20
        $app['app.template_dir'] = $app['app.dir'] . '/templates';
21
        $app['app.config_dir'] = $app['app.dir'] . '/config';
22
        $app['app.cache_dir'] = static function ($app) {
23
            return $app['config']['cache'] ?? $app['app.dir'] . '/cache';
24
        };
25
    }
26
27
    /**
28
     * Add common service objects to the container.
29
     */
30
    private function setupServices(Container $app): void
31
    {
32
        $app['searcher'] = static function ($app) {
33
            $saver = $app['config']['save.handler'];
34
35
            return $app["searcher.$saver"];
36
        };
37
38
        $app['saver'] = static function ($app) {
39
            $saver = $app['config']['save.handler'];
40
41
            return new NormalizingSaver($app["saver.$saver"]);
42
        };
43
    }
44
}
45