|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Limoncello\Passport\Package; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Copyright 2015-2019 [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9
|
|
|
* you may not use this file except in compliance with the License. |
|
10
|
|
|
* You may obtain a copy of the License at |
|
11
|
|
|
* |
|
12
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13
|
|
|
* |
|
14
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
15
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17
|
|
|
* See the License for the specific language governing permissions and |
|
18
|
|
|
* limitations under the License. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
use Doctrine\DBAL\Connection; |
|
22
|
|
|
use Limoncello\Contracts\Application\ContainerConfiguratorInterface; |
|
23
|
|
|
use Limoncello\Contracts\Container\ContainerInterface as LimoncelloContainerInterface; |
|
24
|
|
|
use Limoncello\Passport\Adaptors\Generic\PassportServerIntegration; |
|
25
|
|
|
use Limoncello\Passport\Adaptors\Generic\TokenRepository; |
|
26
|
|
|
use Limoncello\Passport\Contracts\Entities\DatabaseSchemaInterface; |
|
27
|
|
|
use Limoncello\Passport\Contracts\PassportServerIntegrationInterface; |
|
28
|
|
|
use Limoncello\Passport\Contracts\Repositories\TokenRepositoryInterface; |
|
29
|
|
|
use Psr\Container\ContainerInterface as PsrContainerInterface; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @package Limoncello\Passport |
|
33
|
|
|
*/ |
|
34
|
|
|
class PassportContainerConfigurator extends BasePassportContainerConfigurator implements ContainerConfiguratorInterface |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var callable */ |
|
37
|
|
|
const CONFIGURATOR = [self::class, self::CONTAINER_METHOD_NAME]; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @inheritdoc |
|
41
|
|
|
* |
|
42
|
|
|
* @SuppressWarnings(PHPMD.UnusedLocalVariable) |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public static function configureContainer(LimoncelloContainerInterface $container): void |
|
45
|
|
|
{ |
|
46
|
1 |
|
static::baseConfigureContainer($container); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
$container[PassportServerIntegrationInterface::class] = function ( |
|
49
|
|
|
PsrContainerInterface $container |
|
50
|
|
|
): PassportServerIntegrationInterface { |
|
51
|
1 |
|
return new PassportServerIntegration($container); |
|
52
|
|
|
}; |
|
53
|
|
|
|
|
54
|
|
|
$container[TokenRepositoryInterface::class] = function ( |
|
55
|
|
|
PsrContainerInterface $container |
|
56
|
|
|
): TokenRepositoryInterface { |
|
57
|
1 |
|
$connection = $container->get(Connection::class); |
|
58
|
1 |
|
$schema = $container->get(DatabaseSchemaInterface::class); |
|
59
|
|
|
|
|
60
|
1 |
|
return new TokenRepository($connection, $schema); |
|
61
|
|
|
}; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
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:
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: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: