Completed
Push — master ( 88eef6...81252c )
by Joschi
02:44
created

AbstractAdapterStrategy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 3
c 5
b 0
f 0
lcom 0
cbo 1
dl 0
loc 51
ccs 12
cts 14
cp 0.8571
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A getType() 0 4 1
1
<?php
2
3
/**
4
 * apparat-object
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Object
8
 * @subpackage  Apparat\Object\Application
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT	The MIT License (MIT)
0 ignored issues
show
Coding Style introduced by
Spaces must be used for alignment; tabs are not allowed
Loading history...
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Object\Application\Repository;
38
39
use Apparat\Object\Domain\Repository\AdapterStrategyInterface;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Apparat\Object\Applicati...dapterStrategyInterface.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
40
use Apparat\Object\Domain\Repository\InvalidArgumentException;
41
42
/**
43
 * Abstract adapter strategy
44
 *
45
 * @package Apparat\Object
46
 * @subpackage Apparat\Object\Application
47
 */
48
abstract class AbstractAdapterStrategy implements AdapterStrategyInterface
49
{
50
    /**
51
     * Configuration
52
     *
53
     * Example
54
     *
55
     * @var array
56
     */
57
    protected $_config = null;
58
59
    /**
60
     * Adapter strategy type
61
     *
62
     * @var string
63
     */
64
    const TYPE = 'abstract';
65
66
    /**
67
     * Adapter strategy constructor
68
     *
69
     * @param array $config Adapter strategy configuration
70
     * @param array $signatureConfigKeys Signature relevant configuration properties
71
     */
72 10
    public function __construct(array $config, array $signatureConfigKeys)
73
    {
74 10
        $this->_config = $config;
75
76
        // Build the signature
77 10
        $signatureConfig = array_intersect_key($this->_config, array_flip($signatureConfigKeys));
78 10
        $signatureConfig['type'] = static::TYPE;
79 10
        if (count($signatureConfig) < 2) {
80 1
            throw new InvalidArgumentException(
81 1
                sprintf(
82 1
                    'Invalid adapter strategy signature configuration "%s"',
83 1
                    implode(', ', $signatureConfigKeys)
84 1
                ), InvalidArgumentException::INVALID_ADAPTER_STRATEGY_SIGNATURE
85 1
            );
86
        }
87 9
    }
88
89
    /**
90
     * Return the adapter strategy type
91
     *
92
     * @return string Adapter strategy type
93
     */
94
    public function getType()
95
    {
96
        return static::TYPE;
97
    }
98
}
99