Passed
Push — 8.x ( 129a4a...ab4097 )
by Tim
09:56
created

SimpleConfigurationLoader::getCommandName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Cli\SimpleConfigurationLoader
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-cli-simple
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Cli;
22
23
use Symfony\Component\Console\Input\InputInterface;
24
use Symfony\Component\DependencyInjection\ContainerInterface;
25
use TechDivision\Import\ConfigurationFactoryInterface;
26
use TechDivision\Import\Cli\Command\InputOptionKeys;
27
use TechDivision\Import\Cli\Configuration\LibraryLoader;
28
use TechDivision\Import\Cli\Utils\DependencyInjectionKeys;
29
use TechDivision\Import\Cli\Utils\MagentoConfigurationKeys;
30
use TechDivision\Import\Utils\CommandNames;
31
use TechDivision\Import\Utils\Mappings\CommandNameToEntityTypeCode;
32
33
/**
34
 * The configuration loader implementation.
35
 *
36
 * @author    Tim Wagner <[email protected]>
37
 * @copyright 2016 TechDivision GmbH <[email protected]>
38
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
39
 * @link      https://github.com/techdivision/import-cli-simple
40
 * @link      http://www.techdivision.com
41
 */
42
class SimpleConfigurationLoader implements ConfigurationLoaderInterface
43
{
44
45
    /**
46
     * The key for the Magento Edition in the metadata extracted from the Composer configuration.
47
     *
48
     * @var string
49
     */
50
    const EDITION = 'edition';
51
52
    /**
53
     * The key for the Magento Version in the metadata extracted from the Composer configuration.
54
     *
55
     * @var string
56
     */
57
    const VERSION = 'version';
58
59
    /**
60
     * The container instance.
61
     *
62
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
63
     */
64
    protected $container;
65
66
    /**
67
     * The actual input instance.
68
     *
69
     * @var \Symfony\Component\Console\Input\InputInterface
70
     */
71
    protected $input;
72
73
    /**
74
     * The library loader instance.
75
     *
76
     * @param \TechDivision\Import\Cli\LibraryLoader
77
     */
78
    protected $libraryLoader;
79
80
    /**
81
     * The configuration factory instance.
82
     *
83
     * @var \TechDivision\Import\ConfigurationFactoryInterface
84
     */
85
    protected $configurationFactory;
86
87
    /**
88
     * The available command names.
89
     *
90
     * @var \TechDivision\Import\Utils\CommandNames
91
     */
92
    protected $commandNames;
93
94
    /**
95
     * The mapping of the command names to the entity type codes
96
     *
97
     * @var \TechDivision\Import\Utils\Mappings\CommandNameToEntityTypeCode
98
     */
99
    protected $commandNameToEntityTypeCode;
100
101
    /**
102
     * Initializes the configuration loader.
103
     *
104
     * @param \Symfony\Component\Console\Input\InputInterface                 $input                        The input instance
105
     * @param \Symfony\Component\DependencyInjection\ContainerInterface       $container                    The container instance
106
     * @param \TechDivision\Import\Cli\Configuration\LibraryLoader            $libraryLoader                The configuration loader instance
107
     * @param \TechDivision\Import\ConfigurationFactoryInterface              $configurationFactory         The configuration factory instance
108
     * @param \TechDivision\Import\Utils\CommandNames                         $commandNames                 The available command names
109
     * @param \TechDivision\Import\Utils\Mappings\CommandNameToEntityTypeCode $commandNameToEntityTypeCodes The mapping of the command names to the entity type codes
110
     */
111
    public function __construct(
112
        InputInterface $input,
113
        ContainerInterface $container,
114
        LibraryLoader $libraryLoader,
115
        ConfigurationFactoryInterface $configurationFactory,
116
        CommandNames $commandNames,
117
        CommandNameToEntityTypeCode $commandNameToEntityTypeCodes
118
    ) {
119
120
        // set the passed instances
121
        $this->input = $input;
122
        $this->container = $container;
123
        $this->libraryLoader = $libraryLoader;
124
        $this->configurationFactory = $configurationFactory;
125
        $this->commandNames = $commandNames;
126
        $this->commandNameToEntityTypeCode = $commandNameToEntityTypeCodes;
127
    }
128
129
    /**
130
     * Factory implementation to create a new initialized configuration instance.
131
     *
132
     * If command line options are specified, they will always override the
133
     * values found in the configuration file.
134
     *
135
     * @return \TechDivision\Import\ConfigurationInterface The configuration instance
136
     */
137
    public function load()
138
    {
139
140
        // initially try to create the configuration instance
141
        $instance = $this->createInstance();
142
143
        // we have to set the entity type code at least
144
        $instance->setEntityTypeCode($this->getEntityTypeCode());
145
146
        // query whether or not a system name has been specified as command line option, if yes override the value from the configuration file
147
        if (($this->input->hasOptionSpecified(InputOptionKeys::SYSTEM_NAME) && $this->input->getOption(InputOptionKeys::SYSTEM_NAME)) || $instance->getSystemName() === null) {
0 ignored issues
show
Bug introduced by
The method hasOptionSpecified() does not exist on Symfony\Component\Console\Input\InputInterface. Did you maybe mean hasOption()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

147
        if (($this->input->/** @scrutinizer ignore-call */ hasOptionSpecified(InputOptionKeys::SYSTEM_NAME) && $this->input->getOption(InputOptionKeys::SYSTEM_NAME)) || $instance->getSystemName() === null) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
148
            $instance->setSystemName($this->input->getOption(InputOptionKeys::SYSTEM_NAME));
149
        }
150
151
        // query whether or not a PID filename has been specified as command line option, if yes override the value from the configuration file
152
        if (($this->input->hasOptionSpecified(InputOptionKeys::PID_FILENAME) && $this->input->getOption(InputOptionKeys::PID_FILENAME)) || $instance->getPidFilename() === null) {
153
            $instance->setPidFilename($this->input->getOption(InputOptionKeys::PID_FILENAME));
154
        }
155
156
        // query whether or not a Magento installation directory has been specified as command line option, if yes override the value from the configuration file
157
        if (($this->input->hasOptionSpecified(InputOptionKeys::INSTALLATION_DIR) && $this->input->getOption(InputOptionKeys::INSTALLATION_DIR)) || $instance->getInstallationDir() === null) {
158
            $instance->setInstallationDir($this->input->getOption(InputOptionKeys::INSTALLATION_DIR));
159
        }
160
161
        // query whether or not a Magento Edition has been specified as command line option, if yes override the value from the configuration file
162
        if (($this->input->hasOptionSpecified(InputOptionKeys::MAGENTO_EDITION) && $this->input->getOption(InputOptionKeys::MAGENTO_EDITION)) || $instance->getMagentoEdition() === null) {
163
            $instance->setMagentoEdition($this->input->getOption(InputOptionKeys::MAGENTO_EDITION));
164
        }
165
166
        // query whether or not a Magento Version has been specified as command line option, if yes override the value from the configuration file
167
        if (($this->input->hasOptionSpecified(InputOptionKeys::MAGENTO_VERSION) && $this->input->getOption(InputOptionKeys::MAGENTO_VERSION)) || $instance->getMagentoVersion() === null) {
168
            $instance->setMagentoVersion($this->input->getOption(InputOptionKeys::MAGENTO_VERSION));
169
        }
170
171
        // query whether or not a directory for the source files has been specified as command line option, if yes override the value from the configuration file
172
        if (($this->input->hasOptionSpecified(InputOptionKeys::SOURCE_DIR) && $this->input->getOption(InputOptionKeys::SOURCE_DIR)) || $instance->getSourceDir() === null) {
173
            $instance->setSourceDir($this->input->getOption(InputOptionKeys::SOURCE_DIR));
174
        }
175
176
        // return the initialized configuration instance
177
        return $instance;
178
    }
179
180
    /**
181
     * This method create the configuration instance from the configuration file
182
     * defined by the commandline args and options.
183
     *
184
     * @return \TechDivision\Import\ConfigurationInterface The configuration instance loaded from the configuration file
185
     * @throws \Exception Is thrown, if the specified configuration file doesn't exist or the mandatory arguments/options to run the requested operation are not available
186
     */
187
    protected function createInstance()
188
    {
189
190
        // load the actual vendor directory and entity type code
191
        $vendorDir = $this->getVendorDir();
192
193
        // the path of the JMS serializer directory, relative to the vendor directory
194
        $jmsDir = DIRECTORY_SEPARATOR . 'jms' . DIRECTORY_SEPARATOR . 'serializer' . DIRECTORY_SEPARATOR . 'src';
195
196
        // try to find the path to the JMS Serializer annotations
197
        if (!file_exists($annotationDir = $vendorDir . DIRECTORY_SEPARATOR . $jmsDir)) {
198
            // stop processing, if the JMS annotations can't be found
199
            throw new \Exception(
200
                sprintf(
201
                    'The jms/serializer libarary can not be found in one of "%s"',
202
                    implode(', ', $vendorDir)
0 ignored issues
show
Bug introduced by
$vendorDir of type string is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

202
                    implode(', ', /** @scrutinizer ignore-type */ $vendorDir)
Loading history...
203
                )
204
            );
205
        }
206
207
        // register the autoloader for the JMS serializer annotations
208
        \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(
0 ignored issues
show
Deprecated Code introduced by
The function Doctrine\Common\Annotati...sterAutoloadNamespace() has been deprecated: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists') ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

208
        /** @scrutinizer ignore-deprecated */ \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
209
            'JMS\Serializer\Annotation',
210
            $annotationDir
211
        );
212
213
        // query whether or not, a configuration file has been specified
214
        if ($configuration = $this->input->getOption(InputOptionKeys::CONFIGURATION)) {
215
            // load the configuration from the file with the given filename
216
            return $this->createConfiguration($configuration);
217
        } elseif (($magentoEdition = $this->input->getOption(InputOptionKeys::MAGENTO_EDITION)) && ($magentoVersion = $this->input->getOption(InputOptionKeys::MAGENTO_VERSION))) {
218
            // use the Magento Edition that has been specified as option
219
            $instance = $this->createConfiguration();
220
221
            // override the Magento Edition/Version
222
            $instance->setMagentoEdition($magentoEdition);
223
            $instance->setMagentoVersion($magentoVersion);
224
225
            // return the instance
226
            return $instance;
227
        }
228
229
        // finally, query whether or not the installation directory is a valid Magento root directory
230
        if (!$this->isMagentoRootDir($installationDir = $this->input->getOption(InputOptionKeys::INSTALLATION_DIR))) {
0 ignored issues
show
Bug introduced by
It seems like $installationDir = $this...Keys::INSTALLATION_DIR) can also be of type string[]; however, parameter $dir of TechDivision\Import\Cli\...der::isMagentoRootDir() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

230
        if (!$this->isMagentoRootDir(/** @scrutinizer ignore-type */ $installationDir = $this->input->getOption(InputOptionKeys::INSTALLATION_DIR))) {
Loading history...
231
            throw new \Exception(
232
                sprintf(
233
                    'Directory "%s" is not a valid Magento root directory, please use option "--installation-dir" to specify it',
234
                    $installationDir
0 ignored issues
show
Bug introduced by
It seems like $installationDir can also be of type string[]; however, parameter $args of sprintf() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

234
                    /** @scrutinizer ignore-type */ $installationDir
Loading history...
235
                )
236
            );
237
        }
238
239
        // use the Magento Edition that has been detected by the installation directory
240
        $instance = $this->createConfiguration();
241
242
        // load the Magento Edition from the Composer configuration file
243
        $metadata = $this->getEditionMapping($installationDir);
0 ignored issues
show
Bug introduced by
It seems like $installationDir can also be of type string[]; however, parameter $installationDir of TechDivision\Import\Cli\...er::getEditionMapping() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

243
        $metadata = $this->getEditionMapping(/** @scrutinizer ignore-type */ $installationDir);
Loading history...
244
245
        // extract edition & version from the metadata
246
        $magentoEdition = $metadata[SimpleConfigurationLoader::EDITION];
247
        $magentoVersion = $metadata[SimpleConfigurationLoader::VERSION];
248
249
        // override the Magento Edition/Version
250
        $instance->setMagentoEdition($magentoEdition);
251
        $instance->setMagentoVersion($magentoVersion);
252
253
        // return the instance
254
        return $instance;
255
    }
256
257
    /**
258
     * Create and return a new configuration instance from the passed configuration filename
259
     * after merging additional specified params from the commandline.
260
     *
261
     * @param string|null $filename The configuration filename to use
262
     *
263
     * @return \TechDivision\Import\ConfigurationInterface The configuration instance
264
     */
265
    protected function createConfiguration($filename = null)
266
    {
267
268
        // initialize the params specified with the --params parameter
269
        $params = null;
270
271
        // try to load the params from the commandline
272
        if ($this->input->hasOptionSpecified(InputOptionKeys::PARAMS) && $this->input->getOption(InputOptionKeys::PARAMS)) {
273
            $params = $this->input->getOption(InputOptionKeys::PARAMS);
274
        }
275
276
        // initialize the params file specified with the --params-file parameter
277
        $paramsFile = null;
278
279
        // try to load the path of the params file from the commandline
280
        if ($this->input->hasOptionSpecified(InputOptionKeys::PARAMS_FILE) && $this->input->getOption(InputOptionKeys::PARAMS_FILE)) {
281
            $paramsFile = $this->input->getOption(InputOptionKeys::PARAMS_FILE);
282
        }
283
284
        // if a filename has been passed, try to load the configuration from the file
285
        if (is_file($filename)) {
286
            return $this->configurationFactory->factory($filename, pathinfo($filename, PATHINFO_EXTENSION), $params, $paramsFile);
0 ignored issues
show
Unused Code introduced by
The call to TechDivision\Import\Conf...oryInterface::factory() has too many arguments starting with $params. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

286
            return $this->configurationFactory->/** @scrutinizer ignore-call */ factory($filename, pathinfo($filename, PATHINFO_EXTENSION), $params, $paramsFile);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
287
        }
288
289
        // initialize the array for the directories
290
        $directories = array();
291
292
        // set the default file format
293
        $format = 'json';
294
295
        // load the actual vendor directory and entity type code
296
        $vendorDir = $this->getVendorDir();
297
298
        // load the default configuration directory from the DI configuration
299
        $defaultConfigurationDirectory = $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_DEFAULT_CONFIGURATION_DIR);
300
301
        // load the directories that has to be parsed for configuration files1
302
        foreach ($this->getDefaultLibraries() as $defaultLibrary) {
303
            // initialize the directory name
304
            $directory = implode(
305
                DIRECTORY_SEPARATOR,
306
                array_merge(
307
                    array($vendorDir),
308
                    explode('/', $defaultLibrary),
309
                    explode('/', $defaultConfigurationDirectory)
310
                )
311
            );
312
313
            // query whether or not the directory is available1
314
            if (is_dir($directory)) {
315
                $directories[] = $directory;
316
            }
317
        }
318
319
        // initialize the default custom configuration directory
320
        $customConfigurationDirectory = implode(
321
            DIRECTORY_SEPARATOR,
322
            array_merge(
323
                array(getcwd()),
324
                explode('/', $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_CUSTOM_CONFIGURATION_DIR))
325
            )
326
        );
