Completed
Pull Request — master (#132)
by
unknown
06:43 queued 04:56
created

AdapterContainer::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of Zippy.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Alchemy\Zippy\Adapter;
13
14
use Alchemy\Zippy\Adapter\BSDTar\TarBSDTarAdapter;
15
use Alchemy\Zippy\Adapter\BSDTar\TarBz2BSDTarAdapter;
16
use Alchemy\Zippy\Adapter\BSDTar\TarGzBSDTarAdapter;
17
use Alchemy\Zippy\Adapter\GNUTar\TarBz2GNUTarAdapter;
18
use Alchemy\Zippy\Adapter\GNUTar\TarGNUTarAdapter;
19
use Alchemy\Zippy\Adapter\GNUTar\TarGzGNUTarAdapter;
20
use Alchemy\Zippy\Resource\RequestMapper;
21
use Alchemy\Zippy\Resource\ResourceManager;
22
use Alchemy\Zippy\Resource\ResourceTeleporter;
23
use Alchemy\Zippy\Resource\TargetLocator;
24
use Alchemy\Zippy\Resource\TeleporterContainer;
25
use Symfony\Component\Filesystem\Filesystem;
26
use Symfony\Component\Process\ExecutableFinder;
27
28
class AdapterContainer implements \ArrayAccess
29
{
30
31
    private $items = array();
32
33
    /**
34
     * Builds the adapter container
35
     *
36
     * @return AdapterContainer
37
     */
38
    public static function load()
39
    {
40
        $container = new static();
41
42
        $container['zip.inflator'] = null;
43
        $container['zip.deflator'] = null;
44
45
        $container['resource-manager'] = function($container) {
46
            return new ResourceManager(
47
                $container['request-mapper'],
48
                $container['resource-teleporter'],
49
                $container['filesystem']
50
            );
51
        };
52
53
        $container['executable-finder'] = function($container) {
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
54
            return new ExecutableFinder();
55
        };
56
57
        $container['request-mapper'] = function($container) {
58
            return new RequestMapper($container['target-locator']);
59
        };
60
61
        $container['target-locator'] = function() {
62
            return new TargetLocator();
63
        };
64
65
        $container['teleporter-container'] = function($container) {
0 ignored issues
show
Unused Code introduced by
The parameter $container is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
66
            return TeleporterContainer::load();
67
        };
68
69
        $container['resource-teleporter'] = function($container) {
70
            return new ResourceTeleporter($container['teleporter-container']);
71
        };
72
73
        $container['filesystem'] = function() {
74
            return new Filesystem();
75
        };
76
77
        $container['Alchemy\\Zippy\\Adapter\\ZipAdapter'] = function($container) {
78
            return ZipAdapter::newInstance(
79
                $container['executable-finder'],
80
                $container['resource-manager'],
81
                $container['zip.inflator'],
82
                $container['zip.deflator']
83
            );
84
        };
85
86
        $container['gnu-tar.inflator'] = null;
87
        $container['gnu-tar.deflator'] = null;
88
89 View Code Duplication
        $container['Alchemy\\Zippy\\Adapter\\GNUTar\\TarGNUTarAdapter'] = function($container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
90
            return TarGNUTarAdapter::newInstance(
91
                $container['executable-finder'],
92
                $container['resource-manager'],
93
                $container['gnu-tar.inflator'],
94
                $container['gnu-tar.deflator']
95
            );
96
        };
97
98 View Code Duplication
        $container['Alchemy\\Zippy\\Adapter\\GNUTar\\TarGzGNUTarAdapter'] = function($container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
99
            return TarGzGNUTarAdapter::newInstance(
100
                $container['executable-finder'],
101
                $container['resource-manager'],
102
                $container['gnu-tar.inflator'],
103
                $container['gnu-tar.deflator']
104
            );
105
        };
106
107 View Code Duplication
        $container['Alchemy\\Zippy\\Adapter\\GNUTar\\TarBz2GNUTarAdapter'] = function($container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
108
            return TarBz2GNUTarAdapter::newInstance(
109
                $container['executable-finder'],
110
                $container['resource-manager'],
111
                $container['gnu-tar.inflator'],
112
                $container['gnu-tar.deflator']
113
            );
114
        };
115
116
        $container['bsd-tar.inflator'] = null;
117
        $container['bsd-tar.deflator'] = null;
118
119 View Code Duplication
        $container['Alchemy\\Zippy\\Adapter\\BSDTar\\TarBSDTarAdapter'] = function($container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
120
            return TarBSDTarAdapter::newInstance(
121
                $container['executable-finder'],
122
                $container['resource-manager'],
123
                $container['bsd-tar.inflator'],
124
                $container['bsd-tar.deflator']
125
            );
126
        };
127
128 View Code Duplication
        $container['Alchemy\\Zippy\\Adapter\\BSDTar\\TarGzBSDTarAdapter'] = function($container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
129
            return TarGzBSDTarAdapter::newInstance(
130
                $container['executable-finder'],
131
                $container['resource-manager'],
132
                $container['bsd-tar.inflator'],
133
                $container['bsd-tar.deflator']
134
            );
135
        };
136
137 View Code Duplication
        $container['Alchemy\\Zippy\\Adapter\\BSDTar\\TarBz2BSDTarAdapter'] = function($container) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
138
            return TarBz2BSDTarAdapter::newInstance(
139
                $container['executable-finder'],
140
                $container['resource-manager'],
141
                $container['bsd-tar.inflator'],
142
                $container['bsd-tar.deflator']);
143
        };
144
145
        $container['Alchemy\\Zippy\\Adapter\\ZipExtensionAdapter'] = function() {
146
            return ZipExtensionAdapter::newInstance();
147
        };
148
149
        return $container;
150
    }
151
152
    /**
153
     * (PHP 5 &gt;= 5.0.0)<br/>
154
     * Whether a offset exists
155
     *
156
     * @link http://php.net/manual/en/arrayaccess.offsetexists.php
157
     *
158
     * @param mixed $offset <p>
159
     *                      An offset to check for.
160
     *                      </p>
161
     *
162
     * @return bool true on success or false on failure.
163
     * <p>The return value will be casted to boolean if non-boolean was returned.</p>
164
     */
165
    public function offsetExists($offset)
166
    {
167
        return isset($this->items[$offset]);
168
    }
169
170
    /**
171
     * (PHP 5 &gt;= 5.0.0)<br/>
172
     * Offset to retrieve
173
     * @link http://php.net/manual/en/arrayaccess.offsetget.php
174
     * @param mixed $offset <p>
175
     * The offset to retrieve.
176
     * </p>
177
     * @return mixed Can return all value types.
178
     */
179
    public function offsetGet($offset)
180
    {
181
        if (array_key_exists($offset, $this->items) && is_callable($this->items[$offset])) {
182
            $this->items[$offset] = call_user_func($this->items[$offset], $this);
183
        }
184
185
        if (array_key_exists($offset, $this->items)) {
186
            return $this->items[$offset];
187
        }
188
189
        throw new \InvalidArgumentException();
190
    }
191
192
    /**
193
     * (PHP 5 &gt;= 5.0.0)<br/>
194
     * Offset to set
195
     * @link http://php.net/manual/en/arrayaccess.offsetset.php
196
     * @param mixed $offset <p>
197
     * The offset to assign the value to.
198
     * </p>
199
     * @param mixed $value <p>
200
     * The value to set.
201
     * </p>
202
     * @return void
203
     */
204
    public function offsetSet($offset, $value)
205
    {
206
        $this->items[$offset] = $value;
207
    }
208
209
    /**
210
     * (PHP 5 &gt;= 5.0.0)<br/>
211
     * Offset to unset
212
     * @link http://php.net/manual/en/arrayaccess.offsetunset.php
213
     * @param mixed $offset <p>
214
     * The offset to unset.
215
     * </p>
216
     * @return void
217
     */
218
    public function offsetUnset($offset)
219
    {
220
        unset($this->items[$offset]);
221
    }
222
}
223