Completed
Push — 15.x ( 481d54...fbe8db )
by Tim
01:46
created

Configuration::getLogLevel()   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 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Configuration\Jms\Configuration
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-configuration-jms
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Configuration\Jms;
22
23
use Psr\Log\LogLevel;
24
use Doctrine\Common\Collections\ArrayCollection;
25
use JMS\Serializer\Annotation\Type;
26
use JMS\Serializer\Annotation\Exclude;
27
use JMS\Serializer\Annotation\SerializedName;
28
use JMS\Serializer\Annotation\PostDeserialize;
29
use JMS\Serializer\Annotation\ExclusionPolicy;
30
use TechDivision\Import\ConfigurationInterface;
31
use TechDivision\Import\Configuration\DatabaseConfigurationInterface;
32
use TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait;
33
use TechDivision\Import\Configuration\Jms\Configuration\CsvTrait;
34
use TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait;
35
use TechDivision\Import\Configuration\ListenerAwareConfigurationInterface;
36
use TechDivision\Import\Configuration\OperationConfigurationInterface;
37
38
/**
39
 * A simple JMS based configuration implementation.
40
 *
41
 * @author    Tim Wagner <[email protected]>
42
 * @copyright 2016 TechDivision GmbH <[email protected]>
43
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
44
 * @link      https://github.com/techdivision/import-configuration-jms
45
 * @link      http://www.techdivision.com
46
 *
47
 * @ExclusionPolicy("none")
48
 */
49
class Configuration implements ConfigurationInterface, ListenerAwareConfigurationInterface
50
{
51
52
    /**
53
     * The default PID filename to use.
54
     *
55
     * @var string
56
     */
57
    const PID_FILENAME = 'importer.pid';
58
59
    /**
60
     * Trait that provides CSV configuration functionality.
61
     *
62
     * @var \TechDivision\Import\Configuration\Jms\Configuration\CsvTrait
63
     */
64
    use CsvTrait;
65
66
    /**
67
     * Trait that provides CSV configuration functionality.
68
     *
69
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ParamsTrait
70
     */
71
    use ParamsTrait;
72
73
    /**
74
     * Trait that provides CSV configuration functionality.
75
     *
76
     * @var \TechDivision\Import\Configuration\Jms\Configuration\ListenersTrait
77
     */
78
    use ListenersTrait;
79
80
    /**
81
     * The array with the available database types.
82
     *
83
     * @var array
84
     * @Exclude
85
     */
86
    protected $availableDatabaseTypes = array(
87
        DatabaseConfigurationInterface::TYPE_MYSQL,
88
        DatabaseConfigurationInterface::TYPE_REDIS
89
    );
90
91
    /**
92
     * The operation names to be executed.
93
     *
94
     * @var array
95
     * @Exclude
96
     */
97
    protected $operationNames = array();
98
99
    /**
100
     * Mapping for boolean values passed on the console.
101
     *
102
     * @var array
103
     * @Exclude
104
     */
105
    protected $booleanMapping = array(
106
        'true'  => true,
107
        'false' => false,
108
        '1'     => true,
109
        '0'     => false,
110
        'on'    => true,
111
        'off'   => false
112
    );
113
114
    /**
115
     * The serial that will be passed as commandline option (can not be specified in configuration file).
116
     *
117
     * @var string
118
     * @Exclude
119
     */
120
    protected $serial;
121
122
    /**
123
     * The shortcut that maps the operation names that has to be executed.
124
     *
125
     * @var string
126
     * @Exclude
127
     */
128
    protected $shortcut;
129
130
    /**
131
     * The prefix for the move files subject.
132
     *
133
     * @var string
134
     * @Exclude
135
     */
136
    protected $moveFilesPrefix;
137
138
    /**
139
     * The name of the command that has been invoked.
140
     *
141
     * @var string
142
     * @Exclude
143
     */
144
    protected $commandName;
145
146
    /**
147
     * The application's unique DI identifier.
148
     *
149
     * @var string
150
     * @Type("string")
151
     * @SerializedName("id")
152
     */
153
    protected $id;
154
155
    /**
156
     * The system name to use.
157
     *
158
     * @var string
159
     * @Type("string")
160
     * @SerializedName("system-name")
161
     */
162
    protected $systemName;
163
164
    /**
165
     * The entity type code to use.
166
     *
167
     * @var string
168
     * @Type("string")
169
     * @SerializedName("entity-type-code")
170
     */
171
    protected $entityTypeCode;
172
173
    /**
174
     * The Magento installation directory.
175
     *
176
     * @var string
177
     * @Type("string")
178
     * @SerializedName("installation-dir")
179
     */
180
    protected $installationDir;
181
182
    /**
183
     * The source directory that has to be watched for new files.
184
     *
185
     * @var string
186
     * @Type("string")
187
     * @SerializedName("source-dir")
188
     */
189
    protected $sourceDir;
190
191
    /**
192
     * The target directory with the files that has been imported.
193
     *
194
     * @var string
195
     * @Type("string")
196
     * @SerializedName("target-dir")
197
     */
198
    protected $targetDir;
199
200
    /**
201
     * The Magento edition, EE or CE.
202
     *
203
     * @var string
204
     * @Type("string")
205
     * @SerializedName("magento-edition")
206
     */
207
    protected $magentoEdition = 'CE';
208
209
    /**
210
     * The Magento version, e. g. 2.2.0.
211
     *
212
     * @var string
213
     * @Type("string")
214
     * @SerializedName("magento-version")
215
     */
216
    protected $magentoVersion = '2.2.0';
217
218
    /**
219
     * ArrayCollection with the information of the configured databases.
220
     *
221
     * @var \Doctrine\Common\Collections\ArrayCollection
222
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Database>")
223
     */
224
    protected $databases;
225
226
    /**
227
     * ArrayCollection with the information of the configured loggers.
228
     *
229
     * @var \Doctrine\Common\Collections\ArrayCollection
230
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Logger>")
231
     */
232
    protected $loggers;
233
234
    /**
235
     * ArrayCollection with the information of the configured operations.
236
     *
237
     * @var \Doctrine\Common\Collections\ArrayCollection
238
     * @Type("array<string, array<string, ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Operation>>>")
239
     */
240
    protected $operations;
241
242
    /**
243
     * The subject's multiple field delimiter character for fields with multiple values, defaults to (,).
244
     *
245
     * @var string
246
     * @Type("string")
247
     * @SerializedName("multiple-field-delimiter")
248
     */
249
    protected $multipleFieldDelimiter = ',';
250
251
    /**
252
     * The subject's multiple value delimiter character for fields with multiple values, defaults to (|).
253
     *
254
     * @var string
255
     * @Type("string")
256
     * @SerializedName("multiple-value-delimiter")
257
     */
258
    protected $multipleValueDelimiter = '|';
259
260
    /**
261
     * The flag to signal that the subject has to use the strict mode or not.
262
     *
263
     * @var boolean
264
     * @Type("boolean")
265
     * @SerializedName("strict-mode")
266
     */
267
    protected $strictMode;
268
269
    /**
270
     * The flag whether or not the import artefacts have to be archived.
271
     *
272
     * @var boolean
273
     * @Type("boolean")
274
     * @SerializedName("archive-artefacts")
275
     */
276
    protected $archiveArtefacts;
277
278
    /**
279
     * The directory where the archives will be stored.
280
     *
281
     * @var string
282
     * @Type("string")
283
     * @SerializedName("archive-dir")
284
     */
285
    protected $archiveDir;
286
287
    /**
288
     * The flag to signal that the subject has to use the debug mode or not.
289
     *
290
     * @var boolean
291
     * @Type("boolean")
292
     * @SerializedName("debug-mode")
293
     */
294
    protected $debugMode = false;
295
296
    /**
297
     * The log level to use (see Monolog documentation).
298
     *
299
     * @var string
300
     * @Type("string")
301
     * @SerializedName("log-level")
302
     */
303
    protected $logLevel = LogLevel::INFO;
304
305
    /**
306
     * The explicit DB ID to use.
307
     *
308
     * @var string
309
     * @Type("string")
310
     * @SerializedName("use-db-id")
311
     */
312
    protected $useDbId;
313
314
    /**
315
     * The explicit PID filename to use.
316
     *
317
     * @var string
318
     * @Type("string")
319
     * @SerializedName("pid-filename")
320
     */
321
    protected $pidFilename;
322
323
    /**
324
     * The collection with the paths to additional vendor directories.
325
     *
326
     * @var \Doctrine\Common\Collections\ArrayCollection
327
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\VendorDir>")
328
     * @SerializedName("additional-vendor-dirs")
329
     */
330
    protected $additionalVendorDirs;
331
332
    /**
333
     * The array with the Magento Edition specific extension libraries.
334
     *
335
     * @var array
336
     * @Type("array")
337
     * @SerializedName("extension-libraries")
338
     */
339
    protected $extensionLibraries = array();
340
341
    /**
342
     * The array with the custom header mappings.
343
     *
344
     * @var array
345
     * @Type("array")
346
     * @SerializedName("header-mappings")
347
     */
348
    protected $headerMappings = array();
349
350
    /**
351
     * The array with the custom image types.
352
     *
353
     * @var array
354
     * @Type("array")
355
     * @SerializedName("image-types")
356
     */
357
    protected $imageTypes = array();
358
359
    /**
360
     * The flag to signal that the import should be wrapped within a single transation or not.
361
     *
362
     * @var boolean
363
     * @Type("boolean")
364
     * @SerializedName("single-transaction")
365
     */
366
    protected $singleTransaction = false;
367
368
    /**
369
     * The flag to signal that the cache should be enabled or not.
370
     *
371
     * @var boolean
372
     * @Type("boolean")
373
     * @SerializedName("cache-enabled")
374
     */
375
    protected $cacheEnabled = true;
376
377
    /**
378
     * ArrayCollection with the information of the configured aliases.
379
     *
380
     * @var \Doctrine\Common\Collections\ArrayCollection
381
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Alias>")
382
     */
383
    protected $aliases;
384
385
    /**
386
     * ArrayCollection with the information of the configured caches.
387
     *
388
     * @var \Doctrine\Common\Collections\ArrayCollection
389
     * @Type("ArrayCollection<TechDivision\Import\Configuration\Jms\Configuration\Cache>")
390
     */
391
    protected $caches;
392
393
    /**
394
     * The array with the shortcuts.
395
     *
396
     * @var array
397
     * @Type("array<string, array<string, array>>")
398
     * @SerializedName("shortcuts")
399
     */
400
    protected $shortcuts = array();
401
402
    /**
403
     * The username to save the import history with.
404
     *
405
     * @var string
406
     * @Type("string")
407
     */
408
    protected $username;
409
410
    /**
411
     * Lifecycle callback that will be invoked after deserialization.
412
     *
413
     * @return void
414
     * @PostDeserialize
415
     */
416
    public function postDeserialize()
417
    {
418
419
        // create an empty collection if no loggers has been specified
420
        if ($this->loggers === null) {
421
            $this->loggers = new ArrayCollection();
422
        }
423
424
        // create an empty collection if no operations has been specified
425
        if ($this->operations === null) {
426
            $this->operations = new ArrayCollection();
427
        }
428
429
        // create an empty collection if no additional venor directories has been specified
430
        if ($this->additionalVendorDirs === null) {
431
            $this->additionalVendorDirs = new ArrayCollection();
432
        }
433
434
        // create an empty collection if no caches has been specified
435
        if ($this->caches === null) {
436
            $this->caches = new ArrayCollection();
437
        }
438
439
        // create an empty collection if no aliases has been specified
440
        if ($this->aliases === null) {
441
            $this->aliases = new ArrayCollection();
442
        }
443
    }
444
445
    /**
446
     * Map's the passed value to a boolean.
447
     *
448
     * @param string $value The value to map
449
     *
450
     * @return boolean The mapped value
451
     * @throws \Exception Is thrown, if the value can't be mapped
452
     */
453
    public function mapBoolean($value)
454
    {
455
456
        // try to map the passed value to a boolean
457
        if (isset($this->booleanMapping[$val = strtolower($value)])) {
458
            return $this->booleanMapping[$val];
459
        }
460
461
        // throw an exception if we can't convert the passed value
462
        throw new \Exception(sprintf('Can\'t convert %s to boolean', $value));
463
    }
464
465
    /**
466
     * Return's the application's unique DI identifier.
467
     *
468
     * @return string The application's unique DI identifier
469
     */
470
    public function getId()
471
    {
472
        return $this->id;
473
    }
474
475
    /**
476
     * Add's the operation with the passed name ot the operations that has to be executed.
477
     *
478
     * If the operation name has already been added, it'll not be added again.
479
     *
480
     * @param string  $operationName The operation to be executed
481
     * @param boolean $prepend       TRUE if the operation name should be prepended, else FALSE
482
     *
483
     * @return void
484
     */
485
    public function addOperationName($operationName, $prepend = false)
486
    {
487
488
        // do nothing if the operation has already been added
489
        if (in_array($operationName, $this->operationNames)) {
490
            return;
491
        }
492
493
        // add the operation otherwise
494
        $prepend ? array_unshift($this->operationNames, $operationName) : array_push($this->operationNames, $operationName);
495
    }
496
497
    /**
498
     * Return's the operation names that has to be executed.
499
     *
500
     * @param array $operationNames The operation names that has to be executed
501
     *
502
     * @return void
503
     */
504
    public function setOperationNames(array $operationNames)
505
    {
506
        return $this->operationNames = $operationNames;
507
    }
508
509
    /**
510
     * Return's the operation names that has to be executed.
511
     *
512
     * @return array The operation names that has to be executed
513
     */
514
    public function getOperationNames()
515
    {
516
        return $this->operationNames;
517
    }
518
519
    /**
520
     * Queries whether or not the passed operation has to be exceuted or not.
521
     *
522
     * @param \TechDivision\Import\Configuration\OperationConfigurationInterface $operation The operation to query for
523
     *
524
     * @return boolean TRUE if the operation has to be executed, else FALSE
525
     */
526
    public function inOperationNames(OperationConfigurationInterface $operation)
527
    {
528
        return in_array($operation->getName(), $this->getOperationNames());
529
    }
530
531
    /**
532
     * Set's the Magento installation directory.
533
     *
534
     * @param string $installationDir The Magento installation directory
535
     *
536
     * @return void
537
     */
538
    public function setInstallationDir($installationDir)
539
    {
540
        $this->installationDir = $installationDir;
541
    }
542
543
    /**
544
     * Return's the Magento installation directory.
545
     *
546
     * @return string The Magento installation directory
547
     */
548
    public function getInstallationDir()
549
    {
550
        return $this->installationDir;
551
    }
552
553
    /**
554
     * Set's the source directory that has to be watched for new files.
555
     *
556
     * @param string $sourceDir The source directory
557
     *
558
     * @return void
559
     */
560
    public function setSourceDir($sourceDir)
561
    {
562
        $this->sourceDir = $sourceDir;
563
    }
564
565
    /**
566
     * Return's the source directory that has to be watched for new files.
567
     *
568
     * @return string The source directory
569
     */
570
    public function getSourceDir()
571
    {
572
        return $this->sourceDir;
573
    }
574
575
    /**
576
     * Set's the target directory with the files that has been imported.
577
     *
578
     * @param string $targetDir The target directory
579
     *
580
     * @return void
581
     */
582
    public function setTargetDir($targetDir)
583
    {
584
        $this->targetDir = $targetDir;
585
    }
586
587
    /**
588
     * Return's the target directory with the files that has been imported.
589
     *
590
     * @return string The target directory
591
     */
592
    public function getTargetDir()
593
    {
594
        return $this->targetDir;
595
    }
596
597
    /**
598
     * Set's the Magento edition, EE or CE.
599
     *
600
     * @param string $magentoEdition The Magento edition
601
     *
602
     * @return void
603
     */
604
    public function setMagentoEdition($magentoEdition)
605
    {
606
        $this->magentoEdition = $magentoEdition;
607
    }
608
609
    /**
610
     * Return's the Magento edition, EE or CE.
611
     *
612
     * @return string The Magento edition
613
     */
614
    public function getMagentoEdition()
615
    {
616
        return $this->magentoEdition;
617
    }
618
619
    /**
620
     * Return's the Magento version, e. g. 2.1.0.
621
     *
622
     * @param string $magentoVersion The Magento version
623
     *
624
     * @return void
625
     */
626
    public function setMagentoVersion($magentoVersion)
627
    {
628
        $this->magentoVersion = $magentoVersion;
629
    }
630
631
    /**
632
     * Return's the Magento version, e. g. 2.1.0.
633
     *
634
     * @return string The Magento version
635
     */
636
    public function getMagentoVersion()
637
    {
638
        return $this->magentoVersion;
639
    }
640
641
    /**
642
     * Return's the entity type code to be used.
643
     *
644
     * @return string The entity type code to be used
645
     */
646
    public function getEntityTypeCode()
647
    {
648
        return $this->entityTypeCode;
649
    }
650
651
    /**
652
     * Set's the entity type code to be used.
653
     *
654
     * @param string $entityTypeCode The entity type code
655
     *
656
     * @return void
657
     */
658
    public function setEntityTypeCode($entityTypeCode)
659
    {
660
        $this->entityTypeCode = $entityTypeCode;
661
    }
662
663
    /**
664
     * Return's the multiple field delimiter character to use, default value is comma (,).
665
     *
666
     * @return string The multiple field delimiter character
667
     */
668
    public function getMultipleFieldDelimiter()
669
    {
670
        return $this->multipleFieldDelimiter;
671
    }
672
673
    /**
674
     * Return's the multiple value delimiter character to use, default value is comma (|).
675
     *
676
     * @return string The multiple value delimiter character
677
     */
678
    public function getMultipleValueDelimiter()
679
    {
680
        return $this->multipleValueDelimiter;
681
    }
682
683
    /**
684
     * Queries whether or not strict mode is enabled or not, default is TRUE.
685
     *
686
     * @return boolean TRUE if strict mode is enabled, else FALSE
687
     */
688
    public function isStrictMode()
689
    {
690
        return $this->strictMode;
691
    }
692
693
    /**
694
     * Remove's all configured database configuration.
695
     *
696
     * @return void
697
     */
698
    public function clearDatabases()
699
    {
700
        $this->databases->clear();
701
    }
702
703
    /**
704
     * Add's the passed database configuration.
705
     *
706
     * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration
707
     *
708
     * @return void
709
     */
710
    public function addDatabase(DatabaseConfigurationInterface $database)
711
    {
712
        $this->databases->add($database);
713
    }
714
715
    /**
716
     * Return's the number database configurations.
717
     *
718
     * @return integer The number of database configurations
719
     */
720
    public function countDatabases()
721
    {
722
        return $this->databases->count();
723
    }
724
725
    /**
726
     * Return's the database configuration with the passed ID.
727
     *
728
     * @param string $id The ID of the database connection to return
729
     *
730
     * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration
731
     * @throws \Exception Is thrown, if no database configuration is available
732
     */
733
    public function getDatabaseById($id)
734
    {
735
736
        // iterate over the configured databases and return the one with the passed ID
737
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
738
        foreach ($this->databases as $database) {
739
            if ($database->getId() === $id && $this->isValidDatabaseType($database)) {
740
                return $database;
741
            }
742
        }
743
744
        // throw an exception, if the database with the passed ID is NOT configured
745
        throw new \Exception(sprintf('Database with ID %s can not be found or has an invalid type', $id));
746
    }
747
748
    /**
749
     * Return's the databases for the given type.
750
     *
751
     * @param string $type The database type to return the configurations for
752
     *
753
     * @return \Doctrine\Common\Collections\Collection The collection with the database configurations
754
     */
755
    public function getDatabasesByType($type)
756
    {
757
758
        // initialize the collection for the database configurations
759
        $databases = new ArrayCollection();
760
761
        // iterate over the configured databases and return the one with the passed ID
762
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
763
        foreach ($this->databases as $database) {
764
            if ($database->getType() === $type && $this->isValidDatabaseType($database)) {
765
                $databases->add($database);
766
            }
767
        }
768
769
        // return the database configurations
770
        return $databases;
771
    }
772
773
    /**
774
     * Query's whether or not the passed database configuration has a valid type.
775
     *
776
     * @param \TechDivision\Import\Configuration\DatabaseConfigurationInterface $database The database configuration
777
     *
778
     * @return boolean TRUE if the passed database configuration has a valid type, else FALSE
779
     */
780
    protected function isValidDatabaseType(DatabaseConfigurationInterface $database)
781
    {
782
        return in_array(strtolower($database->getType()), $this->availableDatabaseTypes);
783
    }
784
785
    /**
786
     * Return's the database configuration.
787
     *
788
     * If an explicit DB ID is specified, the method tries to return the database with this ID. If
789
     * the database configuration is NOT available, an execption is thrown.
790
     *
791
     * If no explicit DB ID is specified, the method tries to return the default database configuration,
792
     * if not available the first one.
793
     *
794
     * @return \TechDivision\Import\Configuration\DatabaseConfigurationInterface The database configuration
795
     * @throws \Exception Is thrown, if no database configuration is available
796
     */
797
    public function getDatabase()
798
    {
799
800
        // if a DB ID has been set, try to load the database
801
        if ($useDbId = $this->getUseDbId()) {
802
            return $this->getDatabaseById($useDbId);
803
        }
804
805
        // iterate over the configured databases and try return the default database
806
        /** @var TechDivision\Import\Configuration\DatabaseInterface  $database */
807
        foreach ($this->databases as $database) {
808
            if ($database->isDefault() && $this->isValidDatabaseType($database)) {
809
                return $database;
810
            }
811
        }
812
813
        // try to return the first database configurtion
814
        if ($this->databases->count() > 0) {
815
            return $this->databases->first();
816
        }
817
818
        // throw an exception, if no database configuration is available
819
        throw new \Exception('There is no database configuration available');
820
    }
821
822
    /**
823
     * Return's the ArrayCollection with the configured operations.
824
     *
825
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the operations
826
     */
827
    public function getOperations()
828
    {
829
        return $this->operations;
830
    }
831
832
    /**
833
     * Return's the ArrayCollection with the configured shortcuts.
834
     *
835
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the shortcuts
836
     */
837
    public function getShortcuts()
838
    {
839
        return $this->shortcuts;
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->shortcuts; (array) is incompatible with the return type declared by the interface TechDivision\Import\Conf...Interface::getShortcuts of type Doctrine\Common\Collections\ArrayCollection.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
840
    }
841
842
    /**
843
     * Return's the ArrayCollection with the configured loggers.
844
     *
845
     * @return \Doctrine\Common\Collections\ArrayCollection The ArrayCollection with the loggers
846
     */
847
    public function getLoggers()
848
    {
849
        return $this->loggers;
850
    }
851
852
    /**
853
     * Set's the flag that import artefacts have to be archived or not.
854
     *
855
     * @param boolean $archiveArtefacts TRUE if artefacts have to be archived, else FALSE
856
     *
857
     * @return void
858
     */
859
    public function setArchiveArtefacts($archiveArtefacts)
860
    {
861
        $this->archiveArtefacts = $archiveArtefacts;
862
    }
863
864
    /**
865
     * Return's the TRUE if the import artefacts have to be archived.
866
     *
867
     * @return boolean TRUE if the import artefacts have to be archived
868
     */
869
    public function haveArchiveArtefacts()
870
    {
871
        return $this->archiveArtefacts;
872
    }
873
874
    /**
875
     * The directory where the archives will be stored.
876
     *
877
     * @param string $archiveDir The archive directory
878
     *
879
     * @return void
880
     */
881
    public function setArchiveDir($archiveDir)
882
    {
883
        $this->archiveDir = $archiveDir;
884
    }
885
886
    /**
887
     * The directory where the archives will be stored.
888
     *
889
     * @return string The archive directory
890
     */
891
    public function getArchiveDir()
892
    {
893
        return $this->archiveDir;
894
    }
895
896
    /**
897
     * Set's the debug mode.
898
     *
899
     * @param boolean $debugMode TRUE if debug mode is enabled, else FALSE
900
     *
901
     * @return void
902
     */
903
    public function setDebugMode($debugMode)
904
    {
905
        $this->debugMode = $debugMode;
906
    }
907
908
    /**
909
     * Queries whether or not debug mode is enabled or not, default is TRUE.
910
     *
911
     * @return boolean TRUE if debug mode is enabled, else FALSE
912
     */
913
    public function isDebugMode()
914
    {
915
        return $this->debugMode;
916
    }
917
918
    /**
919
     * Set's the log level to use.
920
     *
921
     * @param string $logLevel The log level to use
922
     *
923
     * @return void
924
     */
925
    public function setLogLevel($logLevel)
926
    {
927
        $this->logLevel = $logLevel;
928
    }
929
930
    /**
931
     * Return's the log level to use.
932
     *
933
     * @return string The log level to use
934
     */
935
    public function getLogLevel()
936
    {
937
        return $this->logLevel;
938
    }
939
940
    /**
941
     * Set's the explicit DB ID to use.
942
     *
943
     * @param string $useDbId The explicit DB ID to use
944
     *
945
     * @return void
946
     */
947
    public function setUseDbId($useDbId)
948
    {
949
        $this->useDbId = $useDbId;
950
    }
951
952
    /**
953
     * Return's the explicit DB ID to use.
954
     *
955
     * @return string The explicit DB ID to use
956
     */
957
    public function getUseDbId()
958
    {
959
        return $this->useDbId;
960
    }
961
962
    /**
963
     * Set's the PID filename to use.
964
     *
965
     * @param string $pidFilename The PID filename to use
966
     *
967
     * @return void
968
     */
969
    public function setPidFilename($pidFilename)
970
    {
971
        $this->pidFilename = $pidFilename;
972
    }
973
974
    /**
975
     * Return's the PID filename to use.
976
     *
977
     * @return string The PID filename to use
978
     */
979
    public function getPidFilename()
980
    {
981
        return $this->pidFilename;
982
    }
983
984
    /**
985
     * Set's the systemm name to be used.
986
     *
987
     * @param string $systemName The system name to be used
988
     *
989
     * @return void
990
     */
991
    public function setSystemName($systemName)
992
    {
993
        $this->systemName = $systemName;
994
    }
995
996
    /**
997
     * Return's the systemm name to be used.
998
     *
999
     * @return string The system name to be used
1000
     */
1001
    public function getSystemName()
1002
    {
1003
        return $this->systemName;
1004
    }
1005
1006
    /**
1007
     * Set's the collection with the path of the Magento Edition specific extension libraries.
1008
     *
1009
     * @param array $extensionLibraries The paths of the Magento Edition specific extension libraries
1010
     *
1011
     * @return void
1012
     */
1013
    public function setExtensionLibraries(array $extensionLibraries)
1014
    {
1015
        $this->extensionLibraries = $extensionLibraries;
1016
    }
1017
1018
    /**
1019
     * Return's an array with the path of the Magento Edition specific extension libraries.
1020
     *
1021
     * @return array The paths of the Magento Edition specific extension libraries
1022
     */
1023
    public function getExtensionLibraries()
1024
    {
1025
        return $this->extensionLibraries;
1026
    }
1027
1028
    /**
1029
     * Return's a collection with the path to additional vendor directories.
1030
     *
1031
     * @return \Doctrine\Common\Collections\ArrayCollection The paths to additional vendor directories
1032
     */
1033
    public function getAdditionalVendorDirs()
1034
    {
1035
        return $this->additionalVendorDirs;
1036
    }
1037
1038
    /**
1039
     * The array with the subject's custom header mappings.
1040
     *
1041
     * @return array The custom header mappings
1042
     */
1043
    public function getHeaderMappings()
1044
    {
1045
1046
        // initialize the array for the custom header mappings
1047
        $headerMappings = array();
1048
1049
        // try to load the configured header mappings
1050
        if ($headerMappingsAvailable = reset($this->headerMappings)) {
1051
            $headerMappings = $headerMappingsAvailable;
1052
        }
1053
1054
        // return the custom header mappings
1055
        return $headerMappings;
1056
    }
1057
1058
    /**
1059
     * The array with the subject's custom image types.
1060
     *
1061
     * @return array The custom image types
1062
     */
1063
    public function getImageTypes()
1064
    {
1065
1066
        // initialize the array for the custom image types
1067
        $imageTypes = array();
1068
1069
        // try to load the configured image types
1070
        if ($imageTypesAvailable = reset($this->imageTypes)) {
1071
            $imageTypes = $imageTypesAvailable;
1072
        }
1073
1074
        // return the custom image types
1075
        return $imageTypes;
1076
    }
1077
1078
    /**
1079
     * Set's the flag that decides whether or not the import should be wrapped within a single transaction.
1080
     *
1081
     * @param boolean $singleTransaction TRUE if the import should be wrapped in a single transation, else FALSE
1082
     *
1083
     * @return void
1084
     */
1085
    public function setSingleTransaction($singleTransaction)
1086
    {
1087
        $this->singleTransaction = $singleTransaction;
1088
    }
1089
1090
    /**
1091
     * Whether or not the import should be wrapped within a single transation.
1092
     *
1093
     * @return boolean TRUE if the import should be wrapped in a single transation, else FALSE
1094
     */
1095
    public function isSingleTransaction()
1096
    {
1097
        return $this->singleTransaction;
1098
    }
1099
1100
    /**
1101
     * Set's the flag that decides whether or not the the cache has been enabled.
1102
     *
1103
     * @param boolean $cacheEnabled TRUE if the cache has been enabled, else FALSE
1104
     *
1105
     * @return void
1106
     */
1107
    public function setCacheEnabled($cacheEnabled)
1108
    {
1109
        $this->cacheEnabled = $cacheEnabled;
1110
    }
1111
1112
    /**
1113
     * Whether or not the cache functionality should be enabled.
1114
     *
1115
     * @return boolean TRUE if the cache has to be enabled, else FALSE
1116
     */
1117
    public function isCacheEnabled()
1118
    {
1119
        return $this->cacheEnabled;
1120
    }
1121
1122
    /**
1123
     * Set's the passed serial from the commandline to the configuration.
1124
     *
1125
     * @param string $serial The serial from the commandline
1126
     *
1127
     * @return void
1128
     */
1129
    public function setSerial($serial)
1130
    {
1131
        $this->serial = $serial;
1132
    }
1133
1134
    /**
1135
     * Return's the serial from the commandline.
1136
     *
1137
     * @return string The serial
1138
     */
1139
    public function getSerial()
1140
    {
1141
        return $this->serial;
1142
    }
1143
1144
    /**
1145
     * Return's the configuration for the caches.
1146
     *
1147
     * @return \Doctrine\Common\Collections\ArrayCollection The cache configurations
1148
     */
1149
    public function getCaches()
1150
    {
1151
1152
        // iterate over the caches and set the parent configuration instance
1153
        foreach ($this->caches as $cache) {
1154
            $cache->setConfiguration($this);
1155
        }
1156
1157
        // return the array with the caches
1158
        return $this->caches;
1159
    }
1160
1161
    /**
1162
     * Return's the cache configuration for the passed type.
1163
     *
1164
     * @param string $type The cache type to return the configuation for
1165
     *
1166
     * @return \TechDivision\Import\Configuration\CacheConfigurationInterface The cache configuration
1167
     */
1168
    public function getCacheByType($type)
1169
    {
1170
1171
        // load the available cache configurations
1172
        $caches = $this->getCaches();
1173
1174
        // try to load the cache for the passed type
1175
        /** @var \TechDivision\Import\Configuration\CacheConfigurationInterface $cache */
1176
        foreach ($caches as $cache) {
1177
            if ($cache->getType() === $type) {
1178
                return $cache;
1179
            }
1180
        }
1181
    }
1182
1183
    /**
1184
     * Return's the alias configuration.
1185
     *
1186
     * @return \Doctrine\Common\Collections\ArrayCollection The alias configuration
1187
     */
1188
    public function getAliases()
1189
    {
1190
        return $this->aliases;
1191
    }
1192
1193
    /**
1194
     * Set's the prefix for the move files subject.
1195
     *
1196
     * @param string $moveFilesPrefix The prefix for the move files subject
1197
     *
1198
     * @return void
1199
     */
1200
    public function setMoveFilesPrefix($moveFilesPrefix)
1201
    {
1202
        $this->moveFilesPrefix = $moveFilesPrefix;
1203
    }
1204
1205
    /**
1206
     * Return's the prefix for the move files subject.
1207
     *
1208
     * @return string The prefix for the move files subject
1209
     *
1210
     * @return string The prefix for the move files subject
1211
     */
1212
    public function getMoveFilesPrefix()
1213
    {
1214
        return $this->moveFilesPrefix;
1215
    }
1216
1217
    /**
1218
     * Set's the shortcut that maps the operation names that has to be executed.
1219
     *
1220
     * @param string $shortcut The shortcut
1221
     */
1222
    public function setShortcut($shortcut)
1223
    {
1224
        $this->shortcut = $shortcut;
1225
    }
1226
1227
    /**
1228
     * Return's the shortcut that maps the operation names that has to be executed.
1229
     *
1230
     * @return string The shortcut
1231
     */
1232
    public function getShortcut()
1233
    {
1234
        return $this->shortcut;
1235
    }
1236
1237
    /**
1238
     * Set's the name of the command that has been invoked.
1239
     *
1240
     * @param string $commandName The command name
1241
     */
1242
    public function setCommandName($commandName)
1243
    {
1244
        $this->commandName = $commandName;
1245
    }
1246
1247
    /**
1248
     * Return's the name of the command that has been invoked.
1249
     *
1250
     * @return string The command name
1251
     */
1252
    public function getCommandName()
1253
    {
1254
        return $this->commandName;
1255
    }
1256
1257
    /**
1258
     * Set's the username to save the import history with.
1259
     *
1260
     * @param string $username The username
1261
     */
1262
    public function setUsername($username)
1263
    {
1264
        $this->username = $username;
1265
    }
1266
1267
    /**
1268
     * Return's the username to save the import history with.
1269
     *
1270
     * @return string The username
1271
     */
1272
    public function getUsername()
1273
    {
1274
        return $this->username;
1275
    }
1276
}
1277