327
328
        // query whether or not a custom configuration directory has been speified, if yes override the default one
329
        if ($this->input->hasOptionSpecified(InputOptionKeys::CUSTOM_CONFIGURATION_DIR) && $this->input->getOption(InputOptionKeys::CUSTOM_CONFIGURATION_DIR)) {
330
            $customConfigurationDirectory = $this->input->getOption(InputOptionKeys::CUSTOM_CONFIGURATION_DIR);
331
        }
332
333
        // specify the default directory for custom configuration files
334
        if (is_dir($customConfigurationDirectory)) {
0 ignored issues
show
Bug introduced by
It seems like $customConfigurationDirectory can also be of type string[]; however, parameter $filename of is_dir() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

334
        if (is_dir(/** @scrutinizer ignore-type */ $customConfigurationDirectory)) {
Loading history...
335
            $directories[] = $customConfigurationDirectory;
336
        }
337
338
        // load and return the configuration from the files found in the passed directories
339
        return $this->configurationFactory->factoryFromDirectories($directories, $format, $params, $paramsFile);
0 ignored issues
show
Bug introduced by
It seems like $params can also be of type string[]; however, parameter $params of TechDivision\Import\Conf...actoryFromDirectories() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

339
        return $this->configurationFactory->factoryFromDirectories($directories, $format, /** @scrutinizer ignore-type */ $params, $paramsFile);
Loading history...
Bug Best Practice introduced by
The expression return $this->configurat..., $params, $paramsFile) returns the type void which is incompatible with the documented return type TechDivision\Import\ConfigurationInterface.
Loading history...
Bug introduced by
Are you sure the usage of $this->configurationFact..., $params, $paramsFile) targeting TechDivision\Import\Conf...actoryFromDirectories() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
It seems like $paramsFile can also be of type string[]; however, parameter $paramsFile of TechDivision\Import\Conf...actoryFromDirectories() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

339
        return $this->configurationFactory->factoryFromDirectories($directories, $format, $params, /** @scrutinizer ignore-type */ $paramsFile);
Loading history...
340
    }
341
342
    /**
343
     * Return's the DI container instance.
344
     *
345
     * @return \Symfony\Component\DependencyInjection\ContainerInterface The DI container instance
346
     */
347
    protected function getContainer()
348
    {
349
        return $this->container;
350
    }
351
352
    /**
353
     * Return's the absolute path to the actual vendor directory.
354
     *
355
     * @return string The absolute path to the actual vendor directory
356
     * @throws \Exception Is thrown, if none of the possible vendor directories can be found
357
     */
358
    protected function getVendorDir()
359
    {
360
        return $this->getContainer()->getParameter(DependencyInjectionKeys::CONFIGURATION_VENDOR_DIR);
361
    }
362
363
    /**
364
     * Return's the actual command name.
365
     *
366
     * @return string The actual command name
367
     */
368
    protected function getCommandName()
369
    {
370
        return $this->input->getArgument('command');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->input->getArgument('command') also could return the type string[] which is incompatible with the documented return type string.
Loading history...
371
    }
372
373
    /**
374
     * Return's the command's entity type code.
375
     *
376
     * @return string The command's entity type code
377
     * @throws \Exception Is thrown, if the command name can not be mapped
378
     */
