Completed
Push — develop ( 67e5f1...4da4e3 )
by Neomerx
08:20
created

PostgreSqlPassportContainerConfigurator   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 25
loc 25
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A configureContainer() 19 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php namespace Limoncello\Passport\Package;
2
3
/**
4
 * Copyright 2015-2018 [email protected]
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
use Doctrine\DBAL\Connection;
20
use Limoncello\Contracts\Application\ContainerConfiguratorInterface as CCI;
21
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface;
22
use Limoncello\Passport\Adaptors\PostgreSql\PassportServerIntegration;
23
use Limoncello\Passport\Adaptors\PostgreSql\TokenRepository;
24
use Limoncello\Passport\Contracts\Entities\DatabaseSchemaInterface;
25
use Limoncello\Passport\Contracts\PassportServerIntegrationInterface;
26
use Limoncello\Passport\Contracts\Repositories\TokenRepositoryInterface;
27
use Psr\Container\ContainerInterface as PsrContainerInterface;
28
29
/**
30
 * @package Limoncello\Passport
31
 */
32 View Code Duplication
class PostgreSqlPassportContainerConfigurator extends BasePassportContainerConfigurator implements CCI
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
{
34
    /**
35
     * @inheritdoc
36
     */
37 2
    public static function configureContainer(LimoncelloContainerInterface $container): void
38
    {
39 2
        static::baseConfigureContainer($container);
0 ignored issues
show
Unused Code introduced by
The call to the method Limoncello\Passport\Pack...aseConfigureContainer() 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...
40
41
        $container[PassportServerIntegrationInterface::class] = function (
42
            PsrContainerInterface $container
43
        ): PassportServerIntegrationInterface {
44 2
            return new PassportServerIntegration($container);
45
        };
46
47
        $container[TokenRepositoryInterface::class] = function (
48
            PsrContainerInterface $container
49
        ): TokenRepositoryInterface {
50 1
            $connection = $container->get(Connection::class);
51 1
            $schema     = $container->get(DatabaseSchemaInterface::class);
52
53 1
            return new TokenRepository($connection, $schema);
54
        };
55
    }
56
}
57