379
    protected function getEntityTypeCode()
380
    {
381
382
        // try to map the command name to a entity type code
383
        if (array_key_exists($commandName = $this->getCommandName(), (array) $this->commandNameToEntityTypeCode)) {
384
            return $this->commandNameToEntityTypeCode[$commandName];
385
        }
386
387
        // throw an exception if not possible
388
        throw new \Exception(sprintf('Can\'t map command name %s to a entity type', $commandName));
389
    }
390
391
    /**
392
     * Returns the mapped Magento Edition from the passed Magento installation.
393
     *
394
     * @param string $installationDir The Magento installation directory
395
     *
396
     * @return array The array with the mapped Magento Edition (either CE or EE) + the Version
397
     * @throws \Exception Is thrown, if the passed installation directory doesn't contain a valid Magento installation
398
     */
399
    protected function getEditionMapping($installationDir)
400
    {
401
402
        // load the default edition mappings from the configuration
403
        $editionMappings = $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_EDITION_MAPPINGS);
404
405
        // load the composer file from the Magento root directory
406
        $composer = json_decode(file_get_contents($composerFile = sprintf('%s/composer.json', $installationDir)), true);
407
408
        // try to load and explode the Magento Edition identifier from the Composer name
409
        $explodedEdition = explode('/', $composer[MagentoConfigurationKeys::COMPOSER_EDITION_NAME_ATTRIBUTE]);
410
411
        // try to load and explode the Magento Edition from the Composer configuration
412
        if (!isset($editionMappings[$possibleEdition = end($explodedEdition)])) {
413
            throw new \Exception(
414
                sprintf(
415
                    '"%s" detected in "%s" is not a valid Magento Edition, please set Magento Edition with the "--magento-edition" option',
416
                    $possibleEdition,
417
                    $composerFile
418
                )
419
            );
420
        }
421
422
        // try to load and explode the Magento Version from the Composer configuration
423
        if (!isset($composer[MagentoConfigurationKeys::COMPOSER_EDITION_VERSION_ATTRIBUTE])) {
424
            throw new \Exception(
425
                sprintf(
426
                    'Can\'t detect a version in "%s", please set Magento Version with the "--magento-version" option',
427
                    $composerFile
428
                )
429
            );
430
        }
431
432
        // return the array with the Magento Version/Edition data
433
        return array(
434
            SimpleConfigurationLoader::VERSION => $composer[MagentoConfigurationKeys::COMPOSER_EDITION_VERSION_ATTRIBUTE],
435
            SimpleConfigurationLoader::EDITION => $editionMappings[$possibleEdition]
436
        );
437
    }
438
439
440
    /**
441
     * Return's the application's default libraries.
442
     *
443
     * @return array The default libraries
444
     */
445
    protected function getDefaultLibraries()
446
    {
447
448
        // load the default libraries from the configuration
449
        $defaultLibraries = $this->getContainer()->getParameter(DependencyInjectionKeys::APPLICATION_DEFAULT_LIBRARIES);
450
451
        // initialize the array for the libraries
452
        $libraries = array();
453
454
        // append each library only ONCE
455
        foreach ($defaultLibraries as $libraries) {
456
            foreach ($libraries as $library) {
457
                if (in_array($library, $libraries)) {
458
                    continue;
459
                }
460
                // append the library
461
                $libraries[] = $library;
462
            }
463
        }
464
465
        // return the array with the libraries
466
        return $libraries;
467
    }
468
469
    /**
470
     * Query whether or not, the passed directory is a Magento root directory.
471
     *
472
     * @param string $dir The directory to query
473
     *
474
     * @return boolean TRUE if the directory is a Magento root directory, else FALSE
475
     */
476
    protected function isMagentoRootDir($dir)
477
    {
478
        return is_file($this->getMagentoEnv($dir));
479
    }
480
481
    /**
482
     * Return's the path to the Magento file with the environment configuration.
483
     *
484
     * @param string $dir The path to the Magento root directory
485
     *
486
     * @return string The path to the Magento file with the environment configuration
487
     */
488
    protected function getMagentoEnv($dir)
489
    {
490
        return sprintf('%s/app/etc/env.php', $dir);
491
    }
492
}
493